Programming the Sequential Function Chart (SFC)

Creating POUs in the SFC implementation language

  1. Select an application in the device tree.

  2. Click Project ‣ Add object ‣ POU .

    ⇒ The dialog box Add POU opens.

  3. Enter a name and select the implementation language Sequential Function Chart (SFC).

    Click Add.

    ⇒ CODESYS adds the POU to the device tree and opens it in the editor.

Adding step-transitions

  1. Select the transition after the initial step.

    ⇒ The transition is marked red.

  2. Click SFC ‣ Insert step-transition after .

    ⇒ CODESYS inserts the Step0 step and the Trans0 transition.

  3. Select the Trans0 transition and click SFC ‣ Insert step-transition .

    ⇒ CODESYS inserts the Trans1 transition and the Step1 step before the Trans0 transition.

You can also drag the Step and Transition elements into the diagram from the Toolbox view.

See also

Adding entry actions

  1. Select Step0.

  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 to 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. When it is deactivated, 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 default setting Copy reference and confirm by clicking OK.

    ⇒ The Add entry action dialog box opens.

  4. Type the name “Step0_entry” and select “Structured Text (ST)” as the 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 “Step0_entry” editor.

    ⇒ The Step0 step is now marked with an E in the lower left corner. Double-clicking this marker opens 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.

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

See also

Adding exit actions

  1. Select Step0.

  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 entry actions. Then the Add exit action dialog box opens.

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

    ⇒ CODESYS inserts the “Step0_exit” action below the POU in the device tree and opens the action 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 “Step0_exit” editor.

    ⇒ The Step0 step is now marked with an X in the lower right corner. Double-clicking this marker opens the editor.

You can define the exit action in the step properties of Exit action, as well as select other actions as needed.

See also

Adding actions

  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 entry actions. The Add action dialog box opens.

  2. Type the name “Step0_active” and select the implementation language “Structured Text (ST)”. 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 “Step0_active” editor.

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

You can define the action in the step properties of Step action, as well as select other actions as needed.

See also

Adding alternative branches

  1. Select Step1.

  2. Click SFC ‣ Insert branch right .

    ⇒ CODESYS inserts the Step2 step to the right of Step1. 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

    ⇒ CODESYS converts the branch into an alternative branch. The double lines change into a single line.

You can convert an alternative branch into a parallel branch by clicking SFC ‣ Parallel .

See also

Adding jumps

  1. Select Step2.

  2. Click SFC ‣ Insert jump after .

    ⇒ CODESYS inserts the Step jump after the Step2 step.

  3. Select the Step jump destination.

    ⇒ You can type the jump destination manually or select it by using the input assistant . Select Step0.

See also

Adding macros

  1. Select Step1.

  2. Click SFC ‣ Insert macro after .

    ⇒ CODESYS inserts the Macro0 macro 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 .

    ⇒ CODESYS inserts a step-transition combination.

  5. Click SFC ‣ Zoom out of macro .

    ⇒ The implementation section returns to the main diagram.

See also

Adding associations

  1. Select Step2.

  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 input assistant|PNG72/button_threedots.png.png|. 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 input assistant .

See also

See also