IEC 61131-3 Reference
Free reference guide: IEC 61131-3 Reference
About IEC 61131-3 Reference
The IEC 61131-3 Reference provides a complete, searchable guide to the international standard for PLC programming languages. It covers all five languages defined by the standard: Structured Text (ST) with high-level constructs including IF/ELSIF/THEN, CASE state machines, FOR/WHILE loops, variable declarations (BOOL, INT, REAL, STRING, TIME), function blocks with VAR_INPUT/VAR_OUTPUT, and composite data types using STRUCT and ARRAY. Code examples demonstrate practical patterns like motor control state machines and parameter-driven automation.
The reference includes detailed coverage of graphical programming languages: Ladder Diagram (LD) with NO/NC contacts (a-contact and b-contact), positive/negative edge detection (P/N contacts), output coils, set/reset latches, self-holding circuits, and timer integration; Function Block Diagram (FBD) with serial, parallel, and feedback block connections; and Instruction List (IL) with operators (LD, ST, AND, OR, ADD, CAL, JMP) and modifiers (N for negation, C for conditional execution, parentheses for grouping).
Advanced topics include Sequential Function Chart (SFC) for state-based control with steps, transitions, action qualifiers (N for non-stored, P for pulse, S for set, R for reset, L for time-limited, D for time-delayed), alternative and simultaneous branching patterns. The guide covers the complete IEC 61131-3 data type hierarchy (ANY tree with ANY_BIT, ANY_NUM, ANY_STRING, ANY_DATE), explicit type conversion functions (*_TO_* pattern), standard function blocks (TON/TOF/TP timers, CTU/CTD/CTUD counters, R_TRIG/F_TRIG edge detection, SR/RS flip-flops), and PROGRAM/TASK configuration for scan cycle management.
Key Features
- Structured Text (ST) syntax reference with IF/CASE/FOR constructs, variable declarations, function block calls, and STRUCT/ARRAY types
- Ladder Diagram (LD) guide covering NO/NC contacts, P/N edge contacts, output coils, set/reset latches, and self-holding circuits
- Function Block Diagram (FBD) connection patterns: serial, parallel, and feedback with AND/OR/TON block examples
- Sequential Function Chart (SFC) with step/transition design, 10 action qualifiers (N, P, P0, S, R, L, D, SD, DS, SL), and alternative/simultaneous branching
- Instruction List (IL) operators (LD, ST, AND, OR, ADD, CAL, JMP) with N/C modifiers and parenthesis grouping
- Complete IEC 61131-3 data type hierarchy: BOOL through LREAL, STRING/WSTRING, TIME/DATE/DT, and ANY generic types
- Standard function blocks: TON/TOF/TP timers, CTU/CTD/CTUD counters, R_TRIG/F_TRIG edge detection, SR/RS flip-flops
- PROGRAM/TASK configuration with scan interval settings (e.g., T#10MS main task, T#1MS fast motion task)
Frequently Asked Questions
What are the five programming languages in IEC 61131-3?
IEC 61131-3 defines five programming languages: (1) Structured Text (ST) - a high-level textual language similar to Pascal/VB, (2) Ladder Diagram (LD) - a graphical language based on relay circuit logic, (3) Function Block Diagram (FBD) - a graphical language using connected function blocks, (4) Sequential Function Chart (SFC) - a graphical language for state-based sequential control, and (5) Instruction List (IL) - a low-level textual language similar to assembly. ST and LD are the most widely used in modern PLC programming.
How do I implement a state machine in Structured Text?
Use the CASE statement with an integer step variable: CASE nStep OF 0: (initialization, set nStep := 10); 10: (wait for start, IF bStart THEN nStep := 20); 20: (run process); 100: (error handling); ELSE nStep := 0; END_CASE. This pattern is the standard approach for sequential automation logic in ST, providing clear state transitions and easy debugging. Each state can call function blocks and set outputs.
What is the difference between TON, TOF, and TP timers?
TON (On-Delay) starts timing when IN becomes TRUE; Q becomes TRUE after PT elapses; Q immediately becomes FALSE when IN goes FALSE. TOF (Off-Delay) immediately sets Q to TRUE when IN becomes TRUE; Q remains TRUE and starts timing when IN goes FALSE; Q becomes FALSE after PT elapses. TP (Pulse) generates a fixed-duration pulse of PT length on the rising edge of IN, ignoring further IN changes during the pulse.
How do SFC action qualifiers work?
SFC action qualifiers determine when and how step actions execute: N (Non-stored) executes every scan while the step is active, P (Pulse) executes once on step entry, P0 executes once on step exit, S (Set) activates and remains active even after the step deactivates, R (Reset) deactivates a previously set action, L (time-Limited) activates for a specified time, D (time-Delayed) activates after a delay, SD (Stored and Delayed), DS (Delayed and Stored), and SL (Stored and time-Limited).
What is the ANY type hierarchy in IEC 61131-3?
The ANY type is the root of the generic type hierarchy used for function overloading. ANY_BIT includes BOOL, BYTE, WORD, DWORD, LWORD. ANY_NUM splits into ANY_INT (SINT, INT, DINT, LINT and unsigned USINT, UINT, UDINT, ULINT) and ANY_REAL (REAL for 32-bit IEEE 754, LREAL for 64-bit). ANY_STRING covers STRING and WSTRING. ANY_DATE includes DATE, TOD (Time of Day), and DT (Date and Time). ANY_DURATION contains TIME. There is no implicit type conversion; use explicit *_TO_* functions like INT_TO_REAL().
How do I declare and use function blocks in Structured Text?
Declare with FUNCTION_BLOCK FB_Name, then define VAR_INPUT, VAR_OUTPUT, and internal VAR sections. Call by first declaring an instance (VAR fbValve1 : FB_Valve; END_VAR), then invoking with fbValve1(bOpen := TRUE). Access outputs with dot notation: IF fbValve1.bOpened THEN ... END_IF. Function blocks retain their state between scan cycles, unlike FUNCTION which has no persistent state and returns a single value.
What is the difference between SR and RS flip-flops and when should I use each?
SR (Set-priority) makes Set dominant: if both SET1 and RESET are TRUE simultaneously, Q1 is TRUE. RS (Reset-priority) makes Reset dominant: if both SET and RESET1 are TRUE simultaneously, Q1 is FALSE. Use RS (Reset-priority) for safety-critical applications like emergency stops, where the reset/stop condition must always override. Use SR (Set-priority) for self-holding circuits where the run/start condition should persist.
How do I configure PROGRAM and TASK assignments?
A PROGRAM is the top-level Program Organization Unit (POU) that contains the main execution logic. A TASK defines the execution schedule. Assign programs to tasks with: TASK Main_Task(INTERVAL := T#10MS); PROGRAM Main WITH Main_Task. For time-critical operations, create a separate fast task: TASK Fast_Task(INTERVAL := T#1MS); PROGRAM Motion WITH Fast_Task. This allows different scan rates for different control loops, such as 10ms for general logic and 1ms for motion control.