Sequential Function Chart Editor
This is how a POU written in the SFC appears in the TwinCAT PLC Control editor:
All editors for POUs consist of a declaration part and a body. These are separated by a screen divider.
The sequential function chart editor is a graphic editor. The most important commands are found in the context menu (right mouse button). Tooltips show in Offline as well as in Online mode and in the zoomed state the full names or expressions of steps, transitions, jumps, jump labels, qualifiers or associated actions.
For information about the sequential function chart, see the chapter about Sequential Function Chart editor.
The editor for the sequential function chart must agree with the particulars of the SFC. In reference to these, the following menu items will be of service.
Marking Blocks in the SFC
A marked block is a bunch of SFC elements that are enclosed in a dotted rectangle. (In the example somewhat above, the step is marked Switch1.)
You can select an element (a step, a transition, or a jump) by pointing the mouse on this element and pressing the left mouse button, or you can use the arrow keys. In order to mark a group of several elements, press <Shift> for a block already marked, and select the element in the lower left or right corner of the group. The resulting selection is the smallest cohesive group of elements that includes both of these elements.
Observe that all commands can only be executed, if they do not contradict the conventions of the language.
'Insert' 'Step Transition (before)' <Ctrl>+<T>
This command inserts a step in the SFC editor followed by a transition in front of the marked block.
'Insert' 'Step Transition (after)' <Ctrl>+<E>
This command inserts a step in the SFC editor followed by a transition after the first transition in the marked block.
'Insert' 'Alternative Branch (right)' <Ctrl>+<A>
This command inserts an alternative branch in the SFC editor as a right branch of the marked block. For this the marked block must both begin and end with a transition. The new branch is then made up of one transition.
'Insert' 'Alternative Branch (left)'
This command inserts an alternative branch in the SFC editor as the left branch of the marked block. For this the marked block must both begin and end with a transition. The new branch is then made up of one transition.
'Insert' 'Parallel Branch (right)' <Ctrl>+<L>
This command inserts a parallel branch in the SFC editor as the right branch of the marked block. For this the marked block must both begin and end with a step. The new branch is then made up of one step. To allow jumps to the parallel branches that have been created, these must be provided with a jump label.
'Insert' 'Parallel Branch (left)'
This command inserts a parallel branch in the SFC editor as the left branch of the marked block. For this the marked block must both begin and end with a step. The new branch is then made up of one step. To allow jumps to the parallel branches that have been created, these must be provided with a jump label (see 'Extras' 'Add label to parallel branch').
'Insert' 'Jump' <Ctrl>+<U>
This command inserts a jump in the SFC editor at the end of the branch, to which the marked block belongs. For this the branch must be an alternative branch. The inserted text string 'Step' in the inserted jump can then be selected and replaced by the step name to be jumped to.
'Insert' 'Transition-Jump'
This command inserts a transition in the SFC editor, followed by a jump at the end of the selected branch. For this the branch must be a parallel branch. The inserted text string 'Step' in the inserted jump can then be selected and replaced by the step name or the jump label of a parallel branch to be jumped to.
'Insert' 'Add Entry-Action'
With this command you can add an entry-action to a step. An entry-action is only executed once, right after the step has become active. The entry-action can be implemented in a language of your choice.
A step with an entry-action is designated by an "E" in the bottom left corner. An entry-action cannot be defined to an IEC step.
'Insert' 'Add Exit-Action'
With this command you can add an exit-action to a step. An exit-action is only executed once, before the step is deactivated. The exit-action can be implemented in a language of your choice.
A step with an exit-action is designated by an "X" in the lower right corner. An exit-action can not be defined to an IEC step.
'Extras' 'Paste Parallel Branch (right)'
This command pastes the contents of the clipboard as a right parallel branch of the marked block. For this the marked block must both begin and end with a step. The contents of the clipboard must, likewise, be an SFC block that both begins and ends with a step.
'Extras' 'Add label to parallel branch'
In order to provide a newly inserted parallel branch with a jump label, the transition occurring before the parallel branching must be marked and the command 'Add label to parallel branch' must be executed. At that point, the parallel branch will be given a standard name consisting of „Parallel“ and an appended serial number, which can be edited according to the rules for identifier names. In the following example, "Parallel" was replaced by "Par_1_2" and the jump to the transition "End" was steered to this jump label.
Delete a label
A jump label can be deleted by deleting the label name.
'Extras' 'Paste After'
This command pastes the SFC block on the clipboard after the first step or the first transition of the marked block. (Normal copying pastes it in front of the marked block.) This will now be executed, if the resulting SFC structure is correct, according to the language norms.
'Extras' 'Zoom Action/Transition' Shortcut: <Alt>+<Enter>
The action of the first step of the marked block or the transition body of the first transition of the market block is loaded into the editor in the respective language, in which it has been written. If the action or the transition body is empty, then the language must be selected, in which it has been written.
'Extras' 'Clear Action/Transition'
With this command you can delete the actions of the first step of the marked block or of the transitions body of the first transition.
If, during a step, you implement either only the action, the entry-action, or the exit-action, then the same will be deleted by the command. Otherwise a dialog box appears, and you can select which action or actions are to be deleted.
If the cursor is located in the action of an IEC step, then only this association will be deleted. If an IEC step with an associated action is selected, then this association will be deleted. During an IEC step with several actions, a selection dialog box will appear.
'Extras' 'Step Attributes'
With this command you can open a dialog box in which you can edit the attributes for the marked step.
Dialog Box for Editing Step Attributes
You can take advantage of three different entries in the step attribute dialog box. Under Minimum Time, you enter the minimum length of time that the processing of this step should take. Under the Maximum Time, you enter the maximum length of time that the processing of this step should take. Note that the entries are of the TIME type, so you use a TIME constant (i.e. T#3s) or a variable of the TIME type.
Under Comment you can insert a comment to the step. In the 'Sequential function chart options' dialog which you open under 'Extras' 'Options', you can then enter whether comments or the time setting is displayed for the steps in the SFC editor. On the right, next to the step, either the comment or the time setting will appear.
If the maximum time is exceeded, SFC flags are set which the user can query.
The example shows a step whose execution should last at least two, and at the most, ten seconds. In Online mode, there is, in addition to these two times, a display of how long the step has already been active.
SFC-Flags
If a step is active in SFC for longer than its attributes state, some special flags are set. There are also variables which can be set in order to control the program flow in the sequential function chart. To use the flags it is necessary, globally or locally, to declare them as output or input variables.
SFCEnableLimit
This variable is of the type BOOL. When it has the value TRUE, the timeouts of the steps will be registered in SFCError. Other timeouts will be ignored.
SFCInit
When this boolean variable has the value TRUE the sequential function chart is set back to the Init step. The other SFC flags are reset too (initialization). The Init step remains active, but is not executed, for as long as the variable has the value TRUE. It is only when SFCInit is again set to FALSE that the block can be processed normally.
SFCReset:
This variable, of type BOOL, behaves similarly to SFCInit. Unlike the latter, however, further processing takes place after the initialization of the Init step. Thus for example the SFCReset flag could be re-set to FALSE in the Init step.
SFCQuitError:
Execution of the SFC diagram is stopped for as long as this boolean variable has the value TRUE whereby a possible timeout in the variable SFCError is reset. All previous times in the active steps are reset when the variable again assumes the value FALSE.
SFCPause
Execution of the SFC diagram is stopped for as long as this boolean variable has the value TRUE.
SFCError:
This Boolean variable is TRUE when a timeout has occurred in a SFC diagram. If another timeout occurs in a program after the first one, it will not be registered unless the variable SFCError is reset first.
SFCTrans:
This boolean variable takes on the value TRUE when a transition is actuated.
SFCErrorStep:
This variable is of the type STRING. If SFCError registers a timeout, in this variable is stored the name of the step which has caused the timeout.
SFCErrorPOU:
This variable of the type STRING contains the name of the block in which a timeout has occurred.
SFCCurrentStep:
This variable is of the type STRING. The name of the step is stored in this variable which is active, independently of the time monitoring. In the case of simultaneous sequences the step is stored in the branch on the outer right.
No further timeout will be registered if a timeout occurs and the variable SFCError is not reset again.
SFCErrorAnalyzation:
This variable, of type STRING, provides the transition expression as well as every variable in an assembled expression which gives a FALSE result for the transition and thus produces a timeout in the preceding step. A requirement for this is declaration of the SFCError flag, which registers the timeout. SFCErrorAnalyzation refers back to a function called AppedErrorString in the TcSystem.Lib library. The output string separates multiple components with the symbol “|”.
SFCTip, SFCTipMode:
This variables of type BOOL allow inching mode of the SFC. When this is switched on by SFCTipMode=TRUE, it is only possible to skip to the next step if SFCTip is set to TRUE. As long as SFCTipMode is set to FALSE, it is possible to skip even over transitions.
'Extras' 'Time Overview'
With this command you can open a window in which you can edit the time settings of your SFC steps:
Time Boundaries Overview for a SFC POU
In the time boundaries overview, all steps of your SFC POU are displayed. If you have entered a time boundary for a step, then the time boundary is displayed to the right of the step (first, the lower limit, then the upper limit). You can also edit the time boundaries. To do so, click on the desired step in the overview. The name of the step is then shown below in the window. Go to the Minimum Time or Maximum Time field, and enter the desired time boundary there.
Note that the entries are of the TIME type, so you use a TIME constant (i.e. T#3s) or a variable of the TIME type. If you close the window with OK, then all of the changes will be stored.
In the example, steps 2 and 6 have a time boundary. Shift1 lasts at least two, and at most, ten seconds. Shift2 lasts at least seven, and at most, eight seconds.
'Extras' 'Options'
With this command you open a dialog box in which you can set different options for your SFC POU.
In the SFC Options dialog box you can undertake five entries. Under Step Height, you can enter how many lines high an SFC step can be in your SFC editor. 4 is the standard setting here. Under Step Width, you can enter how many columns wide a step should be. 6 is the standard setting here. The Comment Width defines the number of columns, which are shown, if you let the step shown with the comment.
You can also preset the Display at Step. With this, you have three possibilities: You can either have Nothing displayed, or the Comment, or the Time Limits. The last two are shown the way you entered them in "Extras" "Step Attributes".
'Extras' 'Associate Action'
With this command actions and Boolean variables can be associated with IEC steps. To the right of, and next to the IEC step, an additional divided box is attached, for the association of an action. It is preset in the left field with the qualifier "N" and the name "Action." Both presets can be changed. For this you can use the Input Assistant.
New actions for IEC steps are created in the Object Organizer for an SFC POU with the "Project" "Add Action" command.
'Extras' 'Use IEC-Steps'
If this command is activated (denoted by a check in front of the menu item and a printed symbol in the Tool bar), then IEC steps will be inserted instead of the simplified steps upon insertion of step transitions and parallel branches.
If this option is switched on, the Init step is set as an IEC step when you create a new SFC POU.
The Sequential Function Chart in the Online Mode
With the sequential function chart editor in Online mode, the currently-active steps will be displayed as blue steps (black in the example). If you have set it under "Extras" "Options", then the time management is depicted next to the steps. Under the lower and upper bounds that you have set, a third time indicator will appear from which you can read how long the step has already been active.
In the picture above the step depicted has already been active 8 seconds and 410 milliseconds. The step must, however, be active for at least 7 minutes before the step will be left.
With "Online" "Toggle Breakpoint" , a breakpoint is set at a step, or in an action at the locations allowed by the language in use. Processing then stops prior to execution of this step or before the location of the action in the program. Steps or program locations where a breakpoint is set are marked in light blue.
If several steps are active in a parallel branch, then the active step whose action will be processed next is displayed in red.
If IEC steps have been used, then all active actions in Online mode will be displayed in blue.
With the command 'Online' 'Step over' it is stepped always to the next step which action is executed.
If the current location is:
- a step in the linear processing of a POU or a step in the rightmost parallel branch of a POU, execution returns from the SFC POU to the caller. If the POU is the main program, the next cycle begins.
- a step in a parallel branch other than the rightmost, execution jumps to the active step in the next parallel branch.
- the last breakpoint location within a 3S action, execution jumps to the caller of the SFC.
- the last breakpoint location within an IEC action, execution jumps to the caller of the SFC.
- the last breakpoint position within an input action or output action, execution jumps to the next active step.
With 'Online' 'Step in' even actions can be stepped into. If an input, output or IEC action is to be jumped into, a breakpoint must be set there. Within the actions, all the debugging functionality of the corresponding editor is available to the user.
If you rest the mouse cursor for a short time on a variable in the declaration editor, the type, the address and the comment of the variable will be displayed in a tooltip
Sequential Function Chart in the Online Mode with an Active Step (Shift1) and a Breakpoint (Step10)
CAUTION | |
Undefined state If you rename a step and perform an Online Change while this step is active, the program will be stopped in undefined status. |
Processing order of elements in a sequence:
- First, all Action Control Block flags in the IEC actions that are used in this sequence are reset (not, however, the flags of IEC actions that are called within actions).
- All steps are tested in the order which they assume in the sequence (top to bottom and left to right) to determine whether the requirement for execution of the output action is provided, and this is executed if that is the case.
- All steps are tested in the order which they assume in the sequence to determine whether the requirement for the input action is provided, and this is executed if that is the case.
- For all steps, the following is done in the order which they assume in the sequence:
- If applicable, the elapsed time is copied into the corresponding step variable.
- If applicable, any timeout is tested and the SFC error flags are serviced as required.
- For non-IEC steps, the corresponding action is now executed.
- IEC actions that are used in the sequence are executed in alphabetical order. This is done in two passes through the list of actions. In the first pass, all the IEC actions that are deactivated in the current cycle are executed. In the second pass, all the IEC actions that are active in the current cycle are executed.
- Transitions are evaluated: If the step in the current cycle was active and the following transition returns TRUE (and if applicable the minimum active time has already elapsed), then the following step is activated.
The following must be noted concerning implementation of actions:
It can come about that an action is carried out several times in one cycle because it is associated with multiple sequences. (For example, an SFC could have two IEC actions A and B, which are both implemented in SFC, and which both call IEC action C; then in IEC actions A and B can both be active in the same cycle and furthermore in both actions IEC action C can be active; then C would be called twice).
If the same IEC action is used simultaneously in different levels of an SFC, this could lead to undesired effects due to the processing sequence described above. For this reason, an error message is issued in this case.
It can possibly arise during processing of projects created with older versions of TwinCAT PLC.
In monitoring expressions (e.g. A AND B) in transitions, only the „Total value“ of the transition is displayed. |