-

SFC Parameters, Operating Modes and Data Types

This topic contains the following descriptions:

SFC parameters and operating modes as IEC 61131-3 extensions

PLCnext Engineer extends the IEC 61131-3 standard by implementing SFC operating modes used to control the execution of the SFC program. For that purpose, each SFC function block gets parameters by default when it is inserted into a code worksheet by drag and drop from the COMPONENTS area.

When creating an SFC block using the command 'Add SFC Function Block' (context menu on the 'Functions & Function Blocks' folder in the COMPONENTS area), the parameters are available as input and output formal parameters at the FB icon.

When creating a compact SFC block using the command 'Add Compact SFC Function Block', most of the parameters are combined in a STRUCT data type which is to be connected to an InOut formal parameter. Only the dynamically generated 'STEP_STATES' and 'STRUCTURE' are implemented as formal parameters.

The only difference between the normal and the compact SFC FB is the way it is connected in the calling POU. The contained SFC code and functional possibilities are identical.

When debugging SFC code worksheets in debug mode, the debugging commands provided on the editor's toolbar can be used to set the formal parameters of the SFC function block (e.g., to change the operating mode, to acknowledge an SFC error, etc.) independent of the value connected to the function block inputs. See the topic "Debugging SFC Code" for details.

SFC operating modes

The following operating modes are available. They are available as members in the SFC_OPERATING_MODE enumeration. Via this ENUM an operating mode can be set at the PRESET_OPERATING_MODE input and is indicated at the ACTIVE_OPERATING_MODE output.

Operating modeDescription
Automatic mode
SFC_OPERATING_MODE_AUTO in Enum
The automatic mode is the initial mode after a cold/warm restart. In automatic mode, the SFC chart is evaluated normally, i.e., the steps become active/inactive and the actions are executed according to their qualifiers according to the evaluation of the transitions and depending on the states of Interlocks, if attached to the steps.
Step mode
SFC_OPERATING_MODE_STEP in Enum
In step mode, the succeeding step of the SFC program is only executed if the relevant transition condition is fulfilled and a rising edge is detected at the 'PROCEED' input of the function block instance.
Forced (unconditional) mode
SFC_OPERATING_MODE_STEP_FORCED in Enum
In forced mode, the succeeding step of the SFC program is executed if a rising edge is detected at the 'PROCEED' input of the function block instance. This happens independently of the transition value.
Halt mode
SFC_OPERATING_MODE_HALT in Enum
In halt mode the transitions do not change the state of the SFC chart. The currently active steps are not executed and the assigned actions are not triggered. The halt mode is activated in case of an SFC error.

In halt mode, a step can be activated/deactivated via the STEP_ID input (see below).

Input (formal) parameters

Note
For compact SFC function blocks, all inputs are combined in the same order in the SFC_PARAMETERS structure. Declare a variable of this data type and connect it to the PARAMETERS InOut formal parameter of the compact SFC function block or connect a suitable function block.

Note
None of the formal parameters must necessarily be connected and used in the calling POU. Unconnected inputs are used with the default initial value noted in the table below. When the default values are used, SFC operates as defined by the IEC 61131-3 standard.

ParameterData typeMeaning
PRESET_OPERATING_MODESFC_OPERATING_MODE
(ENUM)
Sets the operating mode.

Initial value: SFC_OPERATING_MODE_AUTO

The available operating modes are described above.
FINAL_SCANBOOLEnables/disables the final scan function.

The final scan function executes all actions of the currently active step just one more time after the step becomes inactive before switching to the succeeding step in the program.

Initial value: FALSE

According the IEC 61131-3 standard, both settings (with or without final scan) are allowed.

  • TRUE: final scan function is enabled for the SFC program.
  • FALSE: final scan function is disabled for the SFC program.
EVALUATE_ALL_TRANSITIONSBOOLThe value TRUE initiates that all transitions are evaluated during every scan of the chain (although only transitions at the current execution position are relevant). This way, it can be determined which transitions would become TRUE and would therefore activate its subsequent step(s) if its preceding step would be the active one. The lines connected to the appropriate transitions are highlighted in the code.

Initial value: FALSE
PROCEEDBOOLThis input is only relevant if one of the operating modes SFC_OPERATING_MODE_STEP or SFC_OPERATING_MODE_STEP_FORCED is active.

Initial value: FALSE

Edge-triggered input to execute the succeeding step in the SFC program.
  • In step (SFC_OPERATING_MODE_STEP) mode: a rising edge executes the succeeding step if the relevant transition condition is fulfilled.
  • In forced (SFC_OPERATING_MODE_STEP_FORCED) mode: a rising edge executes the succeeding step independent of the transition value. The mode can also be considered as unconditional step mode.
In debug mode, the succeeding step can be executed by using the corresponding commands.
STEP_IDDINTWhile the SFC chart is in halt mode (SFC_OPERATING_MODE_HALT), this input can be used to activate or deactivate a particular step.

To activate a particular step: apply the corresponding step ID to this input and then switch the ACTIVATE_STEP input to TRUE.
To deactivate a particular step: apply the corresponding step ID to this input and then switch the DEACTIVATE_STEP input to TRUE.

After a successful activation/deactivation, the STEP_ID input is automatically set to the value -1. Otherwise the step number is kept.

Note
Alternatively, the ACTIVATE(DINT stepId) or DEACTIVATE(DINT stepId) methods of the SFC FB can be called.

ACTIVATE_STEPBOOLWhile the SFC chart is in halt mode (SFC_OPERATING_MODE_HALT), the value TRUE at this input activates the step whose step ID is specified at the STEP_ID input (see table row above).
After a successful activation, the input is automatically reset to FALSE.
DEACTIVATE_STEPBOOLWhile the SFC chart is in halt mode (SFC_OPERATING_MODE_HALT), the value TRUE at this input deactivates the step whose step ID is specified at the STEP_ID input (see table row above).
After a successful deactivation, the input is automatically reset to FALSE.
ACKNOWLEDGE_ERRORBOOLEdge-triggered input for acknowledging and thus resetting an error that occurred while executing the SFC program (e.g., maximum step time exceeded or step time lower than minimum step time).

In the case of an error, the SFC function block is switched to halt mode. The currently active steps are not executed and the assigned actions are not triggered.

With a rising edge at the input, the function block exits the halt mode and continues execution with the previously active operating mode.

Initial value: FALSE

Output (formal) parameters

Note
For compact SFC function blocks, the outputs except STRUCTURE and STEP_STATES are combined in the same order in the SFC_PARAMETERS structure. Either declare a variable of this data type and connect it to the PARAMETERS InOut formal parameter of the compact SFC function block or connect a suitable function block.

Note
None of the formal parameters must necessarily be connected and used in the calling POU. Unconnected inputs are used with the default initial value noted in the table below. When the default values are used, SFC operates as defined by the IEC 61131-3 standard.

ParameterData typeMeaning
STRUCTUREData type depends on the set compiler options.

SFC_GRAPH_STRUCTURE if static arrays are set in the compiler options.
FBTypeName_SFC_GRAPH_STRUCTURE if dynamic arrays are used.
(STRUCT)
Indicates the type info of the SFC function block as STRUCT data type. Refer to section "SFC Data Types" below for a detailed structure description.

If the compiler option 'Use Dynamic Arrays for SFC Info' is activated ('Extras > Options | Compiler | IEC Compiler Settings)', the length of the ObjectTypeInfo array in this structure is dynamic (according to the number of contained SFC objects) and therefore type-specific. Refer to section "Dynamic Array Sizes" for details.

Declare a variable of this data type and connect it to the STRUCTURE output of the SFC function block.
STEP_STATESData type depends on the set compiler options.

SFC_STEP_STATES if compiler option "static arrays" is set.
FBTypeName_SFC_STEP_STATES if dynamic arrays are used.
(STRUCT)
Indicates the state info of the SFC function block as STRUCT data type. Refer to section "SFC Data Types" below for a detailed structure description.

If the compiler option 'Use Dynamic Arrays for SFC Info' is activated ('Extras > Options | Compiler | IEC Compiler Settings)', the length of the ObjectStateInfo array in this structure is dynamic according and therefore type-specific. Refer to section "Dynamic Array Sizes" for details.

Declare a variable of this data type and connect it to the STEP_STATES output of the SFC function block.
ACTIVE_OPERATING_MODE SFC_OPERATING_MODE
(ENUM)
Indicates the currently active operating mode of the function block instance. The possible operation modes (enumeration members) are described above.
ERRORBOOL
  • FALSE: no error occurred. Normal operation in the PRESET_OPERATING_MODE.
  • TRUE: step watchdog error (minimum or maximum step time violation). While an error is pending, the step chain runs in halt mode (SFC_OPERATING_MODE_HALT).
    After eliminating the error reason, the error has to be acknowledged with a rising edge at the ACKNOWLEDGE_ERROR input or via the corresponding command in the editor toolbar.
ERROR_CODEINTOutputs the error number as INT value.
INTERLOCK_FAULTBOOL
  • FALSE: no interlock active in the chain.
  • TRUE: interlock active at any step in the chain.

SFC data types

SFC_GRAPH_STRUCTURE with all included data types (STRUCTs and ENUMs), used at the STRUCTURE output

SFC_STEP_STATES structure, used at the STEP_STATES output

Dynamic Array Sizes in SFC info structures

The size of the arrays inside the STRUCTs at the outputs STRUCTURE and STEP_STATES can be static or dynamic, depending on your compiler settings. Select 'Extras > Options' and select the category 'Compiler | IEC Compiler Settings'. Here, the option 'Use dynamic arrays for SFC info' is available.

Compiler option
'Use Dynamic Arrays for SFC Info'
is...
Meaning
activatedThe size is dynamic, depending on the SFC chain in the function block type. As a result, the state/type info has a different length for different SFC function blocks.

With a dynamic array length, less memory is occupied in the controller. On the other hand, a new data type is required for each SFC function block due to the FB-specific array size. Therefore, the name of the data type expected at the output contains the type name of the SFC function block
FBTypeName_SFC_GRAPH_STRUCTURE
or
FBTypeName_SFC_STEP_STATES.

Example: data type of the STRUCTURE output of the FB type MyCompactSFCFunctionBlock.

not activatedThe array size is static, i.e., has the same size independent of the SFC function block type. For small SFC chains, this means that possibly more memory space is occupied than necessary. On the other hand, the same data type can be connected to each SFC function block, as they all have the same size.

When setting a static array size in the compiler options, each SFC FB expects the data type SFC_GRAPH_STRUCTURE at the STRUCTURE output and SFC_STEP_STATES at the STEP_STATES output (no type-dependency).