Counters: CTU, CTD, and the reset everyone forgets
Counters look simpler than timers and cause more field problems, almost all of them traceable to the same two mistakes.
Short answer
A count-up instruction increments its accumulator once per false-to-true transition of its rung, not once per scan, and sets its done bit when the accumulator reaches the preset. It keeps counting past the preset and never clears itself. Every counter needs an explicit reset, and forgetting one is the most common counter fault in the field.
A counter increments once per false-to-true transition of its rung and sets a done bit when it reaches a preset. That is the whole instruction, and two details in it cause almost every counter problem in the field.
It counts edges, not scans
Hold the input on for a second at a 10 ms scan and a correctly implemented counter counts one, not a hundred. The instruction remembers the previous state of its own rung and only increments on the transition.
This matters because it is the opposite of how a timer behaves, and because it is easy to build something that looks like a counter and counts scans instead.
It does not stop, and it does not clear
The done bit sets when the accumulator reaches the preset. The accumulator carries on. It will keep going until it overflows or somebody resets it.
If your logic tests for accumulator equals preset rather than for the done bit, it works exactly once and then never again.
The reset is not optional
Every counter needs a reset path, and it needs to be reachable. The usual failures are a reset conditioned on something that never becomes true, and a reset that clears the counter on the same scan it reaches the preset, so the done bit is never seen by anything downstream.
Counting parts on a fast line
If parts pass faster than the scan, ladder cannot count them. The sensor pulse has to be longer than the worst-case scan or the count is wrong in a way that looks like a sensor fault. Use a high-speed counter input.
Common questions
- Why does my counter increment more than once per press?
- It is almost certainly counting scans rather than transitions, which happens when the counting instruction is fed by a level rather than an edge. A correctly implemented count-up counts one per false-to-true transition, so a held button counts once regardless of how many scans it is held for.
- Does a counter stop at its preset?
- No. The done bit sets when the accumulator reaches the preset, but the accumulator keeps incrementing past it until it overflows or is reset. If your logic assumes the count equals the preset, it will be wrong the moment an extra part goes past the sensor.
Keep reading
- Safety
SIL or PL: which one does your machine need?
Two standards, two scales, and one machine. Which one applies, how they map to each other, and why the answer is usually ISO 13849.
- Safety
Categories B, 1, 2, 3 and 4, in plain terms
Five architectures, what a single fault does to each, and the practical wiring that goes with them.
- Safety
Safety relay or safety PLC: how to decide
One is a wiring decision, the other is a programming one. The count of safety functions, not the size of the machine, is what settles it.