Standard and utility function blocks
Migrated page, not yet verified against the current code. Treat values, paths and examples as indicative until this notice is removed.
Pinout, timing and formulas of the IEC 61131-3 function blocks implemented in pkg/plc/fb/.
This hand-written page covers 18 of the 29 native blocks and none of the Structured Text library blocks. The generated function block reference, which covers every block, will replace it.
1. Standard Library (Standard.lib)
Section titled “1. Standard Library (Standard.lib)”- TRUE
- ET counts
- ET holds PT
Read as text
The same input IN drives the three timers, with a preset time PT of 20 units on this axis. IN is TRUE for 30 units, then for 8 units. TON turns Q on PT after IN rises and off when IN falls, so the short pulse gives no output. TOF keeps Q on until PT after IN falls. TP gives a pulse of exactly PT at each rising edge, even when IN is shorter.
Input
- IN: the same for all three
TON, on-delay
- Q. TRUE from PT after IN rose until IN falls. The second IN pulse, shorter than PT, gives no output.
- ET. ET is 0 as soon as IN is FALSE.
TOF, off-delay
- Q. TRUE while IN is TRUE and until PT after IN falls.
- ET. ET counts from the falling edge of IN and reaches PT when Q turns off. It holds PT until IN rises again, which sets it to 0.
TP, pulse
- Q. A pulse of exactly PT from each rising edge of IN, however long IN stays TRUE.
- ET. At the end of the pulse ET stays at PT while IN is TRUE, and is 0 once IN is FALSE.
1.1 TON (On-Delay Timer)
Section titled “1.1 TON (On-Delay Timer)”Delays turning on an output signal for a preset time interval PT.
- Inputs:
IN: BOOL: Trigger inputPT: TIME: Preset delay duration
- Outputs:
Q: BOOL: Output turned ON when elapsed timeET >= PTwhileIN = TRUEET: TIME: Elapsed time counter
1.2 TOF (Off-Delay Timer)
Section titled “1.2 TOF (Off-Delay Timer)”Keeps output Q energized for a preset time PT after input IN drops to FALSE.
- Inputs:
IN: BOOL,PT: TIME - Outputs:
Q: BOOL:TRUEwhileIN = TRUE, and forPTafterINfallsET: TIME:0whileIN = TRUE; counts from the falling edge ofIN; after the delay it holds the value it reached (thePTin force then) untilINrises again, as IEC 61131-3 specifies, even ifPTchanges meanwhile. It is0before the first delay and after a reset.
Earlier eaxPLC versions set ET back to 0 in the cycle after Q turned off. A program that tests TOF.ET = 0 to detect the end of the delay now sees ET = PT instead: test NOT Q for the end of the delay.
1.3 TP (Pulse Timer)
Section titled “1.3 TP (Pulse Timer)”Generates a pulse of fixed duration PT regardless of how long IN remains TRUE.
- Inputs:
IN: BOOL,PT: TIME - Outputs:
Q: BOOL,ET: TIME
1.4 R_TRIG & F_TRIG (Edge Detectors)
Section titled “1.4 R_TRIG & F_TRIG (Edge Detectors)”R_TRIG: OutputQproduces a single-cycle pulse on the rising edge ofCLK(FALSE -> TRUE).F_TRIG: OutputQproduces a single-cycle pulse on the falling edge ofCLK(TRUE -> FALSE).
1.5 SR & RS (Bistable Flip-Flops)
Section titled “1.5 SR & RS (Bistable Flip-Flops)”SR(Set-dominant):Q1 := (NOT RESET AND Q1) OR SET1RS(Reset-dominant):Q1 := NOT RESET1 AND (Q1 OR SET)
1.6 CTU, CTD, CTUD (Counters)
Section titled “1.6 CTU, CTD, CTUD (Counters)”CTU: IncrementsCVon rising edge ofCU.Q := CV >= PV.CTD: DecrementsCVon rising edge ofCD.Q := CV <= 0.CTUD: Bidirectional counter with separate up/down triggers,LOAD, andRESET.
2. Utility Library (Util.lib)
Section titled “2. Utility Library (Util.lib)”2.1 BLINK (Asymmetric Pulse Generator)
Section titled “2.1 BLINK (Asymmetric Pulse Generator)”Generates continuous square-wave pulses with distinct high and low intervals.
- Inputs:
ENABLE: BOOL,TIMELOW: TIME,TIMEHIGH: TIME - Outputs:
OUT: BOOL
2.2 GEN (Waveform Generator)
Section titled “2.2 GEN (Waveform Generator)”Generates analog waveforms with selectable mode:
MODE 1: Triangle waveMODE 2: Positive triangle waveMODE 3: Sawtooth risingMODE 4: Sawtooth fallingMODE 5: Sine wave (sin(2π·t/T) × AMPLITUDE)MODE 6: Cosine wave (cos(2π·t/T) × AMPLITUDE)MODE 7: Rectangle / square wave
2.3 PID & PID_FIXCYCLE (Closed-Loop Controllers)
Section titled “2.3 PID & PID_FIXCYCLE (Closed-Loop Controllers)”Implements standard parallel PID control law:
Y = KP · ( e(t) + (1/TN) · ∫ e(t) dt + TV · de(t)/dt ) + Y_OFFSET- Anti-windup clamping to
[Y_MIN, Y_MAX]. - Manual override mode with
Y_MANUAL. LIMITS_ACTIVEandOVERFLOWdiagnostic flags.
2.4 LIN_TRAFO (Linear Scaling)
Section titled “2.4 LIN_TRAFO (Linear Scaling)”Transforms input value from [IN_MIN, IN_MAX] into [OUT_MIN, OUT_MAX]:
OUT = OUT_MIN + (IN − IN_MIN) / (IN_MAX − IN_MIN) × (OUT_MAX − OUT_MIN)2.5 RAMP_REAL & RAMP_INT (Rate-of-Change Limiters)
Section titled “2.5 RAMP_REAL & RAMP_INT (Rate-of-Change Limiters)”Limits the maximum upward (ASCEND) and downward (DESCEND) rate of change per unit time TIMEBASE.
2.6 HYSTERESIS (Schmitt Trigger)
Section titled “2.6 HYSTERESIS (Schmitt Trigger)”Prevents signal chatter around a threshold:
OUT := TRUEwhenIN >= HIGHOUT := FALSEwhenIN <= LOW- Retains previous state when
LOW < IN < HIGH
2.7 LIMITALARM (Deadband Alarm)
Section titled “2.7 LIMITALARM (Deadband Alarm)”O: BOOL: High alarm (IN > HIGH)U: BOOL: Low alarm (IN < LOW)IL: BOOL: In-limit indicator (LOW <= IN <= HIGH)
3. Arrays of function block instances
Section titled “3. Arrays of function block instances”Every block on this page, and every user FUNCTION_BLOCK, can be declared as an array. Each element is a full instance with its own state, called and read like a named instance. A 2-D array is an array of arrays: g[i, j] and g[i][j] are the same element. An index outside the bounds stops the scan with “array index out of range”.
VAR t : ARRAY[0..7] OF TON; g : ARRAY[1..2, 1..3] OF FB_Valve; i, j : INT;END_VAR
FOR i := 0 TO 7 DO t[i](IN := Run[i], PT := T#2s); Done[i] := t[i].Q;END_FOR;FOR i := 1 TO 2 DO FOR j := 1 TO 3 DO g[i, j](); END_FOR; END_FOR;A safety target can name an element’s member (t[3].Q, g[1, 2].Cmd). The code generation, the cost per scan and the safety-target rules are in Compiler and bytecode VM.