TwinCAT PLC Control: Languages

Sequential Function Chart (SFC)

The sequential function chart a graphically oriented language which makes it possible to describe the chronological order of different actions within a program.

Example for a network in the sequential function chart:

Sequential Function Chart (SFC) 1:

Step

A POU written in a sequential function chart consists of a series of steps which are connected with each other through directed connections (transitions). 
There are two types of steps. 

Action

An action can contain a series of instructions in IL or in ST, a lot of networks in FBD or in LD, or again in sequential function chart (SFC). With the simplified steps an action is always connected to a step. In order to edit an action, click twice with the mouse on the step to which the action belongs. Or select the step and select the menu command "Extras" "Zoom Action/Transition". In addition, one input or output action per step is possible.
Actions of IEC steps hang in the Object Organizer directly under their SFC-POU and are loaded with a doubleclick or by pressing <Enter> in their editor. New actions can be created with "Project" "Add Action"..

Entry or exit action

Additional to a step action you can add an entry action and an exit action to a step. An entry action is executed only once, right after the step has become active. An exit action is executed only once before the step is deactivated. A step with entry action is indicated by an "E" in the lower left corner, the exit action by an "X" in the lower right corner. The entry and exit action can be implemented in any language. In order to edit an entry or exit action, doubleclick in the corresponding corner in the step with the mouse. An entry and exit action can only be defined to a simplified step, but not to an IEC step. 

Example of a step with entry and exit action:


Sequential Function Chart (SFC) 2:

Transition/Transition condition

Between the steps there are so-called transitions. A transition condition must have the value TRUE or FALSE. Thus it can consist of either a boolean variable, a boolean address or a boolean constant. It can also contain a series of instructions having a boolean result, either in ST syntax (e.g. (i<= 100) AND b) or in any language desired (see 'Extras” “Zoom Action/Transition”). But a transition may not contain programs, function blocks or assignments! 

Note: 

Besides transitions, inching mode can also be used to skip to the next step; see SFCtip and SFCtipmode.

Active Step

After calling the SFC POU, the action (surrounded by a double border) belonging to the initial step is executed first. A step, whose action is being executed, is called active. If the step is active, then the appropriate action is executed once per cycle. In Online mode active steps are shown in blue. To each step belongs a flag which saves the condition of the step. The step flag (active or inactive condition of the step) is shown by the logical value of a Boolean structure element <StepName>.x. This Boolean variable has the value TRUE if the appropriate step is active and FALSE if it is inactive. This variable is implicitly declared and can be used in any action and transition of the SFC POU.In a control cycle all actions are executed which belong to active steps. Thereafter the respective following steps of the active steps become active if the transition conditions of the following steps are TRUE. The currently active steps will be executed in the next cycle.

Note: 

If the active step contains an output action, this will only be executed during the next cycle, provided that the transition following is TRUE.

IEC step

Along with the simplified steps the standard IEC steps in SFC are available. In order to be able to use IEC steps, you must link the library TcSystem.Lib into your project. 
Any number of actions can be assigned to an IEC step. IEC actions are not fixed as input, step or output actions to a certain step as in the simplified steps, but are stored separately from the steps and can be reused many times within a POU. For this they must be associated to the single steps with the command 'Extras''Associate action'.

Along with actions, Boolean variables can be assigned to steps. 
The activation and deactivation of actions and boolean variables can be controlled using so-called qualifiers. Time delays are possible. Since an action can still be active, if the next step has been processed, for example through the qualifier S (Set), one can achieve concurrent processes.

An associated boolean variable is set or reset with each call of the SFC block. That means, that with each call the value changes from TRUE or FALSE or back again.

The actions associated with an IEC step are shown at the right of the step in a two-part box. The left field contains the qualifier, possibly with time constant, and the right field contains the action name.

An example for an IEC step with two actions:


Sequential Function Chart (SFC) 3:

In order to make it easier to follow the processes, all active actions in on-line mode are shown in blue like the active steps. After each cycle a check is made to see which actions are active.

Pay attention here also to the restrictions on the use of time-qualifiers in actions that are repeatedly re-used within the same cycle.

Note:

If an action has been inactivated, it will be executed once more. That means, that each action is executed at least twice (also an action with qualifier P). In case of a call first the deactivated actions, then the active actions are executed, in alphabetical order each time.

Whether a newly inserted step is an IEC step depends upon whether the menu command "Extras" "Use IEC-Steps" has been chosen. 

In the Object Organizer the actions hang directly underneath their respective SFC POUs. New actions can be created with "Project" "Add Action". In order to use IEC steps you must include in your project the special SFC library lecsfc.lib .

Sequential Function Chart (SFC) 4:

In order to associate the actions with IEC steps the following qualifiers are available:

N Non-stored The action active as long as the step.
R overriding Reset The action is deactivated.
S Set (Stored) The action is activated and remains active until a Reset.
L time Limited The action is activated for a certain time.
D time Delayed The action becomes active after a certain time as long as the step is still active.
P Pulse The action is executed just one time if the step is active.
SD Stored and time Delayed The action is activated after a certain time and remains active until a Reset.
DS Delayed and Stored The action is activated after a certain time as long as the step is still active and remains active up to a Reset.
SL Stored and time Limited The is action is activated for a certain time.

Note:

If the same action is used with qualifiers in two straight sequently steps, which influence the time flow, the time qualifier can´t become operative at the second use. To avoid this, an intermediate step has to be inserted. Thus the action status can be initialised anewd in the additional passing through cycle.

Implicit variables in SFC

There are implicitly declared variables in the SFC which can be used. A flag belongs to each step which stores the state of the step. The step flag (active or inactive state of the step) is called <StepName>.x for IEC steps or <StepName> for the simplified steps. This Boolean variable has the value TRUE when the associated step is active and FALSE when it is inactive. It can be used in every action and transition of the SFC block. One can make an enquiry with the variable <ActionName>.x. as to whether an IEC action is active or not.

 

Alternative branch

Two or more branches in SFC can be defined as alternative branches. Each alternative branch must begin and end with a transition. Alternative branches can contain parallel branches and other alternative branches. An alternative branch begins at a horizontal line (alternative beginning) and ends at a horizontal line (alternative end) or with a jump. 

If the step which precedes the alternative beginning line is active, then the first transition of each alternative branch is evaluated from left to right. The first transition from the left whose transition condition has the value TRUE is opened and the following steps are activated.

For IEC steps the implicit variables <StepName>.t can be used to enquire about the active time of the steps. Implicit variables can also be accessed by other programs. Example: boolvar1:=sfc.step1.x; Here, step1.x is the implicit boolean variable representing the state of IEC step step1 in POU sfc1.

Parallel branch

Two or more branches in SFC can be defined as parallel branches. Each parallel branch must begin and end with a step. Parallel branches can contain alternative branches or other parallel branches. A parallel branch begins with a double line (parallel beginning) and ends with a double line (parallel end) or with a jump. 

If the parallel beginning line of the previous step is active and the transition condition after this step has the value TRUE, then the first steps of all parallel branches become active (see active step). These branches are now processed parallel to one another. The step after the parallel end line becomes active when all previous steps are active and the transition condition before this step produces the value TRUE.

Jump

A jump is a connection to the step whose name is indicated under the jump symbol. Jumps are required because it is not allowed to create connections which lead upward or cross each other.