ROBT308Lecture22Spring16 PDF
ROBT308Lecture22Spring16 PDF
ROBT308Lecture22Spring16 PDF
Industrial Automation
Lecture 22 Sequential Function Chart (SFC)
programming in CODESYS
7 April 2015, Thursday
Industrial Automation (ROBT308) - Spring 2016
Topics
Todays Topics
SFC examples: Traffic light control (one lane and two lane)
The Sequential Function Chart (SFC) is a graphically oriented language which allows to
describe the chronological order of particular actions within a program. These actions are
available as separate programming objects, written in any available programming language.
In a SFC the actions are assigned to "step" elements and the sequence of processing is
controlled by transition elements.
SFC is a high-level language to
describe control sequences in
graphical form.
SFC is a tool for the top-down
analysis and representation of a
control sequence.
2. Element bodies
By default a new SFC POU contains an init step and a subsequent transition.
Navigating: Jumping to the next and previous element in the chart is possible by using
the arrow keys.
Insert elements
The particular SFC elements can be inserted via the respective commands which by
default are available in the "SFC" menu. A double-click on an already inserted step,
transition or action element, which does not yet reference a project object, will open a
dialog for assigning one.
Select elements
An element and text field might be selected by a mouse-click on a possible cursor
position. The selection might also always be given to an adjacent element by using the
arrow keys. The element will change color to red.
Multiple selection is possible by the following:
1. Keep the [ Shift ] -key pressed and subsequently click on the particular elements to be
selected. 2. Press the left mouse-key and draw a rectangle (dotted line) around the
elements to be selected. 3. Use command Select All , by default from the Edit menu.
Edit texts
By a mouse-click on a text-cursor-position at once the edit field opens, where you can edit
the text. If a text area has been selected via the arrow keys, the edit field must be opened
explicitly by using the [ Space ] -bar.
Edit associated actions
A double click on an step (entry, active or exit) or transition action association opens the
associated action in the corresponding editor. For example perform a double click on the
transition element or on the triangle indicating an exit action in a step element.
Cut, Copy, Paste elements
Select the element(s) and use command Cut, Copy resp. Paste (by default from the
Edit menu) or the corresponding keys.
Notice the following behavior which is different to CODESYS V2.3 :
When you paste one or several cut or copied element(s), the content of the clipboard will be
inserted before the currently selected position. If nothing is currently selected, the
element(s) will be appended at the end of the currently loaded chart.
If you paste a branch while the currently selected element is also a branch, the pasted
branch elements will be inserted left to the existing ones.
If you paste an action (list) at a currently selected step, the actions will be added at the
beginning of the action list of the step resp. an action list for the step will be created.
Incompatible elements when cutting/copying: If an associated action (list) and additionally
an element, which is not the step to which the action (list) belongs, are selected, a message
box will appear: "The current selection contains incompatible elements. No data will be
filed to the clipboard." The selection will not be stored and you cannot paste or copy it
somewhere else!
Incompatible elements when pasting: If you try to paste an action (list) while the currently
selected element is not a step or another association, an error box will appear: "The current
clipboard content can not be pasted at the current selection." If you try to paste an element
like a step, branch or transition when currently an associated action (list) is selected the
same message box will appear.
Delete elements:
Select the element(s) and use command Delete or the [ Del ] -key. Notice the following:
Deleting a step also deletes the associated action list.
Deleting the init step automatically sets the following step to be the initial one, that is
option 'Initial step' will be activated in the properties of this step.
Deleting the horizontal line preceding a branched area will delete all branches.
Deleting all particular elements of a branch will delete the branch.
The properties of a SFC element can be viewed and edited in the "Element properties"
window. This window can be opened via command 'Element Properties', which by default is
part of the 'View' menu.
It depends on the currently selected element which properties are displayed. The properties
are grouped and the particular group sections can be opened or closed by using the plusand minus signs.
Notice that in the 'View' tab of the SFC-Editor options you can configure whether the
particular types of properties should be displayed next to an element in the SFC chart.
See in the following all possible properties:
10
11
SFC Elements
The graphic elements usable for programming in the SFC editor window can be inserted by
using the commands by default available in the SFC menu.
The elements Step, Transition, Action, Branch (Alternative), Branch (Parallel), Jump, Macro
are available and described in the following:
Step-Transition
Steps and transitions are basically inserted in combination, via command Insert steptransition and Insert step-transition after.
A step is represented by a box primarily containing an automatically generated step name. It is
connected to the preceding and subsequent transition by a line. The box frame of the first step
within a SFC, the init step, is double-lined.
The transition is represented by a small rectangle. After inserting primarily it has a default name:
Trans<n>, whereby n is a running number.
12
SFC Elements
Step names must be unique in the scope of the parent POU. Notice this especially when using
actions programmed in SFC
Notice that each step - by command Init step or by activating the respective step property can be transformed to an init step, that is to that step, which will be executed first when the
IL-POU is called.
Each step is defined by the step properties.
After inserting a step, the action(s) to be performed when the step is active (processed) are
to be associated.
Transitions:
A transition must provide the condition on which the subsequent step shall get active as
soon as the condition value is TRUE.
So a transition condition must have the value TRUE or FALSE. It can be defined in the
following two ways:
13
Transitions:
SFC Elements
1. Directly ("inline condition"): Replace the default transition name by either a boolean
variable, a boolean address, a boolean constant or an instruction having a boolean result
(e.g. (i<100) AND b). It is not possible here to specify programs, function blocks or
assignments!
2. Using a separate transition or property object ("multi-use condition"): Replace the default
transition name by the name of a transition or property object (
,
) available in the
project (this allows multiple use of transitions. The object like an inline transition can
contain a boolean variable, address, constant or instruction, but also multiple statements
with arbitrary code.
It is the user's responsibility to assign the desired expression to a transition variable, if a
transition produces multiple statements!
14
Transitions:
SFC Elements
15
Transitions:
SFC Elements
16
Actions:
SFC Elements
An action can contain a series of instructions written in one of the valid programming
languages. It is assigned to a step and in online mode it will be processed according to the
defined sequence of processing .
Each action to be used in SFC steps must be available as a valid POU within the SFC POU
17
Actions:
SFC Elements
18
Actions:
SFC Elements
19
Actions:
SFC Elements
20
Actions:
SFC Elements
The main difference between step actions and IEC actions with qualifier N is the following:
The IEC action is at least executed twice: First time when the step is active, second time
when the step gets deactivated. See the following example:
21
SFC Elements
Branches:
A sequential function chart can diverge, that is the processing line can be branched into two
or several further lines ("branches"). Parallel branches will be processed parallel (both at a
time), in case of alternative branches only one will be processed depending on the
preceding transition condition. Each branching within a chart is preceded by a horizontal
double (parallel) or simple (alternative) line and also terminated by such a line or by a jump.
A parallel branch must begin and end with a step.
Parallel branches can contain alternative branches or
other parallel branches.
The horizontal lines before and after the branched area
are double-lines.
Example Parallel Branch
22
Branches:
SFC Elements
23
Jump:
SFC Elements
Example Jump
24
Macros:
SFC Elements
25
In order to configure in which way the actions should be associated to the IEC steps, some
qualifiers are available, which are to be inserted in the qualifier field of an action element.
These qualifiers are handled by the SFCActionControl function block of the IecSfc.library,
which automatically is included in a project by the SFC plug-ins.
The available
qualifiers:
The qualifiers
L, D, SD, DS
and SL need a
time value in
the TIME
constant
format.
26
Each SFC step and IEC action provides implicitly generated variables for watching the status
of steps and IEC actions during runtime. Also variables can be defined for watching and
controlling the execution of a SFC (timeouts, reset, tip mode). These variables also might be
generated implicitly by the SFC object.
Basically for each step and each IEC action an implicit variable is generated. A structure
instance, named like the element, for example "step1" for a step with step name "step1".
Notice the possibility, to define in the element properties, whether for this flag a symbol
definition should be exported to the symbol configuration and how this symbol should be
accessible in the PLC.
The data types for those implicit variables are defined in library IecSFC.library. This library
will automatically be included in the project as soon as an SFC object is added.
Step and Action status and Step time
Basically for each step and each IEC action an implicit structure variable of type
SFCStepType and SFCActionType is created. The structure components (flags) describe the
status of a step and action or the currently processed time of an active step.
The syntax for the implicitly done variable declaration is:
<stepname>: SFCStepType; or _<actionname>:SFCActionType;
27
The following boolean flags for step or IEC-action states are available:
Step
<stepname>.x: shows the current activation status.
If <stepname>.x = TRUE, the step will be executed in the current cycle.
<stepname>._x: shows the activation status for the next cycle.
If <stepname>._x = TRUE and <stepname>.x = FALSE, the step will be executed in the
following cycle, that is <stepname>._x gets copied to <stepname>.x at the beginning of a
cycle.
IEC action
_<actionname>.x is TRUE, when the action is executed.
_<actionname>.x is TRUE, when the action is active.
Symbol generation
In the SFC Element Properties of a step or an action you can define, whether for the step
or action name flag a symbol definition should be added to a possibly created and
downloaded symbol application. For this purpose make an entry for the desired access right
in column Symbol of the element properties view.
28
29
The following implicit variables (flags) can be used. For this purpose they must be declared and
activated in the SFC Settings:
30
The following implicit variables (flags) can be used. For this purpose they must be declared and
activated in the SFC Settings:
31
32
Accessing flags:
For enabling access on the flags for the control of SFC execution (timeouts, reset, tip mode),
the flag variables must be declared and activated as described above.
Syntax for accessing:
... from an action or transition within the SFC POU: <stepname>.<flag> and
_<actionname>.<flag>
33
Regard that in case of write access from another POU the implicit variable additionally must
be declared explicitly as a VAR_INPUT variable of the SFC POU or globally for example in a
GVL.
34
In online mode the particular action types will be processed according a defined sequence as
below:
Following terms are used:
Active step: A step, whose step action is being executed, is called "active". In Online mode
active steps are filled with blue color.
Initial step: In the first cycle after a SFC POU has been called, the initial step automatically gets
active and the associated step action is executed.
IEC actions are executed at least twice: The first time when they have got active, the second
time - in the following cycle - when they have been deactivated.
Alternative Branches: If the step preceding the horizontal start line of alternative branches is
active, then the first transition of each particular branch will be evaluated from left to right.
The first transition from the left whose transition condition has value TRUE will be searched
and the respective branch will be executed, that is the subsequent step within this branch will
get active.
Parallel Branches: If the double-line at the beginning line of parallel branches is active and the
preceding transition condition has the value TRUE, then in all parallel branches each the first
step will get active. The branches now will be processed parallel to one another. The step
subsequent to the double-line at the end of the branching will become active when all
previous steps are active and the transition condition after the double-line has the value TRUE.
35
36
37
In online mode the SFC-Editor provides views for monitoring and for writing and forcing the
variables and expressions on the controller. Debugging functionality (breakpoints, stepping
etc.) is not yet available.
Notice that the editor window of an SFC object also includes the Declaration Editor in the
upper part.
In case of having declared implicit variables (SFC flags) via the SFC Settings dialog, those will be
added here, but will not be viewed in the offline mode of the declaration editor.
Also please notice the sequence of processing of the elements of a sequential function chart.
Consider the possible use of flags for watching and controlling the processing of an SFC.
Monitoring
Active steps are displayed filled blue-colored. The display of step attributes depends on the
currently set SFC Editor options.
38
1
2
39
1
3
1
3
40
Adding actions:
41
Adding actions:
42
Adding actions:
In the editor window for implementing the action, insert a coil and
assign GreenLight variable for that (1). Note that the created action
appears under the main program in the project tree view (2). Select
LD for this case. Then add the action.
3
Click on the Green state, then select Add exit
action icon from the toolbar (3).
3
43
Adding actions:
44
Adding actions:
1
2
45
46
1
1
Insert another step after Init (3). You will jump to this
step afterwards
47
48
49
50
51
52