IEC61131-3
What Is IEC 61131-3?
IEC 61131-3 is an international standard that standardizes the programming languages of PLCs (Programmable Logic Controllers).
Its purpose is to unify the program notation that differed between PLC manufacturers and to improve the reusability and maintainability of programs.
Five Standard Programming Languages
Graphical languages
LD (Ladder Diagram)
A language based on relay circuits.
FBD (Function Block Diagram)
A language that expresses processing by connecting blocks with signal lines.
SFC (Sequential Function Chart)
A language that describes process "steps" and "transition conditions" like a flowchart.
Textual languages
ST (Structured Text)
A high/mid-level language similar to C and Pascal. Complex numeric calculations, data processing (arrays and strings) and
conditional branching (IF statements, FOR loops, etc.) can be written compactly and cleanly.
IL (Instruction List)
So-called mnemonics. A low-level language similar to assembly language.
Choosing Between Them
Programs are basically written by combining LD (ladder) and FBD (FUNs, FBs)
By grouping frequently used processing into modules, it can be reused.
Modules (your own FUNs or FBs) can be shared as company-wide assets, and when a bug is found, fixing the module fixes every program that uses it, which also improves quality
ST makes complex numeric calculations, data processing (arrays, string processing), loops (FOR statements) and conditional branching (IF statements) easier to read
Data type
Basic type
| Category | Data typeSize | |
|---|---|---|
| Boolean | BOOL | TRUE/FALSE |
| Bit string | BYTE | 8bit |
| WORD | 16bit | |
| DWORD | 32bit | |
| LWORD | 64bit | |
| Integer types | SINT | 8bit |
| INT | 16bit | |
| DINT | 32bit | |
| LINT | 64bit | |
| USINT | 8bit | |
| UINT | 16bit | |
| UDINT | 32bit | |
| ULINT | 64bit | |
| Real types | REAL | 32bit |
| LREAL | 64bit | |
| STRING | Number of characters + NULL |
Date type
| Category | Data typeSize | |
|---|---|---|
| Duration type | TIME | 64bit |
| Date type | DATE | 64bit |
| Time of day type | TIME_OF_DAY | 64bit |
| Date and time type | DATE_AND_TIME | 64bit |
Arrays
| Category | Example |
|---|---|
| INT array with 100 elements | ARRAY[0..99] OF INT |
Structures
| Name | Data type | |
|---|---|---|
| mySTRUCT | STRUCT | |
| mem1 | DINT | |
| mem2 | INT | |
| mem3 | STRING | |
Unions
| Name | Data type | |
|---|---|---|
| myUNION | UNION | |
| mem1 | ARRAY[0..3] OF BYTE | |
| mem2 | ARRAY[0..1] OF WORD | |
| mem3 | DWORD | |
Enumerations
| Name | Value | |
|---|---|---|
| myENUM | ||
| right | 1 | |
| left | 2 | |
| center | 3 | |
Variable Scope
Local
Variable used only within a POU
Global variable
Variable usable everywhere
Input variable
Variable writable from an external network
Output variable
Variable readable from an external network
In-out variable
Variable readable and writable from an external network
FUNs and FBs
Function (FUN)
Behavior
A function executes when its input turns ON and returns a result. Input and output values do not retain state.
Examples of standard FUNs
- MOV
- SHL
- Decoder etc.
Function Block (FB)
Behavior
Instances (children) are created from the function block definition (parent).
Each instance is handled separately; if you create multiple instances, each behaves independently.
Note that, unlike functions, function blocks are executed every scan.
Examples of standard FBs
- TON
- PIDAT
- SktUDPCreate
- FileOpen etc.
Compatibility Between Manufacturers
Programs using only contacts and outputs, like relay circuits, do not depend on the manufacturer.
However, the implementation and names of FBs and FUNs differ somewhat between manufacturers.
Below are some of the FUNs and FBs defined by IEC 61131-3
Function
Arithmetic
- ADD, SUB, MUL, DIV, MOD : addition, subtraction, multiplication, division, modulo
- ABS : absolute value
- SQRT : square root
- SIN, COS, TAN, ASIN, ACOS, ATAN : trigonometric functions
- EXPT : exponentiation
- LN, LOG : logarithms
Bit operations
- AND, OR, XOR, NOT : bitwise logical operations
- SHL, SHR : bit shift left / right
- ROR, ROL : bit rotate right / left
Data type conversion
- INT_TO_UDINT etc. : convert from any data type to another
- INT_TO_REAL, REAL_TO_INT : conversion between integer and real
- BCD_TO_INT, INT_TO_BCD : conversion between BCD code and integer
Selection and comparison
- MOVE : assign a value
- EQ, NE, GT, GE, LT, LE : comparison operations
- LIMIT : upper/lower limit of a value
- MAX, MIN : select the maximum/minimum of several values
- MUX : multiplexer
String operations
- LEN : get string length
- CONCAT : concatenate strings
- INSERT : insert into a string
- DELETE : delete from a string
- REPLACE : replace in a string
- FIND : search a string
Function block
Timers and counters
- TON : on-delay timer
- TOF : off-delay timer
- TP : pulse timer
- CTU : up counter
- CTD : down counter
- CTUD : up-down counter
Related pages
PLC

FUN/FB Comparison by Manufacturer
Compares the functions and function blocks of OMRON NX and KEYENCE KV-X.
