Skip to content

Standard and utility function blocks

eaxPLCReferenceFreeProView as Markdown

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.


TimelineTON, TOF and TP over the same input
TON, TOF and TP over the same inputThe 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.IN onIN offIN on, brieflyINPUTINthe same for all threeTON, ON-DELAYQETTOF, OFF-DELAYQETTP, PULSEQET
ET counts while the time runs. After its delay, TOF's ET holds PT until IN rises again.
  • 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.

Delays turning on an output signal for a preset time interval PT.

  • Inputs:
    • IN: BOOL: Trigger input
    • PT: TIME: Preset delay duration
  • Outputs:
    • Q: BOOL: Output turned ON when elapsed time ET >= PT while IN = TRUE
    • ET: TIME: Elapsed time counter

Keeps output Q energized for a preset time PT after input IN drops to FALSE.

  • Inputs: IN: BOOL, PT: TIME
  • Outputs:
    • Q: BOOL: TRUE while IN = TRUE, and for PT after IN falls
    • ET: TIME: 0 while IN = TRUE; counts from the falling edge of IN; after the delay it holds the value it reached (the PT in force then) until IN rises again, as IEC 61131-3 specifies, even if PT changes meanwhile. It is 0 before 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.

Generates a pulse of fixed duration PT regardless of how long IN remains TRUE.

  • Inputs: IN: BOOL, PT: TIME
  • Outputs: Q: BOOL, ET: TIME
  • R_TRIG: Output Q produces a single-cycle pulse on the rising edge of CLK (FALSE -> TRUE).
  • F_TRIG: Output Q produces a single-cycle pulse on the falling edge of CLK (TRUE -> FALSE).
  • SR (Set-dominant): Q1 := (NOT RESET AND Q1) OR SET1
  • RS (Reset-dominant): Q1 := NOT RESET1 AND (Q1 OR SET)
  • CTU: Increments CV on rising edge of CU. Q := CV >= PV.
  • CTD: Decrements CV on rising edge of CD. Q := CV <= 0.
  • CTUD: Bidirectional counter with separate up/down triggers, LOAD, and RESET.

Generates continuous square-wave pulses with distinct high and low intervals.

  • Inputs: ENABLE: BOOL, TIMELOW: TIME, TIMEHIGH: TIME
  • Outputs: OUT: BOOL

Generates analog waveforms with selectable mode:

  • MODE 1: Triangle wave
  • MODE 2: Positive triangle wave
  • MODE 3: Sawtooth rising
  • MODE 4: Sawtooth falling
  • MODE 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_ACTIVE and OVERFLOW diagnostic flags.

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.

Prevents signal chatter around a threshold:

  • OUT := TRUE when IN >= HIGH
  • OUT := FALSE when IN <= LOW
  • Retains previous state when LOW < IN < HIGH
  • O: BOOL: High alarm (IN > HIGH)
  • U: BOOL: Low alarm (IN < LOW)
  • IL: BOOL: In-limit indicator (LOW <= IN <= HIGH)

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.