Skip to main content

SFC Flags

SFC flags are implicitly created variables with predefined names which provide functions for controlling and diagnosing SFC charts. These flags allow you to trigger transitions in a targeted manner.

For example

  • Detecting timeouts

  • Resetting step chains

  • Activating the tip mode

To access these variables, the corresponding flags must be declared and enabled.

Name

Data Type

Description

SFCInit

BOOL

TRUE: Resets the flow 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 it will not be executed. The POU will be processed normally only after you set SFCInit back to FALSE.

SFCReset

BOOL

Behaves similarly to SFCInit

In contrast, after initialization, the initial step continues to be executed. For example, in the initial step you can immediately set the SFCReset flag back to FALSE.

SFCError

BOOL

Becomes TRUE when a timeout has occurred in an SFC chart.

If another timeout occurs in the program after the first one, then it will only be detected if the variable SFCError has been previously reset. Otherwise, the flag remains set and additional timeouts will not be registered.

The declaration of SFCError is required in order that the other flag variables for monitoring the timing will work: SFCErrorStep, SFCErrorPOU, SFCQuitError

SFCEnableLimit

BOOL

Used for targeted activation (TRUE) and deactivation (FALSE) of the control for timeouts in steps by SFCError

When you declare and activate this variable (SFC settings), then you also need to set it to TRUE for SFCError to function; otherwise any timeouts will be ignored. This can be useful, for example, during commissioning or manual operation. If you do not declare the variable, then SFCError will work automatically.

The requirement is the declaration of SFCError.

SFCErrorStep

STRING

Stores the name of the step which caused a timeout registered by SFCError

The name will be retained until the registered step error is reset using SFCQuitError (FALSE -> TRUE).

The requirement is the declaration of SFCError.

SFCErrorPOU

STRING

In case of a timeout, stores the name of the POU where a timeout registered by SFCError has occurred. The name will be stored until the timeout is reset by SFCQuitError.

The requirement is the declaration of SFCError.

SFCQuitError

BOOL

As long as this Boolean variable is TRUE, the processing of the SFC chart is halted. Any timeout – stored in the variable SFCError – is reset in the process. If you set the variable back to FALSE, then all previous times in the active steps will be reset.

The requirement is the declaration of SFCError.

SFCPause

BOOL

As long as this variable is TRUE, the processing of the SFC chart is halted.

SFCTrans

BOOL

Becomes TRUE when a transition switches.

SFCCurrentStep

STRING

Displays the name of the currently active step, regardless of the time check

In the case of a parallel branch, the name of the step of the branch furthest to the right is always stored.

SFCTip

SFCTipMode

BOOL

TRUE: Activates the tip mode of the SFC POU

When you enable tip mode by setting SFCTipMode := TRUE, you can only proceed to the next step by setting SFCTip to TRUE. As long as you set SFCTipMode to FALSE, you can also switch to the next step via the transitions.

SFCErrorAnalyzation

Contains a string of all variables which contribute to the total value TRUE from SFCError (timeout in one step)

SFCError must be enabled for this to work.

SFCErrorAnalyzation implicitly uses the function of the AnalyzeExpression POU from the Analyzation library for this purpose.

For information about the advanced configuration of the analysis, see also: SFC

SFCErrorAnalyzationTable

Contains a table of the variables which contribute to the total value TRUE from SFCError (timeout in one step)

SFCError must be enabled for this to work.

SFCErrorAnalyzationTable implicitly uses the function of the AnalyzeExpressionTable POU from the Analyzation library for this purpose.

For information about the advanced configuration of the analysis, see also: SFC

Implicit generation of SFC flags

SFC flags are automatically declared when you have enabled the corresponding option. You can set this option in the SFC Settings properties dialog for individual POUs or in the SFC project settings dialog for all SFC POUs in the project.

Tip

The SFC settings of the SFC flags of individual POUs are only effective when you have not enabled the Use defaults option. If you have enabled this option, then the settings defined in the project settings will apply.

Tip

SFC flags which you have declared in the SFC settings dialog are only visible in the online view of the SFC POU.

Tip

In the SFC Element Properties, you can define if a symbol definition should be exported to the symbol configuration for a flag.

Explicit generation of SFC flags

A manual declaration – as previously required in CoDeSys V2.3 – is only still required if there needs to be write access to the flags from another POU. Note the following for this:

Important

If the flags have been declared in a global variable list, then you need to disable the Declare setting in the SFC settings dialog. Otherwise, a local SFC flag is also implicitly created. This flag is then used instead of the global variable.

Application example for SFCError

Example 1. Example

You have created an SFC POU named sfc1, which contains a step s1. You have defined time limits in the properties of the step.

If the activity duration of the step s1 exceeds the limit defined in its time properties, then the flag SFCError will be set. The application can evaluate this flag in order to react to the timeout.

To allow this access, you need to enable and declare the flag in the SFC settings. If you only declare it, then the SFC flag will be displayed in the declaration part of the online view of sfc1, but it will not work.

_cds_img_sfc_sfc_flags.png

Now you can address the SFC flag within the POU – for example in an action (2) or from outside the POU (1).

_cds_img_sfc_sfcerror_example.png

Online view of SFC POU sfc1:

_cds_img_sfc_sfcerror_example_online.png

SFCError will become TRUE as soon as a timeout occurs within sfc1.

You can use the SFCErrorAnalyzation and SFCErrorAnalyzationTable flags from the Analyzation library to analyze the cause of a timeout. These flags allow you to identify the individual components of the expression which contribute to SFCError getting the value TRUE.



Access to the flags

Syntax for access

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

Example 2. Example
checkerror := SFCError;


From another POU with name: <variable name> := <pou name>.<sfc flag>

Example 3. Example:
checkerror := SFC_prog.SFCError;


If you need write access from another POU, then you also need to explicitly declare the SFC flag as a VAR_INPUT variable in the SFC POU or globally in a GVL.

Example 4. 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;  //Write access to SFCInit in SFC_prog