Function Blocks

FunctionClosedA function calculates a result according to the current value of its inputs. A function has no internal data and is not linked to declared instances. 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 (ICClosed"Integrated Circuits" Miniaturized electronic circuits (consisting mainly of semiconductor devices, as well as passive components) that have been manufactured in the surface of a thin substrate of semiconductor material), 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 IECClosed"International Electrotechnical Commission" IEC is a not-for-profit, non-governmental international standards organization that prepares and publishes International Standards for all electrical, electronic and related technologies languages. Note that in an SFCClosed"Sequential function chart" It can be used to program processes that can be split into steps. The main components of SFC are: - Steps with associated actions - Transitions with associated logic conditions - Directed links between steps and transitions program, function blocks can be part of a step or transition created in FFLD, STClosed"Structured text" A high-level language that is block structured and syntactically resembles Pascal, ILClosed"Instruction list" This is a low-level language and resembles assembly and FBDClosed"Function block diagram" A function block diagram describes a function between input variables and output variables. A function is described as a set of elementary blocks.

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 also additional function blocks that can come from libraries produced by you or other suppliers (e.g. a temperature control-loop or PIDClosed"Proportional-Integral-Derivative" A PID controller is a generic control-loop feedback mechanism widely used in industrial control systems. An "error" occurs when an event or a disturbance triggers off a change in the process variable. A PID controller attempts to correct the error between a measured process variable and a desired setpoint by calculating and then outputting a corrective action that can adjust the process accordingly).

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. Please use meaningful names.

Internally, the FB contains the following 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, it 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.