Skip to main content

Programming in SFC

Creating a POU in SFC

  1. Select an application in the device tree.

  2. Click the Project → Add Object → POU command.

    The Add POU dialog will open.

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

  1. Select the transition following the initial step.

    The transition will be highlighted in red.

  2. Click the SFC → Insert Step-Transition After command.

    The Step0 step and the Trans0 transition will be inserted.

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

    The Trans1 transition and the Step1 step will be inserted before the Trans0 transition.

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

  1. Select the Step0 step.

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

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

    The Add Entry Action dialog will open.

  4. Specify the name as Step0_entry and select Structured Text (ST) as the implementation language. Click the Add button.

    CODESYS will insert the Step0_entry action below the POU in the device tree and open the action in the editor.

    In the Step0_entry entry action, you program statements to be executed once when the Step0 step becomes active.

  5. Close the editor of Step0_entry.

    The Step0 step will now be marked with an E in the lower left corner. Double-clicking this marker will open the editor.

    _cds_img_sfc_step_entry.png

    The Step0_entry entry action will now be listed in the step properties under Entry action. There you can also select a different action when needed.

  6. Select the Step0 step. 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

  1. Select the Step0 step.

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

  3. Specify the name as Step0_exit and select Structured Text (ST) as implementation language. Click the Add button.

    The Step0_exit action will be 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 once before the Step0 step becomes inactive.

  4. Close the editor of Step0_exit.

    The Step0 step will now be marked with an X in the lower right corner. Double-clicking this marker will open the editor.

    _cds_img_sfc_step_exit.png

You can define the exit action in the step properties under Exit action. There you can also select a different action.

Add Action

  1. Double-click the Step0 step.

    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.

  2. Specify the name as Step0_active and select Structured Text (ST) as the implementation language. Click the Add button.

    CODESYS will insert the Step0_active action below the POU in the device tree and open the action in the editor.

    In the Step0_active step action, you now program statements which should be executed while the step is active.

  3. Close the editor of Step0_active.

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

    _cds_img_sfc_step_active.png

You can define the action in the step properties under Main action. There you can also select a different action.

Add Alternative Branch

  1. Select the Step1 step.

  2. Click the SFC → Insert Branch Right command.

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

  3. Select one of the two double lines.

    The double line will be highlighted in red.

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

  1. Select the Step2 step.

  2. Click the SFC → Insert Jump After command.

    The Step jump will be inserted after the Step2 step.

  3. Select the Step jump destination.

    You can now specify the jump target manually or via the Input Assistant _cds_icon_button_threedots.png. Select the Step0 step.

    _cds_img_sfc_jump.png

For more information, see the following: Jump

Insert Macro

  1. Select the Step1 step.

  2. Click the SFC → Insert Macro After command.

    The Macro0 macro will be inserted after the Step1 step.

  3. Double-click the Macro0 element.

    The macro will open in the implementation part of the editor. The name Macro0 will be displayed in the header.

  4. Click the SFC → Insert Step-Transition command.

    A step-transition combination will be inserted.

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

  1. Select the Step2 step.

  2. Click the SFC → Insert Action Association command.

    An association is added to the right of the Step2 step.

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

    You can specify the qualifier manually or via the Input Assistant _cds_icon_button_threedots.png. Select P.

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

    You can specify the action manually or via the Input Assistant _cds_icon_button_threedots.png.

    _cds_img_sfc_action_association.png