PLC Standar IEC 1131-3
PLC Standar IEC 1131-3
~
2 rFB--3--------~
~
IEC 1131-3 defines different language paradigms, F2
SFC, and some program organization units. The
standard also specifies their representation, and
Fig. 1 Program Organization Units.
rules of evaluation.
27
Function6 Functions have one or more inputs
but only one output. A function can not store
any state information, i.e., executing a function
with certain values on the inputs always gives the
same output value. Functions can be hierarchically
2] f
defined by using already defined functions. A
function can be ezten6ible, meaning that the user Fig. 2 SFC. with alternative (left) and parallel (right)
can decide the number of inputs. Functions are path•.
either typed (operate on a specified data type) or
overloaded (operate on different types).
An action can also be non-boolean. In that case
,Function block6 Function blocks can have sev- it is described with one of the four programming
eral inputs and outputs. They can store state in- languages or with an SFC. All actions must have
formation so the values of the outputs depend on unique names.
previous values.
Action block6 Action blocks are used to asso-
The user must give each instance of a function ciate actions with steps. An action block has a
block an unique name. Function blocks can be boolean input that indicates when the associated
hierarchically defined by using already defined step is active and an unspecified boolean output.
functions and function blocks. When executing a The action block can also act as a normal boolean
function or a function block all inputs must have function block. Each action block is associated
a value. with an action. A non-boolean action can be asso-
ciated with only one action block and can there-
Program6 Programs are built up by functions fore be declared directly in the action block. Steps,
and function blocks. Programs do not have inputs actions and action blocks relate in the following
or outputs. way:
A task has three inputs: single, interval, and • Each boolean action is associated with one
priority. It can execute once on the rising edge or more action blocks.
of 6ingle or periodically with the period time of
• Each non-boolean action is associated with
interval. The priority of the task is set by priority.
one action block.
2.4 Sequential Function Chart6 Figure 12 shows that the boolean action A2 is
A Sequential Function Chart (SFC) is an extended associated with the action blocks AB1 and AB3.
state machine, also known as a Grafcet (David The non-boolean action A1 is constructed directly
and AlIa, 1992). In the standard, SFC is a way of in the action block AB2 and associated only with
structuring programs and function blocks. A unit that action block.
that is not structured is said to be a single action,
executed continuously. Action qualifier An action block uses an action
qualifier to control the action. The action will
An SFC consists of two main elements, 6tep6 and
execute depending on the action qualifiers on the
tran6ition6, shown in Figure 2. Steps can be active
associated action blocks and the status of the
or inactive. The state of the SFC is determined
associated steps. The action qualifiers are e.g.,
by which steps that are active. A transition has
normal meaning that the action is active while the
a boolean input, tran6ition condition, that can
action block is active or dored meaning that the
be described by any of the four languages or by
action is activated when the action block becomes
a boolean variable. A transition will fire when
active.
the step above it is active and the transition
condition is true. An SFC can contain parallel and
alternative paths, shown in Figure 2.
3. IMPLEMENTATION
Action6 It is possible to associate an action with In this section the prototype implementation is
a step. An action can be a single boolean variable. described. The implementation is done in G2,
28
a graphical and object oriented programming filled red circle indicates when a step is active. The
environment from Gensym Corporation. G2 was state of the step is written to a boolean output
chosen since it is good as a rapid prototyping tool. that can be connected to an action block.
Different implementation methods are discussed.
Transitions are represented graphically as a hori-
Most ideas can be used generally, when working in
zontal bar. They have a boolean input that acts
an object oriented environment. Some solutions,
as a transition condition. Figure 4 shows an SFC.
however, are G2 specific.
A hierarchy of classes containing function blocks,
connections, steps, transitions, tasks, and global
A2
variables has been developed. The user constructs
the programs on a workspace with graphical ob-
jects that are instances of these classes. Class def-
initions and methods are hidden for the user.
29
implementation, steps are executed first and then
function blocks. This is, however, not the most
correct order of execution, see Section 4.2.
To determine the order of execution between ele-
ments, lists are built when a task is initialized. A
step list is built with all steps in random order.
A function block list is built with all the function
blocks in the correct execution order. Each func-
Fig. 5 Algebraic loop.
tion block is placed in the list after the function
blocks connected to its input. Hierarchical func-
the old value from the input and writes it to the tion blocks can be dealt with in two ways: local
output. Therefore, the user can use them, instead and global sorting.
of variables, as a memory. In Figure 6 the algebraic
loop problem is solved by inserting a loop element Local sorting In local sorting each hierarchical
and FB1 can now be executed before FB2. function block have its own lists containing all
the function blocks and steps on its subworkspace.
Figure 8 shows the main function block list of the
FBD in Figure 3 and the local list of FB4.
,,
30
.- --.
FB2
-fB2.tt -
does not support pointers. Instead, each functi
block stores the name of its task and when a ta
----'
is activated G2 effectively inserts all associat
.- --. function blocks in a list.
fB 2.2!- -
~ __ .J
31
correct behavior from a control point of view A function can be extensible, i.e., can have a
is global sorting. Using that strategy the execu- variable number of inputs. The standard does
tion order will be PID:CalculateOutput, Limit, not state if the user has to specify the number
PID:UpdateState. Using local sorting the old of inputs when the function is created or if the
value of 14 will be used in the calculation of Updat- number can be changed during the lifetime of the
eState, i.e., an unnecessary delay of one sampling function.
interval is introduced.
According to the standard it shall be possible to do
jumps in all languages. It is probable not so good
4.2 Ezecution order to do jumps in the FBD language. The guidelines
The execution order between functions and func- (IEC, 1995a) also advices not to use them.
tion blocks, SFC-elements, action blocks, and ac-
tions is not specified. The standard states that no
element shall be evaluated until the states of all 5. CONCLUSIONS
its inputs have been evaluated. The authors be- The standard IEC 1131-3 contains most of the
lieve that this leads to the execution order shown needed information but is sometimes not easy
in Figure 12: to understand. It is well specified how SFC and
FBD function separately, but not so well how they
1. Elements connected to a transition. function together. The execution order between
2. All SFC elements. function blocks and SFC elements is the most
unclear part the standard. Probably, the parts of a
3. Action blocks, function blocks connected to
FBD connected to transitions should be executed
them and non-boolean actions.
before an SFC and parts associated with actions
4. Boolean actions. after the SFC.
In the prototype implementation, all function
blocks are sorted into lists before they are exe-
DA2 cuted. Algorithms for sorting the lists locally or
globally are implemented. Local sorting was found
to be easier to implement. However, global sort is
necessary if artificial time delays are to be avoided.
For a small example, a single procedure is writ-
ten with the code from all the function blocks in
a function block diagram. The program executed
much faster with this method. It would be inter-
esting to implement methods for generating such
procedures.
The programming environment G2 is useful as a
2 3 4 prototype tool since it is easy to learn and work
with. Since it is slow and quite expensive, it is
Fig. 12 The execution order of functions, function however unrealistic to use it to control real PLCs.
blow, steps, transitions, action blocks, and actions.
REFERENCES
4.3 Scheduling
The standard does not specify whether the David, R. and H. AlIa (1992): Petri Nets and
scheduling of tasks should be preemptive or non- Grafcet: Tools for modelling discrete events
preemptive. A function block can indirectly be systems. Prentice-Hall.
controlled by more than one task, see Figure 1. IEC (1995a): "Guidelines for the application and
If they try to execute at the same time and if implementation of programming languages for
preemptive scheduling is used, there might be programmable controllers." Technical Report,
problems. IEC.
IEC (1995b): "IEC 1131-3." Technical Report,
4.4 Mi6cellaneou6 IEC. first edition.
SFC in IEC 1131-3 does not support macro steps,
Johansson, S. and M. Ohman (1995): "Proto-
as Grafcet normally do.
type implementation of the PLC standard IEC
The standard specifies that there can be multiple 1131-3." Master thesis ISRN LUTFD2/TFRT-
instances of function blocks. Probably also func- -5547--SE, Department of Automatic Control,
tions can have multiple instances. Lund Institute of Technology, Lund, Sweden.
32