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 |
SFCReset | Bool | Behaves similarly to |
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 |
SFCEnableLimit | Bool | Used for specific activation (TRUE) and deactivation (FALSE) of the timeout control in steps by |
SFCErrorStep | String | Saves the name of the step that caused a timeout registered by |
SFCErrorPOU | String | In case of a timeout, saves the name of the function block in which a timeout registered by |
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 |
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 |
SFCErrorAnalyzation |
| Contains, in the form of a string, all variables that contribute to the total value TRUE of
|
SFCError |
| Contains, in the form of a table, the variables that contribute to the total value TRUE of
|
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.
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 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.
Now you can address the SFC flag within the function block, for example in an action, or from outside the function block.
Online view of SFC function block SFCSample
:
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