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 sequences, 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.

SFC-Flags

Name

Data type

Description

SFCInit

Bool

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.

SFCReset

Bool

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

SFCError

Bool

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 reset 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).

SFCEnableLimit

Bool

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 the declaration of SFCError.

SFCErrorStep

String

Saves the name of the step that caused a timeout registered by SFCError. The name is stored until the registered timeout is reset by SFCQuitError.
Prerequisite is the declaration of SFCError.

SFCErrorPOU

String

In case of a timeout, saves the name of the function block in which a timeout registered by SFCError occurred. The name is stored until the registered timeout is reset by SFCQuitError.
Prerequisite is the declaration of SFCError.

SFCQuitError

Bool

As long as this Boolean variable is TRUE, TwinCAT suspends the execution of the SFC diagram. A possible timeout, stored in the variable SFCError, will be reset. If you reset the variable to FALSE, all previous times in the active steps are reset.
A prerequisite is the declaration of SFCError.

SFCPause

Bool

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

SFCTrans

Bool

Becomes TRUE when a transition occurs.

SFCCurrentStep

String

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.

SFCTip,

SFCTipMode

Bool

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.

SFCErrorAnalyzation

 

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 Tc2_System library.

SFCError
AnalyzationTable

 

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 Tc2_System library.

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 are only 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 variables!

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:

Now you can address the SFC flag within the function block, for example in an action, or from outside the function block.

SFC Flags 4:

Online view of SFC function block SFCSample:

SFC Flags 5:

SFCError becomes TRUE if a timeout occurs within SFCSample.

Note the possibility of using the flags SFCErrorAnalyzation and SFCErrorAnalyzationTable to determine the components of the expression that contributes to the value TRUE of the SFCError.

Accessing the flags

Syntax for the access:

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

Example:

checkerror:=SFCerror;

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

Example:

checkerror:=SFC_prog.SFCerror;

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.

Example:

Local declaration:

PROGRAM SFC_prog
VAR_INPUT
    SFCinit:BOOL;
END_VAR

or global declaration in a global variable list:

VAR_GLOBAL
    SFCinit:BOOL;
END_VAR

PROGRAM PLC_PRG
VAR
    setinit: BOOL;
END_VAR
SFC_prog.SFCinit:=setinit;  //Schreibzugriff auf SFCinit in SFC_prog