Skip to main content

Processing Order

Important

Note the following when implementing actions:

Multiple executions of an action are possible within the same cycle because the action can be used in multiple SFC charts.

Example: An SFC chart contains two IEC actions A and B, both of which are programmed in SFC, and both of which call an IEC action C. In this case, C would be called twice.

Using the same IEC action at the same time in different levels of an SFC chart can have unpredictable results when processing. CODESYS will issue a corresponding error message due to this. This error message could be displayed, for example, when you are working with projects which have been created in an earlier version of the development system.

Tip

Note: It is possible to use implicit variables to monitor the processing status of steps and actions or to control processing.

Basic behavior of elements

  • Active step

    An active step contains actions that are currently being executed. In online mode, CODESYS displays active steps in blue.

  • Init Step

    In the first cycle after calling a POU in SFC, the initial step is automatically activated and the step action is executed.

  • IEC actions are executed at least twice. The first time is when the step is activated, and the second time when the step is deactivated (but not until the next cycle).

  • Alternative branches

    If the step preceding the branch is active, then the first transitions of the alternative branches are evaluated from left to right. As soon as a transition yields the value TRUE, the next step of the corresponding branch is activated. The transitions of the branches to the right of it are no longer evaluated.

  • Parallel branches

    If the step preceding the branch is active and the transition before the horizontal double line is TRUE, then the first steps of all branches will be activated simultaneously. The branches are then executed in parallel. The step following the branch is activated as soon as the last steps of all branches are active and the next transition yields the value TRUE.

Processing order

  1. Reset IEC actions

    The internal control flags of the actions with the qualifiers N, R, S, L, D, P, SD, DS, SL will be reset. These flags control an IEC action. However, the flags which are accessed within actions are not reset.

  2. Execute exit actions

    Then each step is checked to verify whether it fulfills the condition for executing its exit action. The order of verification follows the layout of the SFC chart, from top to bottom and from left to right.

    An exit action is executed when the step is deactivated, that is, when its entry and step actions, if any, have been executed in the previous cycle and the condition for the next step yields TRUE.

  3. Execute entry actions

    Then each step is checked to verify whether it fulfills the condition for executing its entry action. The order of verification follows the layout of the SFC chart, from top to bottom and from left to right. When this is the case, all entry actions will be executed.

    An entry action is executed once when the associated step is activated. The requirement for this is that the transition preceding the step yields the value TRUE.

  4. Time check / Execute step actions

    A check is performed to detect if a step has remained active longer than allowed. The time check is used to detect errors in the flow. For example, if an expected transition is not fulfilled and the flow therefore stops within a step.

  5. Execute IEC actions

    The IEC actions are executed in alphabetical order. This is done in two passes through the list of actions. In the first pass, the IEC actions of all steps are executed which have been deactivated in the preceding cycle. In the second pass, the IEC actions of all steps are executed which are active.

  6. Transition check / Activate next steps

    When the following conditions are fulfilled, the next step will be activated:

    • The step is active in the current cycle.

    • The following transition returns the value TRUE.

    • Any defined minimum time for the step has expired.