Loading local progress…
PLC Gym
PLC Gym homeLevel 1, 0 XP · your progress
All guides

PLC timers and counters: how they work and when to use them

PLC timer and counter basics explained with examples: on delay, off delay, retentive timers, counting bottles and common faults.

An illustration of a sensor beside metal parts on a conveyor, with a control cabinet behind it.
A sensor can tell the PLC when a part has passed
In this guide
  1. First, how does a PLC keep track?
  2. What is a PLC timer?
  3. An on delay timer, worked through
  4. What about an off delay or a retentive timer?
  5. What is a PLC counter?
  6. Counting six bottles
  7. Using a timer and a counter together
  8. Why might a timer or counter not work?
  9. Where to practise next
  10. Sources

A PLC timer answers a question like “has this been on for five seconds?” A counter answers “how many times has this happened?” They sound simple, but getting the difference right matters when a pump needs to wait before starting or a conveyor has to stop after six bottles.

This guide takes both from the beginning. It looks at what the PLC remembers, the common instructions you'll meet, and a small example of each. You don't need a PLC on your desk to follow it.

First, how does a PLC keep track?

A PLC reads inputs, runs its program and updates outputs repeatedly. Each trip through the program is called a scan. A sensor might stay on for hundreds of scans while a bottle sits in front of it.

A timer needs somewhere to keep its elapsed time between scans. A counter needs somewhere to keep its current count and remember the previous state of its input. Each timer or counter needs its own memory, usually called an instance or a tag, depending on the controller.

The preset is the target you give it. For a timer that might be five seconds. For a counter it might be six bottles. The current value is what it has reached so far. An output or status bit tells your program when the target has been reached.

You don't normally make the whole program sit and wait. The PLC keeps scanning and checks the timer or counter as it runs. Other parts of the machine can carry on working.

What is a PLC timer?

A timer measures time for a condition in your program. Exactly what happens when that condition turns on or off depends on the type of timer you choose.

TimerWhat it doesExample
On delayWaits before turning its output onStart a pump after a start request stays on for five seconds
Off delayWaits before turning its output offKeep a fan running briefly after a machine stops
Retentive timerHolds elapsed time when timing stops, until resetAdd up machine running time towards a service reminder
Pulse timerProduces an output pulse for a set timeGive a device a timed signal

Those are the ideas. Instructions and their behaviour vary between controllers, so check the manual for the equipment you're using. A PLC timer isn't a substitute for a properly designed safety system.

An on delay timer, worked through

Imagine a tank pump. You want the start request to stay on for five seconds before the pump starts. A quick flicker should not start it.

An illustrative image of a pump connected to a water tank beside a control cabinet.
A pump is one place you might use a timer

An on delay timer, often called TON, is the usual starting point. Set its preset to five seconds and give it the start request as its input.

What happensElapsed timeTimer output
Start request is off0 secondsOff
Request comes on and stays onRising towards 5 secondsOff
Request stays on for 5 seconds5 secondsOn
Request goes offResets to 0Off

If the request drops after three seconds, a normal on delay resets. When it comes back, the five seconds starts again. If it stays on past five seconds, the timer output stays on until the input drops. Your pump logic can use that output as one condition for running.

On a Siemens S7 PLC, the timer instance has inputs named IN and PT, and outputs named Q and ET. IN is the condition, PT is the preset, Q tells you the time has been reached, and ET is the elapsed time. A preset of T#5s means five seconds.

This is what the timer call can look like in Siemens SCL, with a separate timer instance called StartDelay:

#StartDelay(IN := #StartRequest, PT := T#5s);
#DelayDone := #StartDelay.Q;

The timer instance must be declared in the block. This example shows the delay only: a real pump also needs the right interlocks, fault handling and a properly designed stop.

Rockwell has its own instructions and timer tags. In Logix ladder, TON uses a timer's preset and accumulated values, commonly written as PRE and ACC, and its done bit is DN. Preset values for the standard Logix timer are in milliseconds, so five seconds is 5,000. Don't assume the same names or syntax work on every controller or in every language.

You can try the idea in the on delay mission, then change the time and watch what happens when the input goes off early.

What about an off delay or a retentive timer?

An off delay, often TOF, works at the other end. The output comes on when its input comes on. When the input goes off, the output stays on for the preset time before switching off.

