IEC 61131-3 Function Block Reference Library
A complete reference for every standard function block in PLC programming. Each entry includes input/output definitions, ladder logic examples, structured text code, timing diagrams, and platform-specific notes for Siemens, Allen-Bradley, and CODESYS.
IEC 61131-3 defines a set of standard function blocks that form the building blocks of PLC programs across all major platforms. These function blocks include timers (TON, TOF, TP), counters (CTU, CTD, CTUD), bistables (SR, RS), edge detectors (R_TRIG, F_TRIG), comparison operations, math functions, type conversions, process control blocks like PID, string operations, and selection functions. Understanding these function blocks is essential for writing portable, maintainable PLC code that works across Siemens TIA Portal, Allen-Bradley Studio 5000, CODESYS, and other IEC-compliant environments.
Timers & Counters
Timer and counter function blocks for controlling time-based operations and counting events in PLC programs.
TON (Timer On-Delay)
BeginnerStarts timing on rising edge, output activates after preset delay.
TOF (Timer Off-Delay)
BeginnerOutput stays TRUE for preset time after input goes FALSE.
TP (Timer Pulse)
BeginnerGenerates a fixed-duration pulse on rising edge of input.
RTO (Retentive Timer On)
IntermediateTimer retains accumulated value when input goes FALSE; requires manual reset.
TONR (Timer On-Delay Retentive)
IntermediateSiemens retentive on-delay timer that accumulates time across multiple enable cycles.
RTOR (Retentive Timer On with Reset)
IntermediateRetentive on-delay timer with integrated reset input for accumulated time clearing.
Counters
Counter function blocks for tracking events, quantities, and sequential operations in industrial automation.
CTU (Counter Up)
BeginnerCounts up on each rising edge; output activates when count reaches preset.
CTD (Counter Down)
BeginnerCounts down from preset value; output activates when count reaches zero.
CTUD (Counter Up/Down)
IntermediateCounts both up and down with separate done outputs for each direction.
CTU with Auto-Reset
IntermediateCounter that automatically resets after reaching preset, creating repeating count cycles.
HSC (High-Speed Counter)
AdvancedHardware-accelerated counter for high-frequency pulse inputs beyond normal scan rate.
Bistables & Edge Detection
Bistable (flip-flop) and edge detection function blocks for latching outputs and detecting signal transitions.
SR (Set-Reset Flip-Flop, Set Dominant)
BeginnerSet-dominant flip-flop: output latches TRUE on set, cleared by reset. Set wins if both active.
RS (Reset-Set Flip-Flop, Reset Dominant)
BeginnerReset-dominant flip-flop: reset wins if both set and reset are active simultaneously.
R_TRIG (Rising Edge Detection)
BeginnerDetects FALSE-to-TRUE transition, outputs single-scan pulse on rising edge.
F_TRIG (Falling Edge Detection)
BeginnerDetects TRUE-to-FALSE transition, outputs single-scan pulse on falling edge.
Comparison Operations
Comparison function blocks for evaluating relationships between values in PLC logic.
GT (Greater Than)
BeginnerReturns TRUE when first input is strictly greater than second input.
GE (Greater Than or Equal)
BeginnerReturns TRUE when first input is greater than or equal to second input.
EQ (Equal)
BeginnerReturns TRUE when both inputs are exactly equal.
NE (Not Equal)
BeginnerReturns TRUE when inputs are not equal to each other.
LE (Less Than or Equal)
BeginnerReturns TRUE when first input is less than or equal to second input.
LT (Less Than)
BeginnerReturns TRUE when first input is strictly less than second input.
Math Operations
Mathematical function blocks for arithmetic calculations in PLC programs.
ADD (Addition)
BeginnerAdds two or more numeric values and outputs the sum.
SUB (Subtraction)
BeginnerSubtracts second input from first input, outputs the difference.
MUL (Multiplication)
BeginnerMultiplies two numeric values and outputs the product.
DIV (Division)
BeginnerDivides first input by second input, outputs the quotient.
MOD (Modulo)
IntermediateReturns the remainder after integer division of two values.
ABS (Absolute Value)
BeginnerReturns the absolute (non-negative) value of the input.
Data Movement & Bit Shifting
Function blocks for moving data between registers and performing bit manipulation operations.
MOVE (Data Move)
BeginnerCopies a value from source to destination for any data type.
SWAP (Byte Swap)
IntermediateReverses byte order of a word value for endianness conversion.
SHL (Shift Left)
IntermediateShifts bits left by N positions, filling right with zeros. Equivalent to multiply by 2^N.
SHR (Shift Right)
IntermediateShifts bits right by N positions. Equivalent to integer division by 2^N.
ROL (Rotate Left)
IntermediateRotates bits left; bits shifted out the left wrap around to the right.
Type Conversion
Type conversion function blocks for converting between different data types in IEC 61131-3 programs.
INT_TO_REAL (Integer to Real Conversion)
BeginnerConverts 16-bit integer to 32-bit floating-point real value.
REAL_TO_INT (Real to Integer Conversion)
BeginnerConverts 32-bit floating-point value to 16-bit integer with rounding.
BOOL_TO_INT (Boolean to Integer Conversion)
BeginnerConverts FALSE to 0 and TRUE to 1 for numeric operations.
INT_TO_STRING (Integer to String Conversion)
IntermediateConverts integer value to its decimal string representation for display or logging.
ANY_TO_ANY (Universal Type Conversion)
IntermediateGeneral type conversion framework covering all IEC 61131-3 type conversion functions.
Process Control
Advanced process control function blocks including PID controllers, PWM outputs, and signal conditioning.
PID (Proportional-Integral-Derivative Controller)
AdvancedClosed-loop feedback controller using proportional, integral, and derivative terms.
PWM (Pulse Width Modulation)
IntermediateConverts analog percentage to pulsed digital output with proportional duty cycle.
RAMP (Ramp Function / Rate Limiter)
IntermediateLimits rate of change to create smooth transitions between values.
LIMIT (Limiter / Clamp)
BeginnerClamps a value between minimum and maximum boundaries.
String Operations
String manipulation function blocks for handling text data in PLC programs.
CONCAT (String Concatenation)
IntermediateJoins two or more strings into a single combined string.
LEFT (Left String Extract)
IntermediateExtracts a specified number of characters from the beginning of a string.
RIGHT (Right String Extract)
IntermediateExtracts a specified number of characters from the end of a string.
FIND (String Search)
IntermediateFinds position of a substring within a string; returns 0 if not found.
Selection & Limiting
Selection and limiting function blocks for choosing between values and clamping signals within ranges.
SEL (Binary Selector)
BeginnerSelects between two values based on a boolean condition: FALSE=IN0, TRUE=IN1.
MUX (Multiplexer)
IntermediateSelects one of N input values based on an integer selector index.
MAX (Maximum Selection)
BeginnerReturns the larger of two or more input values.
MIN (Minimum Selection)
BeginnerReturns the smaller of two or more input values.
LIMIT (Value Limiter)
BeginnerConstrains input value to specified minimum and maximum range.
Browse by Category
Put These Function Blocks Into Practice
Get 20 production-ready ladder logic templates that use these function blocks in real-world applications -- motor control, PID loops, safety interlocks, and more.
Get the Ladder Logic Pack -- $29