SFC Flags

SFC flags are implicitly generated variables with predefined names. You can use them to influence the processing of an SFC diagram. You can use these flags to indicate timeouts or reset step chains, for example. You can also activate inching mode, for example, to switch transitions selectively. To have access these variables, you must declare and activate them.

Implicit creation of SFC flags

TwinCAT declares SFC flags automatically if you have activated the corresponding option. You can set this option in the Properties view for a single SFC POU or in the project properties in the SFC category for all SFC POUs in the project.

SFC Flags 1:

The SFC settings of the SFC flags of individual POUs only take effective if you have not activated the Use default SFC settings option. If you have activated this option, the settings defined in the project properties apply.

SFC Flags 2:

SFC flags that you have declared in the SFC settings dialog are only visible in the online view of the SFC function block!

Explicit creation of SFC flags

Manual declaration is only required to enable write access from another function block. In this case, note the following: If you have declared the flag in a global variable list, you must deactivate its Declare setting in the SFC settings dialog. Otherwise a local SFC flag is implicitly declared, which TwinCAT then uses instead of the global variable!

Application example for SFCError

You have created an SFC function block called "SFCSample" that contains a step "s1". You have defined time limits in the step properties. See figure "Online view of SFC function block SFCSample“.

If, for some reason, step s1 remains active longer than permitted in its time properties (timeout), TwinCAT sets the SFC flag SFCError, which the PLC program can access.

To allow this access, you must activate and declare the SFC flag in the SFC settings. If you only declare it, the SFC flag is displayed in the online view of SFCSample in the declaration part, but it has no function.

SFC Flags 3:

You can now access the SFC flag within the POU, e.g. in an action (2) or from outside the function block (1).

SFC Flags 4:

Online view of SFC function block SFCSample:

SFC Flags 5:

SFCError becomes TRUE if a timeout occurs within SFCSample.

Accessing the flags

Syntax for the access:

Within the POU, you assign the flag directly: <variable name>:=<SFC flag>



From another function block with a POU name:  <variable name>:=<POU name>.<SFC flag>



If you require write access from another block, you must also declare the SFC flag explicitly as a VAR_INPUT variable in the SFC function block or globally in a GVL.


Local declaration:


or global declaration in a global variable list:


    setinit: BOOL;
SFC_prog.SFCinit:=setinit;  //Schreibzugriff auf SFCinit in SFC_prog



Data type




TRUE: TwinCAT resets the sequence to the initial step. The other SFC flags are also reset (initialization). As long as the variable is TRUE, the initial step remains set (active), but is not executed. The function block only continues to be processed normally when you set SFCInit back to FALSE.



Behaves similarly to SFCInit. In contrast, however, TwinCAT continues to process the initial step after initialization. For example, you could set the SFCReset flag to FALSE directly in the init step.



Becomes TRUE if a timeout has occurred in an SFC diagram. If a further timeout occurs in the program after the first timeout, this is no longer registered if you have previously not resets the variable SFCError. The declaration of SFCError is a prerequisite for the functioning of the other flag variables to control the timing (SFCErrorStep, SFCErrorPOU, SFCQuitError).



Used for specific activation (TRUE) and deactivation (FALSE) of the timeout control in steps by SFCError. When declaring and activating this variable (SFC settings), you must also set it to TRUE for SFCError to work, otherwise timeouts will be ignored. This can be useful, for example, during commissioning or manual operation. If you do not declare the variable, SFCError works automatically. A prerequisite is, of course, the declaration of SFCError.



Saves the name of the step that caused a timeout registered by SFCError. A prerequisite is the declaration of SFCError.



In case of a timeout, saves the name of the function block in which a timeout registered by SFCError occurred. A prerequisite is the declaration of SFCError.



As long as this Boolean variable is TRUE, TwinCAT stops processing the SFC diagram, thereby resetting any timeout in the SFCError variable. If you reset the variable to FALSE, all previous times in the active steps are reset. A prerequisite is the declaration of SFCError.



As long as this variable is TRUE, TwinCAT suspends the execution of the SFC diagram.



Becomes TRUE when a transition occurs.



Shows the name of the currently active step, regardless of the time monitoring. In a parallel branch, the name of the step of the furthest right branch is always stored.




Allow "tip mode" for the SFC function block.

If you activate tip mode with SFCTipMode=TRUE, you can only switch to the next step by setting SFCTip to TRUE. As long as SFCTipMode is set to FALSE, you can also switch via the transitions.



Contains, in the form of a string, all variables that contribute to the total value TRUE of SFCError (timeout in one step). SFCError must be enabled for this purpose.

SFCErrorAnalyzation implicitly uses the function block AnaylzeExpression from the library Tc2_System.



Contains, in the form of a table, the variables that contribute to the total value TRUE of SFCError (timeout in one step). SFCError must be enabled for this purpose.

SFCErrorAnalyzationTable implicitly uses the function block AnaylzeExpressionTable from the library Tc2_System.