Programming in SFC
Creating a POU in SFC
Select an application in the device tree.
Click
.The Add POU dialog opens.
Specify a name and select the Sequential Function Chart (SFC) implementation language.
Click Add.
CODESYS adds the POU to the device tree and opens it in the editor.
Adding a step-transition
Select the transition after the initial step.
The transition is marked in red.
Click
.The
Step0
step and theTrans0
transition are inserted.Select the
Trans0
transition and click .The
Trans1
transition and theStep1
step are inserted before theTrans0
transition.
You can also drag the Step and Transition elements into the diagram from the Toolbox view.
For more information, see: Step and Transition
Adding an entry action
Select the
Step0
step.Click
.By default, you are prompted to select the duplication mode for the step actions. You decide whether the reference information about the existing step action objects is copied when the step is copied, or the objects are "embedded". Embedding results in new step action objects being created when the step is copied. The duplication mode is defined in the Duplicate when copying step property. As long as this property is disabled, the copied steps call the same actions as the current step.
You can deactivate the prompt completely in the SFC properties.
The display of "embedded" objects in the Devices and POUs views can be deactivated by means of a menu command.
For this example, accept the Copy reference default setting and click OK to confirm.
The Add Entry Action dialog opens.
Specify the name as
Step0_entry
and select the Structured Text (ST) implementation language. Click Add.CODESYS inserts the
Step0_entry
action below the POU in the device tree and opens the action in the editor.In the
Step0_entry
entry action, you program statements to be executed one time when theStep0
step becomes active.Close the editor of
Step0_entry
.The
Step0
step is now marked with anE
in the lower left corner. Double-click this marker to open the editor.The entry action
Step0_entry
is now available in the properties of the step in Entry action. Other actions can also be selected there as needed.Select the
Step0
step. Press Ctrl+V to copy the step.The same entry actions inserted above are available In the inserted copy of the step. The new step then calls the same exact action.
Adding an exit action
Select the
Step0
step.Click
.By default, you are prompted to select the duplication mode for the step actions of the step. See above for adding an entry action. Then the Insert Exit Action dialog opens.
Specify the name as
Step0_exit
and select the Structured Text (ST) implementation language. Click Add.The
Step0_exit
action is inserted below the POU in the device tree and opened in the editor.In the
Step0_exit
exit action, you program statements to be executed one time before theStep0
step becomes inactive.Close the editor of
Step0_exit
.The
Step0
step is now marked with anX
in the lower right corner. Double-click this marker to open the editor.
You can define the exit action in the properties of the step in Exit action. Other actions can also be selected there.
Adding an action
Double-click the
Step0
step.By default, you are prompted to select the duplication mode for the step actions of the step. See above for adding an entry action. The Add Action dialog opens.
Specify the name as "Step0_active" and select the Structured Text (ST) implementation language. Click Add.
CODESYS inserts the
Step0_active
action below the POU in the device tree and opens the action in the editor.In the
Step0_active
step action, you program statements to be executed as long as the step is active.Close the editor of
Step0_active
.The
Step0
step is now marked with a black triangle in the upper right corner.
You can define the action in the properties of the step in Step action. Other actions can also be selected there.
Adding an alternative branch
Select the
Step1
step.Click
.The
Step2
step is inserted to the right of theStep1
step. The steps are connected as a parallel branch signified by two pairs of double lines.Select one of the double lines.
The double line is marked red.
Click
The branch is converted into an alternative branch. The double lines change into a single line.
You can click
to convert an alternative branch into a parallel branch.For more information, see: Branch
Adding a jump
Select the
Step2
step.Click
.The
Step
jump is inserted after theStep2
step.Select the
Step
jump destination.You can type the jump destination manually or select it by using the
Input Assistant. Select
Step0
.
For more information, see: Jump
Adding a macro
Select the
Step1
step.Click
.The
Macro0
macro is inserted after theStep1
step.Double-click the
Macro0
element.The macro opens in the implementation section of the editor. The name
Macro0
is displayed in the caption.Click
.A step-transition combination is inserted.
Click
.The implementation section returns to the main diagram.
For more information, see: Macro
Adding an association
Select the
Step2
step.Click
.CODESYS inserts an association to the right of the
Step2
step.Click in the left field of the association to select the qualifier.
You can enter the qualifier manually or use the
Input Assistant. Select
P
.Click in the right field of the association to select the action.
You can type the action or select it by using the
Input Assistant .
Using the analyzation.library
library to analyze expressions
The analyzation.library
library allows for the analyzation of expressions. It can be used, for example, in the SFC diagram to examine the result of the flag SFCError
. This flag is used to monitor timeouts in the SFC diagram.
For more information, see: Library: Analyzation