Skip to content
Tutorials Center
My learning

Topics

Lesson 19 of 37 · Timers, Counters and Sequences

PLC Timers - TON, TOF and TP

Learn how PLC timers work: on-delay (TON), off-delay (TOF), pulse (TP) and retentive timers, with timing diagrams, Structured Text and a runnable C simulation.

Almost every machine needs to wait. A motor must run for ten seconds before a sensor is checked, a pump must stay on for a minute after the level switch opens, a warning horn must sound for exactly two seconds. A PLC has no sleep() call, because the program is executed again and again in a scan cycle and must never block. Instead, it gives you timers: small function blocks that count elapsed time across many scans and raise an output bit when the time is up.

This lesson covers the three standard IEC 61131-3 timers (TON, TOF, TP), the retentive timer, and how to reason about them. A note on what runs here: a real PLC runtime is not available on this site, so the PLC code in the lesson is shown read-only, and the runnable examples are C stand-ins that imitate a timer driven by a simulated scan cycle. The ideas transfer directly.

How a timer works

A timer has an input, a preset time, an output and an elapsed value. The IEC 61131-3 names are:

Pin Name Meaning
IN input Starts or stops the timer
PT preset time How long to time (type TIME, for example T#5s)
Q output The timer's result bit
ET elapsed time How much time has passed

The timer does not measure time by looping. On each scan the runtime adds the time since the last call (or compares a system clock) to ET. That is why a timer must be called every scan, even when its input is false, and why a timer inside a skipped branch behaves strangely.

flowchart LR
    A["IN rises"] --> B["ET counts up<br/>each scan"]
    B --> C{"ET >= PT?"}
    C -- "no" --> B
    C -- "yes" --> D["Q = TRUE"]

A timer is a counter of elapsed time that sets Q when ET reaches PT.

TON: on-delay

TON delays turning something on. When IN becomes true, ET starts counting. When ET reaches PT, Q becomes true. If IN drops before the time is up, ET resets to zero and Q never goes true. When IN drops after Q is true, Q drops immediately.

TEXT
IN  ____/‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾\______
Q   ___________/‾‾‾‾‾‾‾‾\______
         |<-PT->|

In Structured Text (read-only, as it needs a PLC runtime):

TEXT
(* Start the conveyor 3 s after the start button is held *)
startDelay(IN := startButton, PT := T#3s);
conveyorRun := startDelay.Q;

TON is the most used timer. Typical uses: debounce a noisy switch, wait for a pressure to settle, give a motor time to reach speed before checking its feedback.

TOF: off-delay

TOF delays turning something off. Q becomes true the moment IN is true. When IN falls, ET counts, and Q stays true until ET reaches PT. If IN rises again in time, the count restarts.

TEXT
IN  ____/‾‾‾‾‾‾\_______________
Q   ____/‾‾‾‾‾‾‾‾‾‾‾‾‾\________
                 |<-PT->|

Use it for a cooling fan that keeps running after a machine stops, or for a stairwell light that stays on for 30 seconds after the last motion.

TP: pulse

TP produces a pulse of a fixed length. A rising edge on IN sets Q true for exactly PT, no matter what IN does during the pulse (a re-trigger is ignored until the pulse ends).

TEXT
IN  ___/‾\__/‾‾‾‾‾‾‾\__________
Q   ___/‾‾‾‾‾\______________
        |<-PT->|

A pulse is perfect for "sound the horn for two seconds", for a one-time valve kick, or to turn a long button press into a fixed-length command.

Retentive timers

A retentive on-delay timer (RTO in Allen-Bradley, TONR in Siemens) keeps its ET when IN goes false and only resets with an explicit reset input. It accumulates running time, so it is the tool for "run-hours" counting or maintenance intervals ("grease the bearing every 500 hours of operation"). In the IEC standard only TON, TOF and TP are defined, so retentive timers are vendor extensions.

Simulating a TON in C

Here is a tiny stand-in. The simulated scan time is 100 ms, and we feed a scripted input. This is not a PLC program: it shows what the function block does internally.

C C stand-in: a TON timer driven by scans

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

Notice that the first run reaches Q = 1 after five scans (500 ms), and that the input dropping at scan 10 clears everything. The second run starts counting from zero.

Simulating TOF and TP

Now the other two. Each keeps a little state, and each is a few lines.

C C stand-in: TOF and TP side by side

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

Compare the columns: TOF keeps Q on for 300 ms after the input falls (it drops on the third counted scan), while TP produces a 300 ms pulse for each rising edge, even if the input was only briefly true.

Common mistakes

  • Calling a timer conditionally. If you call the block only when some condition is true, ET is not updated on the other scans. Call timers unconditionally and drive IN with the condition.
  • Sharing one timer instance. Every timer needs its own instance (its own memory). Reusing one for two jobs produces odd timing.
  • Using timers for precision. A timer's resolution is the scan time. Under a 20 ms scan, a 5 ms preset is meaningless. Use a hardware timer or a high-speed module when you need microsecond accuracy.
  • Forgetting restart behaviour. Know whether your timer resets when IN drops, and design with that in mind.

For counting events instead of time, continue with PLC counters.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. A TON has PT = T#5s. IN is true for 3 seconds and then false. What does Q do?

    TON only sets Q after IN has stayed true for the whole preset time. Dropping IN early resets ET and Q never goes true.
  2. 2. Which timer keeps its output on for a while AFTER the input turns off?

    TOF is the off-delay timer: Q follows IN going true immediately, and stays true for PT after IN falls.
  3. 3. Why must a timer block be called on every scan?

    The block adds the time since the last call to ET. If it is skipped, ET stops advancing and the timing is wrong.
  4. 4. You want a horn that sounds for exactly 2 seconds each time a button is pressed, even if the button is released early. Which timer fits best?

    TP creates a fixed-length pulse from a rising edge, regardless of how long IN stays true.

Summary

  • A PLC timer counts elapsed time across scans and sets Q when the rule for its type is met.
  • TON delays switching on, TOF delays switching off, TP produces a fixed-length pulse.
  • Retentive timers keep ET between activations and are reset explicitly.
  • Call timers every scan, give each its own instance, and remember the resolution equals the scan time.
  • The C programs here are stand-ins that model the logic; real timers live in the PLC runtime.

Next: PLC Counters