PLC timer and counter simulator
Timers and counters are in almost every PLC program, and they are where beginners go wrong most often: a TON that never turns on, a TOF mixed up with a TP, a counter that does not count because its input never makes an edge. Here you can operate each block with buttons and watch, at the same time, the block as it appears in the PLC editor and its timing diagram for the last 20 seconds. The blocks follow the IEC 61131-3 standard, the same one used by TIA Portal, Codesys and most manufacturers.
Try this
How to use it
- Block: choose the timer or counter you want to try.
- IN, CU or CD: a push button; the input is 1 while you hold it down. With Switch ticked, each click latches it to 1 or 0.
- R or LD: reset (R) or load the PV value (LD), on the blocks that have it.
- PT or PV: the block's preset time or value. You can change it while it runs.
- Timing diagram: single-bit signals at the top; ET or CV at the bottom, with the preset as a dashed line.
A timer's inputs and outputs
All IEC timers have the same pins: an input IN that starts it, a preset time PT, a single-bit output
Q and the elapsed time ET. PT and ET are of type TIME and are written as T#5S or
T#1S500MS. What changes from one timer to another is when Q turns on and when ET goes back to zero.
TON: on-delay
The most used of all. When IN goes to 1, ET starts counting; when it reaches PT, Q goes to 1 and stays there as long as IN stays at 1. As soon as IN goes back to 0, Q and ET return to zero at once. If IN lasts less than PT, Q never turns on.
That is why a TON does two jobs: waiting (starting a conveyor 3 seconds after the horn sounds) and filtering (only accepting a sensor signal if it has been on for at least half a second, so that bounce or a flicker does not trigger it). It is also used for monitoring: if a valve is told to open and its limit switch does not arrive within 5 seconds, the TON raises an alarm.
TOF: off-delay
The opposite. When IN goes to 1, Q goes to 1 at once. When IN returns to 0, Q stays at 1 for the time PT and then drops. If IN goes back to 1 before PT runs out, ET returns to zero and Q stays at 1: the time only counts from the last time IN went to 0.
Typical examples: a fan that keeps cooling a motor or a drive for a while after it stops, an area light that stays on for some time after the presence sensor stops detecting, or a conveyor that keeps running for a few seconds to empty itself after product stops arriving.
TP: pulse
On a rising edge of IN, Q gives a pulse lasting exactly PT, whatever IN does afterwards: if it is released early, the pulse carries on; if it is held, the pulse ends anyway. During the pulse it cannot be retriggered or extended. When it ends, ET stays at PT while IN is still 1 and returns to zero when IN goes to 0.
It is used when a signal of fixed length is needed from any command: a 200 ms air blast to eject a part, a lubrication pulse, a handshake signal another machine expects, or turning a held push button into a single short command.
TONR: the timer that accumulates
The TONR (Siemens' name; other brands call it RTO or retentive timer) works like a TON, but when IN goes back to 0 it does not reset ET: it keeps it and, the next time IN goes to 1, it carries on adding. Q turns on when the total reaches PT. Only the R input sets it back to zero. It is used to count running hours, for example to flag that a pump is due for maintenance every 500 hours of running, even if it has started and stopped a thousand times.
CTU and CTD: the counters
A counter does not count how long the signal lasts, but its rising edges: each time the input goes from 0 to 1. The CTU adds 1 to CV (current value) on every edge of CU, and its output Q goes to 1 when CV is equal to or greater than PV (preset value). CV does not stop at PV: it keeps going up. The R input sets CV to zero.
The CTD counts down: the LD input loads PV into CV, each edge of CD subtracts 1, and Q goes to 1 when CV reaches 0 or less. A detail that catches people out: when the PLC starts, CV is 0, so Q is already 1 until PV is loaded. Examples: a CTU counts parts until a batch of 12 is complete; a CTD keeps track of how many parts are still needed to fill a box of 6.
There is also the CTUD, which combines both: it counts up with CU and down with CD, for example to know how many parts are in a buffer between two sensors.
Common mistakes
- Using a TON where a TOF is needed, or the other way round: draw the timing diagram of what you want first.
- Expecting a TON to stay on when IN is removed: Q drops at once. If it has to stay on, you need a seal-in or a TOF.
- Feeding IN with a signal that only lasts one scan, such as an edge: a TON never gets to count.
- Calling the same timer in two places in the program: each call restarts or runs it, and the result depends on the order.
- Counting with an input that never makes an edge because it stays at 1: the counter only adds once.
- Not resetting the counter at the start of the next batch, or resetting it in the same scan as the count.
Teaching a class? There is a printable worksheet for this simulator, with exercises and answers. More material on the teachers page.
Found it useful? Share it with your class or your team: WhatsApp · Telegram · LinkedIn · Email