Packing 12 bottles per case, changing a cutting blade every 5,000 cycles, counting cars into a car park: these all use counters.
Up counter (CTU)
- Each time the counter’s input changes from 0 to 1, the current value (CV or ACC) goes up by one.
- When the current value reaches the preset (PV or PRE), the done bit turns on.
- The count is kept even if the input stays on, goes off, or the preset is passed. Only a RESET instruction (RES, RST, or the R input of an IEC counter) clears it.
Here a photo eye counts parts into a box. The conveyor runs until five parts have passed; then the “box full” lamp lights and the conveyor stops until RESET is pressed. Press PART EYE five times:
Program listing (IL)
LD X0
OUT C0 K5
LD X1
RST C0
LDI C0
OUT Y0
LD C0
OUT Y1LD X0 ; part sensor
OUT C0 K5 ; count to 5
LD X1 ; RESET (box changed)
RST C0
LDI C0 ; NOT box full
OUT Y0 ; CONVEYOR
LD C0
OUT Y1 ; BOX FULL lamp
Why it counts edges, not “on time”
If a counter added one every scan while its input was on, a single part sitting in front of the sensor for 200 ms would count 40 times on a 5 ms scan. So counters only react to the rising edge: the one scan where the input was 0 last time and is 1 now.
You can use the same idea yourself with a one-shot (rising edge) instruction: PLS in Mitsubishi, ONS or OSR in Allen-Bradley, R_TRIG in IEC languages, or a P contact in ladder. A one-shot bit is true for exactly one scan when its input turns on. It is the right tool whenever something must happen once per press: advancing a step, adding to a total, toggling a mode.
Down counters and up/down counters
- A down counter (CTD) subtracts one on each rising edge, typically from a loaded preset down to zero. Example: “parts remaining in this batch”.
- An up/down counter (CTUD) has both inputs. Example: a car park with an entry sensor counting up, an exit sensor counting down, and a “FULL” sign when the count reaches the number of spaces.
Keeping counts through a power cut
Whether a count survives a power cut depends on the memory area. On Mitsubishi FX, counters C0–C99 are non-retentive and C100–C199 are retentive (latched). Other brands let you mark tags or data blocks as retentive. A shift production total should be retentive; a “parts in this box” count often should not.
High-speed counters
A normal counter can only see pulses that last longer than a scan (lesson 3). Encoders on motors and fast production lines produce thousands of pulses per second. For those, PLCs have dedicated high-speed counter inputs that count in hardware, independent of the scan, often at 10–100 kHz or more. You configure them in the PLC’s hardware settings and read the value in the program.
Check the count, not just the done bit. Showing the current count on an HMI (“7 of 12”) makes a counting machine far easier to set up and troubleshoot.
Frequently asked questions
Does a counter reset by itself when it reaches the preset?
No. The done bit turns on and the count stays (or keeps rising, depending on the PLC) until a reset instruction runs. Many programs use the done bit to trigger the reset on the next cycle.
What is a one-shot?
An instruction that makes a bit true for exactly one scan when its input turns on, such as PLS, ONS, OSR or R_TRIG. Use it so an action happens once per event instead of every scan.
