Processing Order in SFC
Basic behavior of the elements
- Active step: An active step is a step whose actions are currently being executed. In online mode TwinCAT displays active steps in blue.
- Initial step: In the first cycle after calling an SFC POU, the initial step is automatically activated and the step action is executed.
- TwinCAT executes the IEC actions at least twice. The first time after the step has been activated, the second time - but only in the next cycle - after the step has been deactivated.
- Alternative branches: If the step preceding the branch is active, TwinCAT evaluates the first transition of each alternative branch from left to right. In the first branch, in which TwinCAT finds a transition that returns TRUE, the next step is activated.
- Parallel branches: If the step preceding the branch (before the horizontal double line) is active and the transition before the branch returns TRUE, TwinCAT activates the first steps in all branches. The branches are then processed simultaneously. The step after the end of the branch (after the horizontal double line) is activated when all last steps in the branches are active and the transition after the double line returns TRUE.
Processing sequence
- Resetting of the IEC actions
TwinCAT resets the internal action control flags of the action qualifiers (N, R, S, L, D, P, SD, DS, SL). These are the flags that control an IEC action. However, flags that are called within actions will not be reset! - Executing exit actions
TwinCAT then checks all steps to see whether they fulfill the condition for executing the exit actions. The checking sequence corresponds to the order in the SFC diagram: from top to bottom and from left to right.
TwinCAT executes an exit action when the step is deactivated, i.e. when its input and step actions (if available) have been executed in the previous cycle and the condition for the subsequent step returns TRUE. - Executing entry actions
TwinCAT then checks all steps to see whether they fulfill the condition for executing the entry actions. The checking sequence corresponds to the order in the SFC diagram: from top to bottom and from left to right. If this is the case, TwinCAT executes the entry actions.
TwinCAT executes an entry action as soon as processing has reached the transition preceding the step and this transition returns TRUE, i.e. the step is activated. - Time check, executing step actions
TwinCAT executes the following for all steps in the sequence in which they are arranged in the SFC diagram: - TwinCAT copies the elapsed time of the active step into the corresponding implicit step variable <step name>.t.
- In the event of a timeout, TwinCAT sets the corresponding error flags.
- For non-IEC steps, TwinCAT now executes the step action.
- Executing IEC actions
TwinCAT executes the IEC actions in alphabetical order. This is done in two cycles through the list of actions. In the first run TwinCAT executes the IEC actions of all steps that were deactivated in the previous cycle. In the second run, the IEC actions of all steps that are active are executed. - Transition check, activation of the following steps
The transitions are evaluated: If a step is active in the current cycle and the following transition returns TRUE (and a minimum step time that may have been defined has elapsed), the following step is activated.
When implementing actions, note the following: |
Note the possibility of using implicit variables to monitor or control the processing status of steps and actions. |
See also: