Introduction

FFB is the generic term for:

Elementary Function

Elementary functions (EF) have no internal states. If the input values are the same, the value on the output is the same every time the function is called. For example, the addition of two values always gives the same result.

An elementary function is represented graphically as a frame with inputs and one output. The inputs are always represented on the left and the output is always on the right of the frame.

The name of the function, i.e. the function type, is displayed in the center of the frame.

The execution number for the function is shown to the right of the function type.

The function counter is shown above the frame. The function counter is the sequential number of the function within the current section. Function counters cannot be modified.

Elementary Function

With some elementary functions, the number of inputs can be increased.

Elementary Function Block

Elementary function blocks (EFBs) have internal states. If the input values are the same, the value on the output can be different each time the function is called. e.g. for a counter the value on the output is incremented.

An elementary function block is represented graphically as a frame with inputs and outputs. The inputs are always represented on the left and the outputs always on the right of the frame.

Function blocks can have more than one output.

The name of the function block, i.e. the function block type, is displayed in the center of the frame.

The execution number for the function block is shown to the right of the function block type.

The instance name is displayed above the frame.

The instance name serves as a unique identification for the function block in a project.

The EFB instance name is created automatically and has the following structure: TYPE_n, where:

  • TYPE is the type of the function block.

  • n is the sequential number of the function block type in the project.

For example:

  • First instance of a type EFB type TON is named TON_0

  • First instance of a type EFB type MOTOR is named MOTOR_0

  • Second instance of a type EFB type TON is named TON_1

This automatically generated name can be modified for clarification. The instance name (max. 32 characters) must be unique throughout the project and is not case-sensitive. The instance name must conform to general naming conventions.

NOTE: To conform to IEC61131-3, only letters are permitted as the first character of the name. If you want to use a numeral as your first character however, this must be enabled explicitly.

Elementary Function Block

DFB

Derived function blocks (DFBs) have the same properties as elementary function blocks. The user can create them in the programming languages FBD, LD, IL, and/or ST.

The only difference to elementary function blocks is that the derived function block is represented as a frame with double vertical lines.

Derived Function Block

Procedure

Procedures are functions viewed technically.

The only difference to elementary functions is that procedures can occupy more than one output and they support data type VAR_IN_OUT.

Procedures are a supplement to IEC 61131-3 and must be enabled explicitly.

To the eye, procedures are no different than elementary functions.

Procedure

Parameters

Inputs and outputs are required to transfer values to or from an FFB. These are called formal parameters.

Objects are linked to formal parameters; these objects contain the current process states. They are called actual parameters.

Formal and actual parameters:

At program runtime, the values from the process are transferred to the FFB via the actual parameters and then output again after processing.

Only one object (actual parameter) of the following types may be linked to FFB inputs:

  • Variable

  • Address

  • Literal

  • ST Expression

    ST expressions on FFB inputs are a supplement to IEC 61131-3 and must be enabled explicitly.

  • Link

The following combinations of objects (actual parameters) can be linked to FFB outputs:

  • one variable

  • a variable and one or more connections (but not for VAR_IN_OUT outputs)

  • an address

  • an address and one or more connections (but not for VAR_IN_OUT outputs)

  • one or more connections (but not for VAR_IN_OUT outputs)

The data type of the object to be linked must be the same as that of the FFB input/output. If all actual parameters consist of literals, a suitable data type is selected for the function block.

Exception: For generic FFB inputs/outputs with data type ANY_BIT, it is possible to link objects of data type INT or DINT (not UINT and UDINT).

This is a supplement to IEC 61131-3 and must be enabled explicitly.

Example:

Allowed:

Not allowed:

(In this case, AND_INT must be used.)

Not all formal parameters have to be assigned an actual parameter. However, this does not apply in the case of negated pins. These must always be assigned an actual parameter. This is also the case with some formal parameter types. These types are shown in the following table.

Table of formal parameter types:

Parameter type

EDT

STRING

ARRAY

ANY_ARRAY

IODDT

DEVICE DDT

STRUCT

FB

ANY

EFB: Input

-

-

-

-

/

/

-

/

-

EFB: VAR_IN_OUT

+

-

-

-

+

/

-

/

-

EFB: Output

-

-

+

+

+

/

-

/

+

DFB: Input

-

-

-

-

/

+

-

/

-

DFB: VAR_IN_OUT

+

-

-

-

+

+

-

/

-

DFB: Output

-

-

+

/

/

/

-

/

+

EF: Input

-

-

-

-

+

/

-

+

-

EF: VAR_IN_OUT

+

-

-

-

+

/

-

/

-

EF: Output

-

-

-

-

-

/

-

/

-

Procedure: Input

-

-

-

-

+

/

-

+

-

Procedure: VAR_IN_OUT

+

+

+

+

+

/

+

/

+

Procedure: Output

-

-

-

-

-

/

-

/

+

+ Actual parameter required

- Actual parameter not required, it's the general rule, but there are exceptions for some FFBs, for instance when some parameters are used to characterize the information we want to be given by the FFB.

/ not applicable

FFBs that use actual parameters on the inputs that have not yet received any value assignment, work with the initial values of these actual parameters.

If no value is allocated to a formal parameter, then the initial value is used for executing the function block. If no initial value has been defined then the default value ("0") is used.

If a formal parameter is not assigned a value and the function block/DFB instance is invoked more than once, then the subsequently executed invocations are run with the last effective actual value.

NOTE: Unassigned data structures are always initialized with value "0", initial values can not be defined.
NOTE: An ANY_ARRAY_xxx input pin not connected will create automatically an hidden array of 1 element.

Public Variables

