Skip to main content

Programming in SFC

Creating a POU in SFC

  1. Select an application in the device tree.

  2. Click Project → Add Object → POU.

    The Add POU dialog opens.

  3. 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

  1. Select the transition after the initial step.

    The transition is marked in red.

  2. Click SFC → Insert Step-Transition After.

    The Step0 step and the Trans0 transition are inserted.

  3. Select the Trans0 transition and click SFC → Insert Step-Transition.

    The Trans1 transition and the Step1 step are inserted before the Trans0 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

  1. Select the Step0 step.

  2. Click SFC → Add Entry Action.

    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.

  3. For this example, accept the Copy reference default setting and click OK to confirm.

    The Add Entry Action dialog opens.

  4. 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 the Step0 step becomes active.

  5. Close the editor of Step0_entry.

    The Step0 step is now marked with an E in the lower left corner. Double-click this marker to open the editor.

    _cds_img_sfc_step_entry.png

    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.

  6. 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

  1. Select the Step0 step.

  2. Click SFC → Add Exit Action.

    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.

  3. 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 the Step0 step becomes inactive.

  4. Close the editor of Step0_exit.

    The Step0 step is now marked with an X in the lower right corner. Double-click this marker to open the editor.

    _cds_img_sfc_step_exit.png

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

  1. 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.

  2. 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.

  3. Close the editor of Step0_active.

    The Step0 step is now marked with a black triangle in the upper right corner.

    _cds_img_sfc_step_active.png

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

  1. Select the Step1 step.

  2. Click SFC → Insert Branch Right.

    The Step2 step is inserted to the right of the Step1 step. The steps are connected as a parallel branch signified by two pairs of double lines.

  3. Select one of the double lines.

    The double line is marked red.

  4. Click SFC → Alternative

    The branch is converted into an alternative branch. The double lines change into a single line.

You can click SFC → Parallel to convert an alternative branch into a parallel branch.

For more information, see: Branch

Adding a jump

  1. Select the Step2 step.

  2. Click SFC → Insert Jump After.

    The Step jump is inserted after the Step2 step.

  3. Select the Step jump destination.

    You can type the jump destination manually or select it by using the _cds_icon_button_threedots.png Input Assistant. Select Step0.

    _cds_img_sfc_jump.png

For more information, see: Jump

Adding a macro

  1. Select the Step1 step.

  2. Click SFC → Insert Macro After.

    The Macro0 macro is inserted after the Step1 step.

  3. Double-click the Macro0 element.

    The macro opens in the implementation section of the editor. The name Macro0 is displayed in the caption.

  4. Click SFC → Insert Step-Transition.

    A step-transition combination is inserted.

  5. Click AS → Zoom out of Macro.

    The implementation section returns to the main diagram.

For more information, see: Macro

Adding an association

  1. Select the Step2 step.

  2. Click SFC → Insert Action Association.

    CODESYS inserts an association to the right of the Step2 step.

  3. Click in the left field of the association to select the qualifier.

    You can enter the qualifier manually or use the _cds_icon_button_threedots.png Input Assistant. Select P.

  4. Click in the right field of the association to select the action.

    You can type the action or select it by using the _cds_icon_button_threedots.png Input Assistant .

    _cds_img_sfc_action_association.png

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