Skip to content

17Standard function blocks

Timers: TON, TOF and TP

The three standard IEC 61131-3 timers, what each one does to the clock, and using them for alarm de-bounce and a run-on fan.

Lesson 17 of 3412 minIEC 61131-3

Three blocks, four pins

The standard gives you three timers and they share the same interface:

Pin

Type

Meaning

IN

BOOL

the start signal

PT

TIME

preset time

Q

BOOL

the output

ET

TIME

elapsed time

The whole difference is when Q goes true and when it drops.

TON · on-delay

Q goes TRUE after IN has stayed true for the whole of PT, and drops immediately when IN drops. Any break in IN before the time is up resets ET to zero and the count starts again.

IN  ___----------______----___
ET  ___/\/\/\/\/\__0___/\__0__
Q   _______-------______________   (PT = 3s)

TOF · off-delay

Q goes TRUE immediately when IN rises, and stays TRUE for PT after IN drops. The timer counts after the signal goes away.

IN  ___-------_____________
Q   ___-------------________    (PT = 5s after the fall)

TP · pulse

Q goes TRUE on the rise of IN and stays true for exactly PT, however long IN stays on. Holding the button for ten minutes does not stretch the pulse.

IN  ___-----------------____
Q   ___------_______________   (PT = 500ms)

Calling one

VAR
  AlmDly : TON;
END_VAR

AlmDly(IN := LSH, PT := T#3s);
HiAlm := AlmDly.Q;

The call must run every scan. Put it inside an IF that is sometimes skipped and the timer freezes mid-count. Keep the call at the top level and control it through IN.

Use one: alarm de-bounce

The alarm standard ISA-18.2 recommends an on-delay on every process alarm. A level hovering at 90% produces 40 alarms a minute, floods the operator, and the whole screen gets ignored. Three seconds turns that into one real alarm:

AlmDly(IN := Level > 90.0, PT := T#3s);
HiAlm := AlmDly.Q;

Add a deadband on the return and the chatter is gone for good.

Use two: a run-on fan

A hot motor needs cooling after it stops, so the fan keeps turning for five minutes. That is literally a TOF:

RunOn(IN := Pump, PT := T#5s);
Valve := RunOn.Q;

The same shape covers a lamp that stays lit after the event and a valve that closes late.

Writing time

T#500ms, T#3s, T#2m30s, T#1h. Never count your own scans into a REAL: a timer measures real time and stays correct when the scan time changes.

Try it in the lab

The lab runs in your browser: an ST editor, a virtual process that suits the lesson, the same program as a live ladder diagram, a watch table, and export to Siemens SCL.

What to try

  1. Run the program and turn S1 on: L1 lights after 2 s while OnDelay.ET counts. Turn it off before 2 s: it never lights.
  2. Turn S2 on, then off: L2 stays lit for 3 s after you switch off.
  3. Give PB1 a short press, then a long one: the pulse is 1.5 s both times.
  4. In the ladder watch the timer boxes and the live ET inside them.

Terms in this lesson

People find this lesson by searching

TON TOF TP structured textplc timer on delayoff delay timer plcTON PT ET Qpulse timer plcalarm on delay ISA 18.2structured text timer examplerun on timer motor fan

Course outline

  1. 01What is Structured Text, and when to use it instead of ladder
  2. 02How a PLC runs your code: the scan cycle and the process image
  3. 03Program structure: POUs, PROGRAM, FUNCTION and FUNCTION_BLOCK
  4. 04Your first program: starting a pump with seal-in logic
  5. 05Data types: BOOL, INT, REAL, TIME and the rest
  6. 06Declaring variables: VAR, VAR_INPUT and RETAIN
  7. 07Literals and constants: 16#FF, 2#1010 and T#5s
  8. 08Type conversion and scaling a 4-20 mA signal
  9. 09Assignment and arithmetic in ST: := and operator precedence
  10. 10Boolean logic, comparisons and bit operations
  11. 11Standard functions: ABS, SQRT, MIN, MAX, LIMIT, SEL, MUX
  12. 12IF, ELSIF and ELSE: the rules and when to avoid them
  13. 13The CASE statement and your first state machine
  14. 14The FOR loop and the watchdog
  15. 15WHILE, REPEAT, EXIT, CONTINUE and RETURN
  16. 16Edge detection: R_TRIG, F_TRIG and the "it fired every scan" bug
  17. 17Timers: TON, TOF and TP
  18. 18Counters: CTU, CTD and CTUD
  19. 19SR and RS flip-flops: which one wins
  20. 20Writing your own function
  21. 21Writing a function block
  22. 22Arrays in Structured Text
  23. 23Structs and enumerations
  24. 24References and pointers
  25. 25The state machine pattern: a batch sequence that cannot get stuck
  26. 26Alarm management to ISA-18.2: delay, deadband, latch, acknowledge, first-out
  27. 27Analogue signal processing: counts to engineering units, NE43 and filtering
  28. 28Closed-loop control in ST: hysteresis first, then a practical PID
  29. 29Motors and valves in practice: permissives, feedback and travel time
  30. 30The same ST on every platform: SCL, Studio 5000, CODESYS, TwinCAT
  31. 31Testing and debugging ST: the watch table, forcing and simulation
  32. 32An ST style guide: naming, comments, constants and version control
  33. 33Final project: a complete tank station with a state machine and alarms
  34. 3420 interview questions on ST and PLC programming, with answers