Programming in SFC
Creating a POU in SFC
Select an application in the device tree.
Click the Project → Add Object → POU command.
The Add POU dialog will open.
Specify a name and select Sequential Function Chart (SFC) as the implementation language.
Click the Add button.
CODESYS will add the POU to the device tree and open it in the editor.
Insert Step Transition
Select the transition following the initial step.
The transition will be highlighted in red.
Click the SFC → Insert Step-Transition After command.
The
Step0step and theTrans0transition will be inserted.Select the
Trans0transition and click the SFC → Insert Step-Transition command.The
Trans1transition and theStep1step will be inserted before theTrans0transition.
You can also drag the Step and Transition elements into the chart from the ToolBox view.
For more information, see the following: Step / Transition
Add Entry Action
Select the
Step0step.Click the SFC → Add Entry Action command.
By default, you will be prompted to select the duplication mode for the step actions. This determines whether the reference information to the existing step action objects is copied when the step is copied in the future, or whether the objects should be embedded. Embedding will result in new step action objects being created when the step is copied. The duplication mode is defined in the Duplicate on copy step property. As long as this property is disabled, the copied steps will call the same actions as the current step.
You can deactivate the prompt completely in the SFC options.
You can use a menu command to turn off the display of embedded objects in the Devices or POUs views.
For this example, leave the default Copy reference setting and click OK to confirm.
The Add Entry Action dialog will open.
Specify the name as
Step0_entryand select Structured Text (ST) as the implementation language. Click the Add button.CODESYS will insert the
Step0_entryaction below the POU in the device tree and open the action in the editor.In the
Step0_entryentry action, you program statements to be executed once when theStep0step becomes active.Close the editor of
Step0_entry.The
Step0step will now be marked with anEin the lower left corner. Double-clicking this marker will open the editor.
The
Step0_entryentry action will now be listed in the step properties under Entry action. There you can also select a different action when needed.Select the
Step0step. Press Ctrl+C to copy it and then press Ctrl+V to paste it at the desired position.The same entry action inserted above is also available in the inserted copy of the step. The new step therefore calls exactly the same action.
Add Exit Action
Select the
Step0step.Click the SFC → Add Exit Action command.
By default, you will be prompted to determine the duplication mode for the step actions of the step. For more information, see above: Add Entry Action. The Add Exit Action dialog will open afterwards.
Specify the name as
Step0_exitand select Structured Text (ST) as implementation language. Click the Add button.The
Step0_exitaction will be inserted below the POU in the device tree and opened in the editor.In the
Step0_exitexit action, you program statements to be executed once before theStep0step becomes inactive.Close the editor of
Step0_exit.The
Step0step will now be marked with anXin the lower right corner. Double-clicking this marker will open the editor.
You can define the exit action in the step properties under Exit action. There you can also select a different action.
Add Action
Double-click the
Step0step.By default, you will be prompted for the duplication mode for the step actions of the step. For more information, see the procedure for adding an entry action. The Add Action dialog will open.
Specify the name as
Step0_activeand select Structured Text (ST) as the implementation language. Click the Add button.CODESYS will insert the
Step0_activeaction below the POU in the device tree and open the action in the editor.In the
Step0_activestep action, you now program statements which should be executed while the step is active.Close the editor of
Step0_active.The
Step0step will now be marked with a black triangle in the upper right corner.
You can define the action in the step properties under Main action. There you can also select a different action.
Add Alternative Branch
Select the
Step1step.Click the SFC → Insert Branch Right command.
The
Step2step is inserted to the right of theStep1step. The steps are connected as a parallel branch with double lines.Select one of the two double lines.
The double line will be highlighted in red.
Click the SFC → Alternative command.
The branch will be converted into an alternative branch. The double lines will change into a single line.
You can use the SFC → Parallel command to convert an alternative branch into a parallel branch.
For more information, see the following: Branch
Insert Jump
Select the
Step2step.Click the SFC → Insert Jump After command.
The
Stepjump will be inserted after theStep2step.Select the
Stepjump destination.You can now specify the jump target manually or via the Input Assistant
. Select the Step0step.
For more information, see the following: Jump
Insert Macro
Select the
Step1step.Click the SFC → Insert Macro After command.
The
Macro0macro will be inserted after theStep1step.Double-click the
Macro0element.The macro will open in the implementation part of the editor. The name
Macro0will be displayed in the header.Click the SFC → Insert Step-Transition command.
A step-transition combination will be inserted.
Click the SFC → Zoom out of Macro command.
The implementation part will show the main chart again.
For more information, see the following: Macro
Insert Action Association
Select the
Step2step.Click the SFC → Insert Action Association command.
An association is added to the right of the
Step2step.Click in the left field of the action association to select the qualifier.
You can specify the qualifier manually or via the Input Assistant
. Select P.Click in the right field of the association to select the action.
You can specify the action manually or via the Input Assistant
.