Skip to content

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.

VariantsDescription
TP, TP_TIME, TP_LTIMEPulse timer
TON, TON_TIME, TON_LTIMEOn-delay timer
TOF, TOF_TIME, TOF_LTIMEOff-delay timer

Common I/O (all timers)

DirectionNameTypeMeaning
InputINBOOLTrigger / start condition
InputPTTIMEPreset time (pulse width or delay)
OutputQBOOLTimer output
OutputETTIMEElapsed time

Signature (shared by all timer types and their typed variants):

FUNCTION_BLOCK TP // also TON, TOF
VAR_INPUT
IN : BOOL;
PT : TIME;
END_VAR
VAR_OUTPUT
Q : BOOL;
ET : TIME;
END_VAR
END_FUNCTION_BLOCK

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 trigger

Timing:

  • Rising edge of INQ becomes TRUE, ET starts counting from 0.
  • While ET < PTQ stays TRUE even if IN falls.
  • When ET reaches PTQ becomes FALSE, ET holds at PT until IN is low.

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 high

Timing:

  • IN low → ET = 0, Q = FALSE.
  • IN high → ET counts up; when ET = PT, Q becomes TRUE.
  • IN falls before PT is reached → timer resets, Q stays FALSE.

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 low

Timing:

  • Rising edge of INQ becomes TRUE immediately, ET = 0.
  • IN falls → ET counts up; Q stays TRUE until ET = PT, then Q = FALSE.
  • IN rises again before PT elapses → the off-delay is cancelled.