Function Blocks

Function Blocks (FBs) take several inputs and return a group of values as the output as the result of processing.

Function Blocks are the equivalent to Integrated Circuits (IC), representing a specialized control function. They are specified at such a level that you quickly recognize the functionality of the function block and specifically what happens if it is activated or connected to other blocks in a sequence of motion commands.

They contain data as well as an algorithm, so they can keep track of the past (which is one of the differences from Functions). They have a well-defined interface and hidden internals, like an IC or a black box. The user only sees the interface, being the inputs and outputs. The code itself is hidden.

Function Blocks can be used in any of the IEC languages. In an SFC program, function blocks can be part of a step or transition created in FFLD, FBD, IL, and ST.

Once defined, they can be used repeatedly, in the same program, different programs, or even different projects. This makes them highly re-usable.

There are predefined function blocks (e.g., timers, counters, or triggers) and additional function blocks that can come from libraries produced by you or other suppliers (e.g., a temperature control-loop or PID).

Example of Function Blocks

  • The function block is based on the programming language function block Diagram and has the name Hysterisis.
  • It has three inputs (XIN1, XIN2 and EPS) of datatype REAL on the left, and one output (called Q) of type BOOL on the right-hand side.

  • Input names are not very usable; use meaningful names.

Internally, the FB contains this body code:

FUNCTION_BLOCK HYSTERISIS
VAR_INPUT
	XIN1, XIN2 : REAL;
	EPS : REAL;  (* Hysterisis ban *)
END_VAR
VAR_OUTPUT
	Q : BOOK := 0
END_VAR
IF Q THEN
	IF XIN1 < ( XIN2 - EPS ) THEN
		Q := 0 (* XIN2 decreasing *)
	END_IF;
	ELSIF XIN1 > ( XIN2 + EPS ) THEN
		Q := 1; (* XIN2 increasing *)
	END_IF;
END_FUNCTION_BLOCK

In this example, the body code is written in the Structured Text language:

  • The first part deals with the data structure.
  • The second with the algorithm.
  • No additional data is used.

Whatever name was used for this local data inside the body does not conflict with matching names in other functions, function blocks, or with global expressions. This example of data encapsulation removes a major source of errors.