Timer function blocks
All timers take a Boolean input IN and a preset duration PT, and produce a
Boolean output Q plus the elapsed time ET. The base types use TIME; the
typed variants make the PT/ET width explicit. In logiccloud all three forms
(TP, TP_TIME, TP_LTIME, etc.) share the same signature shown below.
| Variants | Description |
|---|---|
TP, TP_TIME, TP_LTIME | Pulse timer |
TON, TON_TIME, TON_LTIME | On-delay timer |
TOF, TOF_TIME, TOF_LTIME | Off-delay timer |
Common I/O (all timers)
| Direction | Name | Type | Meaning |
|---|---|---|---|
| Input | IN | BOOL | Trigger / start condition |
| Input | PT | TIME | Preset time (pulse width or delay) |
| Output | Q | BOOL | Timer output |
| Output | ET | TIME | Elapsed time |
Signature (shared by all timer types and their typed variants):
FUNCTION_BLOCK TP // also TON, TOFVAR_INPUT IN : BOOL; PT : TIME;END_VARVAR_OUTPUT Q : BOOL; ET : TIME;END_VAREND_FUNCTION_BLOCKTP — pulse
Section titled “TP — pulse”Generates a pulse of fixed length PT on the rising edge of IN. Once started,
the pulse runs to completion regardless of further changes on IN; ET counts
up to PT and then holds. When the pulse ends and IN is low again, the timer
resets.
VAR pulse : TP;END_VAR
pulse(IN := trigger, PT := T#500ms);output := pulse.Q; // TRUE for 500 ms after each rising edge of triggerTiming:
- Rising edge of
IN→QbecomesTRUE,ETstarts counting from0. - While
ET < PT→QstaysTRUEeven ifINfalls. - When
ETreachesPT→QbecomesFALSE,ETholds atPTuntilINis low.
TON — on-delay
Section titled “TON — on-delay”Delays a rising edge. Q becomes TRUE only after IN has been continuously
TRUE for at least PT. Any drop of IN resets ET to 0 and Q to FALSE.
VAR onDelay : TON;END_VAR
onDelay(IN := startBtn, PT := T#2s);motor := onDelay.Q; // motor starts 2 s after startBtn goes highTiming:
INlow →ET = 0,Q = FALSE.INhigh →ETcounts up; whenET = PT,QbecomesTRUE.INfalls beforePTis reached → timer resets,QstaysFALSE.
TOF — off-delay
Section titled “TOF — off-delay”Delays a falling edge. Q follows IN to TRUE immediately, but stays TRUE
for PT after IN drops.
VAR offDelay : TOF;END_VAR
offDelay(IN := running, PT := T#5s);fan := offDelay.Q; // fan keeps running 5 s after running goes lowTiming:
- Rising edge of
IN→QbecomesTRUEimmediately,ET = 0. INfalls →ETcounts up;QstaysTRUEuntilET = PT, thenQ = FALSE.INrises again beforePTelapses → the off-delay is cancelled.