Glossary · PLC and control programming
Function (IEC 61131-3)
Also known as: FUNCTION, FC
German: Funktion
In IEC 61131-3, a function is a program organization unit that, when executed with the same input values, always returns the same result and has no internal state stored between calls.
- PLC programming
- Standards
In one sentence
An IEC 61131-3 function is a program unit without memory between calls: the same inputs always give the same result.
Example
A function ScaleAnalog converts a raw input value from 0 to 27648 into a temperature from 0 to 150 °C.
How it applies
- Engineering: Functions suit calculations and conversions: scaling, limits, unit conversions, checksums. IEC 61131-3 also defines standard functions such as ADD, MAX, SEL or type conversions. Because a function keeps no state, it can be called anywhere without creating an instance.
- Testing: The lack of internal state makes functions easy to unit-test: a table of inputs and expected outputs is enough.
- Vendor terms: In Siemens environments, the equivalent block is called FC. Some tools allow functions to access global data, which weakens the no-state rule; coding guidelines usually forbid this.
- Documentation: Document each library function with purpose, inputs, output, units, valid ranges and behavior at limits. This reference information maps well to a DITA reference topic.
Function vs. function block
A function has no memory: it returns a result computed from its inputs. A Function block (FB) has an instance with internal data kept between calls, so it can implement timers, counters or state machines.