Think of a fan that keeps running for a short time after a machine stops. It can be useful for clearing heat or fumes, provided the actual process and its safety requirements have been properly assessed. If the input comes back on during the delay, check the controller's instruction behaviour rather than guessing how it restarts.

A retentive timer keeps the elapsed time when timing pauses. If a machine runs for two hours, stops, and then runs for another hour, the timer can accumulate three hours towards a service reminder. It needs a deliberate reset when you want to clear that total.

Be careful with names. Siemens S7 uses TONR for a time accumulator. Rockwell Logix ladder has an RTO instruction for retentive timing, while its TONR name is also used for a different timer instruction in other Logix languages. Look up the exact instruction and language before copying an example. Retaining a value while a timer pauses is also different from guaranteeing it survives a power loss: that depends on the controller and its configuration.

What is a PLC counter?

A counter keeps track of events. A common count up, or CTU, increases its current value as events arrive. Once the value reaches the preset, its output or done bit tells the program the target has been met.

The important word is events. If a sensor stays on while a bottle passes, a normal count up instruction looks for the input changing from off to on. That change is a rising edge. It doesn't add another bottle every time the PLC scans while the sensor is still on.

The input needs to go off and then on again for another rising edge. If two bottles pass without a gap the sensor can see, you may get one count instead of two. Sensor position and the physical gap matter just as much as the program.

Counting six bottles

Imagine a sensor looking across a conveyor. Each bottle breaks the beam, then clears it before the next one arrives. You want to count six bottles and tell the rest of the program when the pack is full.

EventCurrent countPack full?
Counter reset0No
First bottle arrives1No
Fifth bottle arrives5No
Sixth bottle arrives6Yes
Counter reset for the next pack0No

On Siemens, a CTU instruction has a count input called CU, a reset input R, a preset PV, a current value CV and an output Q. On Rockwell Logix ladder, CTU uses a counter tag with PRE, ACC and DN members, and a separate RES instruction can reset the counter.

Those names give you somewhere to start when reading a program. They aren't interchangeable instructions: declare and call the correct counter for the controller and language you're using. Also decide when to reset. Resetting as soon as the sixth bottle arrives could clear the done indication before the rest of the sequence has used it.

Try counting bottles in PLC Gym. Then look at the counter glossary if you want a quick reminder of the terms.

Using a timer and a counter together

Now put the two ideas together. A conveyor counts six bottles, stops for two seconds while a pack is handled, then starts a new count.

  1. Each bottle arriving at the sensor gives the counter an event.
  2. At six, the counter tells the sequence that the pack is full.
  3. The sequence stops the conveyor and starts a two second timer.
  4. When the timer finishes and the other required conditions are satisfied, the sequence resets the counter and moves on.

The timer measures the pause. The counter counts the bottles. The sequence decides when each one should run and reset. That distinction makes a fault much easier to find than trying to make a single timer do everything.

This is a teaching example, not a complete machine program. On a real line you would also need to think about safe stopping, a blocked sensor, an interrupted cycle and what should happen after a restart.

Why might a timer or counter not work?

Start with what the PLC can actually see, then work through the instruction.

  • The timer never finishes. Is the input staying on for the whole delay? If it drops, a normal on delay starts from zero again.
  • The time is wrong. Check the preset and its units. Five milliseconds and five seconds are very different.
  • The count doesn't move. Watch the sensor input. It needs to change state for a new rising edge, and the instruction needs to be executed as intended.
  • The count is too high or too low. Check for a noisy signal, the sensor seeing more than one part, or parts passing without a clear gap.
  • The counter keeps going back to zero. Check what is driving reset and when that part of the program runs.
  • The PLC misses fast pulses. A normal program can only count changes it sees. For short or fast pulses, check the controller's input and high speed counter capabilities.

For either instruction, watch the current value and the done output while the machine runs. Don't just look at the final output and guess where the problem started.

Where to practise next

If you're new to all of this, start with the PLC programming course, then try the timer and bottle missions above. The exercises run in a browser, so you can see the result and try again without wiring a real machine.

PLC Gym is a learning simulator, not a real controller or a substitute for testing in the manufacturer's software. When you move to real equipment, use the manual for your exact controller and have the application checked by a competent controls engineer.

Sources

Questions about this?Ask in the Locker Room

Try it on a machine

Free · Runs in your browser

Try it on a working machine

Write real Siemens or Rockwell code in the free online PLC simulator and watch a 3D pump, tank or filling line do exactly what you told it. Nothing to install.