Functions and function blocks (FUNCTION, FUNCTION_BLOCK)

How a function differs from a function block, instances and memory, the VAR_INPUT/VAR_OUTPUT/VAR_IN_OUT interface, and rules for reusable blocks.

Program organisation units (POUs)

IEC 61131-3 distinguishes three kinds of program organisation unit:

POUMemory between callsTypical use
FUNCTIONnonecomputing from inputs: scaling, limiting, conversion
FUNCTION_BLOCKyes, in the instancean object with state: motor, valve, controller, timer
PROGRAMyestop level, called by a task

A function always returns the same result for the same inputs. A function block keeps its variables between calls — for that an instance is declared. On Siemens a function is an FC, a block an FB, and instance memory lives in an instance DB or as a multi-instance inside another FB.

Interface

SectionPurpose
VAR_INPUTinputs, copied on call
VAR_OUTPUToutputs, read after the call
VAR_IN_OUTpassed by reference: the block reads and modifies the caller's variable
VARinternal instance variables, kept between calls
VAR_TEMPtemporary, exist only during the call
FUNCTION_BLOCK FB_Motor
VAR_INPUT
    Start, Stop, Feedback : BOOL;
    FeedbackTime : TIME := T#3S;
END_VAR
VAR_OUTPUT
    Run, Fault : BOOL;
END_VAR
VAR
    tFeedback : TON;
END_VAR

Call: Motor1(Start := bStart, Stop := bStop, Feedback := bFb); — each motor has its own instance Motor1, Motor2, …

Rules for reusable blocks

  • One instance, one call per cycle. Calling the same instance elsewhere in the program breaks the timers and edges inside it. The code reviewer reports this.
  • The block does not touch global variables or I/O directly — everything goes through the interface. Otherwise it cannot be reused or tested.
  • A fault latches until explicitly acknowledged (Reset) and does not clear itself when the cause disappears.
  • Safe default state: on a fault or loss of communication the block's output goes to a state that creates no hazard.
  • Temporary variables (VAR_TEMP) do not keep their value — never use them for memory between cycles.

Tools

Loading the map…

Sources

  1. IEC 61131-3:2025 Programmable controllers — Part 3: Programming languages — IEC
  2. TwinCAT 3 PLC Library Tc2_Standard — Beckhoff Automation

Updated 2026-10-01