ExamRobotic

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.

The block in the PLC
Timing diagram

Try this

    How to use it

    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

    Every brand has its quirksThe simulator's blocks follow IEC 61131-3. In TIA Portal they are the same, but each timer needs its own instance data block, and the older S7-300/400 also had the S5 timers (S_ODT, S_OFFDT…), which work differently. To see these blocks inside a program with more contacts and coils, try the ladder logic simulator.

    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