For the purposes of programmable controller programming languages, a function block is a program organization unit which, when executed, yields one or more values.
Multiple, named instances (copies) of a function block can be created.
Each instance shall have an associated identifier (the instance name), and a data structure containing its output and internal variables, and, depending on the implementation, values of or references to its input variables.
All the values of the output variables and the necessary internal variables of this data structure shall persist from one execution of the function block to the next.
Therefore, invocation of a function block with the same arguments (input variables) need not always yield the same output values.
Assignment of a value to an output variable of a function block is not allowed except from within the function block.
The assignment of a value to the input of a function block is permitted only as part of the invocation of the function block.
Unassigned or unconnected inputs of a function block shall keep their initialized values or the values from the latest previous invocation, if any.
Allowable usage of function block inputs and outputs are summarized in table below, using the function block FF75 of type SR.
The examples are shown in the ST language.
|
Usage
|
Inside function block
|
Outside function block
|
|
Input read
|
IF IN1 THEN ...
|
Not allowed 1, 2
|
|
Input assignment
|
Not allowed 1
|
FB_INST(IN1:=A,IN2:=B);
|
|
Output read
|
OUT := OUT AND NOT IN2;
|
C := FB_INST.OUT;
|
|
Output assignment
|
OUT := 1;
|
Not allowed 1
|
|
In-out read
|
IF INOUT THEN ...
|
IF FB1.INOUT THEN...
|
|
In-out assignment
|
INOUT := OUT OR IN1; 3
|
FB_INST(INOUT:=D);
|
1 Those usages listed as "not allowed" in this table could lead to implementation-dependent, unpredictable side effects.
2 Reading and writing of input, output and internal variables of a function block may be performed by the "communication function", "operator interface function", or the "programming, testing, and monitoring functions" defined in IEC 61131-1.
3 Modification within the function block of a variable declared in a VAR_IN_OUT block is permitted.
|
EN and ENO in Function Blocks
For function blocks also an additional Boolean EN (Enable) input or ENO (Enable Out) output, or both, can be provided by the manufacturer or user according to the declarations.
When these variables are used, the execution of the operations defined by the function block shall be controlled according to the following rules:
-
If the value of EN is FALSE (0) when the function block instance is invoked, the assignments of actual values to the function block inputs may or may not be made in an implementation-dependent fashion, the operations defined by the function block body shall not be executed and the value of ENO shall be reset to FALSE (0) by the programmable controller system.
-
Otherwise, the value of ENO shall be set to TRUE (1) by the programmable controller system, the assignments of actual values to the function block inputs shall be made and the operations defined by the function block body shall be executed. These operations can include the assignment of a Boolean value to ENO.
-
If the ENO output is evaluated to FALSE (0), the values of the function block outputs (VAR_OUTPUT) keep their states from the previous invocation.
When EN inputs are left open the concerned blocks are not executed in Concept whereas they would be executed in Control Expert.
To eliminate this difference the Concept Converter applies a constant boolean value of FALSE to not connected EN inputs. In this way achieving the same behavior as in Concept.
In-out variables are a special kind of variable used with program organization units (POUs), i.e., functions, function blocks and programs.
They do not represent any data directly but reference other data of the appropriate type. They are declared by use of the VAR_IN_OUT keyword. In-out variables may be read or written to.
Inside a POU, in-out variables allow access to the original instance of a variable instead of a local copy of the value contained in the variable.
Function Block Invocation
A function block invocation establishes values for the function block's input variables and causes execution of the program code corresponding to the function block body.
These values may be established graphically by connecting variables or the outputs of other functions or function blocks to the corresponding inputs, or textually by listing the value assignments to input variables.
If no value is established for a variable in the function block invocation, a default value is used.
Depending on the implementation, input variables may consist of the actual variable values, addresses at which to locate the actual variable values, or a combination of the two.
These values are always passed to the executing code in the data structure associated with the function block instance.
The results of function block execution are also returned in this data structure.
Hence, if the function block invocation is implemented as a procedure call, only a single argument - the address of the instance data structure - need be passed to the procedure for execution.