In addition to inputs and outputs, some function blocks also provide public variables.

These variables transfer static values (values that are not influenced by the process) to the function block. They are used for setting parameters for the function block.

Public variables are a supplement to IEC 61131-3.

The assignment of values to public variables is made using their initial values.

Public variables are read via the instance name of the function block and the names of the public variables.

Example:

Private Variables

In addition to inputs, outputs and public variables, some function blocks also provide private variables.

Like public variables, private variables are used to transfer statistical values (values that are not influenced by the process) to the function block.

Private variables can not be accessed by user program. These type of variables can only be accessed by the animation table.

NOTE: Nested DFBs are declared as private variables of the parent DFB. So their variables are also not accessible through programming, but trough the animation table.

Private variables are a supplement to IEC 61131-3.

Programming Notes

Attention should be paid to the following programming notes:

  • FFBs are only executed if the input EN=1 or if the input EN is grayed out.

  • Boolean inputs and outputs can be inverted.

  • Special conditions apply when using VAR_IN_OUT variables.

  • Function block/DFB instances can be called multiple times.

Multiple Function Block Instance Call

Function block/DFB instances can be called more than once; other than instances from communication EFBs and function blocks/DFBs with an ANY output but no ANY input: these can only be called once.

Calling the same function block/DFB instance more than once makes sense, for example, in the following cases:

  • If the function block/DFB has no internal value or it is not required for further processing.

    In this case, memory is saved by calling the same function block/DFB instance more than once since the code for the function block/DFB is only loaded once.

    The function block/DFB is then handled like a "Function".

  • If the function block/DFB has an internal value and this is supposed to influence various program segments, for example, the value of a counter should be increased in different parts of the program.

    In this case, calling the same function block/DFB means that temporary results do not have to be saved for further processing in another part of the program.

EN and ENO

One EN input and one ENO output can be used in all FFBs.

If the value of EN is equal to "0" when the FFB is invoked, the algorithms defined by the FFB are not executed and ENO is set to "0".

If the value of EN is equal to "1" when the FFB is invoked, the algorithms defined by the FFB is executed. After the algorithms have been executed successfully, the value of ENO is set to "1". If an error occurs when executing these algorithms, ENO is set to "0".

If the EN pin is not assigned a value, when the FFB is invoked, the algorithm defined by the FFB is executed (same as if EN equals to "1"), Please refer to Maintain output links on disabled EF.

If ENO is set to "0" (caused by EN=0 or an error during execution):

  • Function blocks

    • EN/ENO handling with function blocks that (only) have one link as an output parameter:

      If EN of FUNCBLOCK_1 is set to "0", the link on output OUT of FUNCBLOCK_1 maintains the old status it had during the last correctly executed cycle.

    • EN/ENO handling with function blocks that have one variable and one link as output parameters:

      If EN of FUNCBLOCK_1 is set to "0", the link on output OUT of FUNCBLOCK_1 maintains the old status it had during the last correctly executed cycle. The OUT1 variable on the same pin either retains its previous status or can be changed externally without influencing the link. The variable and the link are saved independently of each other.

  • Functions/Procedures

    As defined in IEC61131-3, the outputs from deactivated functions (EN input set to "0") are undefined. (The same applies to procedures.)

    Here nevertheless an explanation of the output statuses in this case:

    • EN/ENO handling with function/procedure blocks that (only) have one link as an output parameter:

      If EN of FUNC_PROC_1 is set to "0", the value of the link on output OUT of FUNC_PROC_1 depends on the project setting Maintain output links on disabled EF.

      If this project setting is set to “0”, the value of the link is set to “0”.

      If this project setting is set to “1”, the link maintains the old value it had during the last correctly executed cycle.

      Please refer to Maintain output links on disabled EF.

    • EN/ENO handling with function/procedure blocks that have one variable and one link as output parameters:

      If EN of FUNC_PROC_1 is set to "0", the value of the link on output OUT of FUNC_PROC_1 depends on the project setting Maintain output links on disabled EF.

      If this project setting is set to “0”, the value of the link is set to “0”.

      If this project setting is set to “1”, the link maintains the old value it had during the last correctly executed cycle.

      Please refer to Maintain output links on disabled EF.

      The OUT1 variable on the same pin either retains its previous status or can be changed externally without influencing the link. The variable and the link are saved independently of each other.

The output behavior of the FFBs does not depend on whether the FFBs are invoked without EN/ENO or with EN=1.

NOTE: For disabled function blocks (EN = 0) with an internal time function (e.g. function block DELAY), time seems to keep running, since it is calculated with the help of a system clock and is therefore independent of the program cycle and the release of the block.

VAR_IN_OUT Variable

FFBs are often used to read a variable at an input (input variables), to process it and to output the altered values of the same variable (output variables).

This special type of input/output variable is also called a VAR_IN_OUT variable.

The link between input and output variables is represented by a line in the FFB.

VAR_IN_OUT variable

The following special features are to be noted when using FFBs with VAR_IN_OUT variables.

  • All VAR_IN_OUT inputs must be assigned a variable.

  • Via graphical links only VAR_IN_OUT outputs with VAR_IN_OUT inputs can be connected.

  • Only one graphical link can be connected to a VAR_IN_OUT input/output.

  • A combination of variable/address and graphical connections is not possible for VAR_IN_OUT outputs).

  • No literals or constants can be connected to VAR_IN_OUT inputs/outputs.

  • No negations can be used on VAR_IN_OUT inputs/outputs.

  • Different variables/variable components can be connected to the VAR_IN_OUT input and the VAR_IN_OUT output. In this case the value of the variables/variable component on the input is copied to the at the output variables/variable component.