SFC Element ‘Action’

Symbol:

An action includes a series of statements in one of the valid implementation languages. You can assign an action to a step.

You must create all actions as POUs in the project when they are used in SFC steps.

Hint

You must define unique step names within the scope of the parent block. An action written in SFC cannot contain a step with a name identical to the step to which the action is assigned.

A distinction is made between IEC actions and step actions.

1.  IEC actions

These actions comply with the IEC1131-3 standard. They are executed according to their qualifiers. Each action is executed two times: first when the step is activated and second when the step is deactivated. If you assign several actions to one step, the action list is processed from top to bottom.

Each action box includes the qualifier in the first column and the action name in the second column, both of which can be edited directly.

As opposed to step actions, you can use different qualifiers for IEC actions. In addition, each IEC action is provided with a control flag. This directs CODESYS to execute an action only one time at any moment, even if the action is called by another step at the same time. This cannot be guaranteed for step actions.

You assign IEC actions to steps by clicking SFC ‣ Insert action association .

See also

2. Step actions:

You can use these step actions to extend the IEC standard.

  • Entry action:

    CODESYS executes this action after the step is activated and before the main action is executed.

    These reference a new action, or action created in below the SFC object, from a step by means of the Entry action step property. (2). You can also add a new action to the step by means of the Add entry action command. The entry action is marked with an E in the lower left corner of the step box.

  • Main action:

    CODESYS executes this action when the step is active and any entry actions have already been processed. However, as opposed to IEC actions (see above), these step actions a are not executed a second time when the step is deactivated. In addition, you cannot use qualifiers here.

    You add an existing action to a step by means of the Main action element property (1). You can create and add a new action by clicking the step element. A main action is marked with a filled triangle in the upper right corner of the step box.

  • Exit action:

    CODESYS executes this action one time when the step is deactivated. Please note, however, that an exit action is not executed in the same cycle, but at the beginning of the next cycle.

    These reference a new action, or action created in below the SFC object, from a step by means of the Exit action step property. (3). You can also add a new action to the step by means of the EAdd exit action command. The exit action is marked with an X in the lower right corner of the step box.

See also

Difference between IEC actions and step actions

Example

The basic difference between step actions and IEC actions with a qualifier N is that an IEC action is executed two times: when the step is activated and when the step is deactivated. See the following example:

You have attached the Action_AS1 action to the AS1 step as a step action (left) and as an IEC action with qualifier N (right). Because two transitions are activated in each case, the time to reach the initial step again is two PLC cycles. This is true as long as the iCounter counter variable was initialized at 0 and then incremented in the Action_AS1 action.  After the Init step is reactivated, iCounter yields a value of 1 in the example on the left. In the example on the right, a value of 2 is yielded because the IEC action is executed a second time due to the deactivation of AS1.

Another difference is that step actions can be pseudo-embedded. In this case, they can be called only from the related step. If you copy this step, CODESYS creates new action objects automatically and copies the respective implementation code. You define whether or not a step action is embedded, either when the first action is inserted into the step, or later in the Duplicate when copying step property. In general, this behavior can also be preset in the SFC options.