PLC Counter Instruction: CTU, CTD, and CTUD with Real Examples
A PLC counter instruction counts events. A sensor detects a part on a conveyor, the counter adds one. When the count matches your target number, the counter triggers an output bit.
Common PLC counter types include CTU, CTD and CTUD. CTU counts up from zero, CTD counts down from a preset, and CTUD counts both directions using one memory location.
What Is a PLC Counter?
A counter instruction sits inside your ladder program. When the input sees a rising edge (the moment it goes from off to on), the counter changes by one.
The preset value is your target. The accumulated value is the current count. The done bit turns on when the count reaches the preset.
Rising edge behavior: If a sensor stays on for ten scan cycles, the counter only moves once. The count happens at the exact moment the input changes from off to on. Holding the input on does not keep counting.
Retention behavior: Whether the counter keeps its value after power loss depends on your PLC brand and how you configure the instruction. Many Allen-Bradley counters keep their count. Some Siemens counters reset unless you set them to retentive. Check your platform manual.
CTU: Count Up Counter
CTU adds one to the accumulator every time the input turns on. When the accumulator equals or passes the preset, the done bit (DN or Q) turns on.
The done bit stays on even if more pulses arrive. The accumulator keeps climbing past the preset unless you gate the input or reset the counter.
CTU Parameters
Preset (PRE or PV) – Your target count. Set this to batch size or total parts needed.
Accumulator (ACC or CV) – The current count. Starts at zero. Increases by one each rising edge.
Done Bit (DN or Q) – Turns on when ACC reaches or passes PRE.
Real CTU Applications
Conveyor part counting: A sensor pulses once per bottle. CTU counts to 24. When the done bit fires, a gate opens and pushes the full case off the line. A reset clears the counter for the next case.
Press cycle tracking: A sensor detects the ram at bottom position. CTU counts strokes. At 50,000 strokes, the done bit triggers a maintenance reminder. The technician resets the counter after service.
Shift production totals: CTU adds every part made during an 8-hour shift. The HMI shows ACC in real time. Supervisor resets counters at shift start.
CTU Ladder Example (Allen-Bradley)
A sensor at I:0/0 counts parts on a conveyor. After 100 parts, output O:0/1 turns on to signal a full pallet. Button I:0/2 resets the counter.
Each rising edge at I:0/0 adds one to C5:0.ACC. At 100 parts, C5:0/DN energizes O:0/1. Pressing I:0/2 fires RES, clearing ACC to zero and turning off DN.
CTU Function Block (IEC 61131-3)
Siemens and CODESYS use the CTU function block.
The R input resets the accumulator when resetButton goes true. Q output is the done bit. CV holds the current count.
CTD: Count Down Counter
CTD subtracts one from the accumulator every rising edge at the CD input. The done bit (DN or QD) turns on when the accumulator reaches zero.
Before CTD can count, you load the preset into the accumulator. The LD input sets ACC equal to PRE. After loading, each pulse decrements ACC by one.
CTD Parameters
Preset (PRE or PV): Starting count. Load this into the accumulator before counting begins.
Accumulator (ACC or CV): Starts at PRE after a load pulse. Decreases by one per pulse.
Done Bit (DN or QD): Turns on when ACC reaches zero.
Load Input (LD): Copies PRE into ACC.
Real CTD Applications
Batch dispensing: A hopper dispenses 50 tablets into a bottle. Load 50 into CTD when the bottle arrives. Each dispense pulse decrements ACC. Done bit at zero closes the valve and moves to the next bottle.
Inventory tracking: Bin holds 500 parts. Load 500 into CTD. Each time a robot picks one part, CD pulses. When ACC drops to a minimum level, system sends reorder alert.
Pallet depletion: Dispenser holds 30 empty pallets. Load 30 into CTD. Each pallet dispensed decrements ACC. Done bit at zero alerts operator to reload.
CTD Ladder Example
A bottle arrives at sensor I:1/0. Load 20 into counter C5:1. Dispense solenoid pulses at I:1/1 once per tablet. After 20 tablets, done bit closes the solenoid.
I:1/0 rising edge loads PRE into ACC. I:1/1 pulses decrement ACC. When ACC hits zero, DN turns on. The normally-closed DN contact on Rung 2 opens and de-energizes the solenoid.
CTUD: Up/Down Counter
CTUD combines CTU and CTD in one instruction. Separate CU and CD inputs control the same accumulator. Two done bits: QU fires when ACC reaches or exceeds PV, QD fires when ACC reaches zero or below.
CTUD Parameters
Preset (PV) – Upper target count.
Accumulator (CV) – Increments on CU rising edge, decrements on CD rising edge.
QU Done Bit – Turns on when CV equals or exceeds PV.
QD Done Bit – Turns on when CV equals or drops below zero.
Reset ® – Clears CV to zero and turns off both done bits.
Load (LD) – Sets CV equal to PV.
Real CTUD Applications
Buffer zone tracking: Parts enter through one sensor (CU input), exit through another (CD input). CTUD CV tracks the exact part count inside the buffer. QU at PV=50 signals buffer full and stops the upstream conveyor. QD at zero signals buffer empty.
Parking lot occupancy: Entry gate pulses CU, exit gate pulses CD. PV set to total spaces (200). QU fires when lot fills, entrance sign changes to FULL.
Warehouse bay tracking: Forklift loads pulse CU, unloads pulse CD. CV shows current pallet count. QU signals bay at capacity. QD signals bay empty.

CTUD Function Block Example
IEC function block for a buffer zone.
Entry sensor increments CV, exit sensor decrements CV. QU stops upstream when buffer reaches 50 parts. QD stops downstream when buffer empties.
Reset Logic
Every counter needs a reset method. Without reset, the counter reaches preset and stays latched until you manually clear it.
Three Reset Methods
Manual operator reset: A pushbutton fires the RES instruction. Best for batch operations where someone confirms batch complete before restarting.
Automatic reset on done bit: Use DN bit with one-shot to reset counter immediately. Creates a self-repeating counter.
One-shot prevents RES from firing every scan while DN stays true. Reset executes for one scan when DN turns on.
Reset at program start: Use first scan bit to clear all counters at PLC startup. Guarantees counters start at zero.
Overflow and Underflow
Counters use 16-bit or 32-bit integers. The maximum value depends on your PLC platform and instruction data type.
CTU overflow: If ACC keeps climbing past PRE without reset, it eventually exceeds the integer limit. On some 16-bit platforms, maximum is 32,767. Overflow wraps to -32,768. On 32-bit platforms, maximum is 2,147,483,647.
Gate the count input using the done bit to prevent overflow:
Normally-closed DN contact blocks further count pulses once preset is reached.
CTD underflow: CTD with ACC at zero continues decrementing into negative values if pulses keep arriving. QD stays on as long as ACC is at or below zero.
Gate CD input with QD bit to stop counting below zero.
High-Speed Counters
Standard counters evaluate during the normal scan cycle. If your signal pulses faster than the scan can detect, the PLC misses transitions and under-counts.
PLC scan cycles typically run 5 to 20 milliseconds. Whether a standard counter can catch a signal depends on pulse width and scan time.
High-speed counters (HSC) run on dedicated hardware or specialty modules. The HSC accumulates counts between scans using interrupt logic. HSC can count at rates from 10 kHz to several hundred kHz or higher depending on hardware.
When HSC is required:
Rotary encoder feedback (thousands of pulses per second at high RPM)
Turbine flow meter at high flow rates
Quadrature encoder input for position tracking
Platform-specific HSC:
Allen-Bradley ControlLogix uses 1756-HSC module. MicroLogix 1100 has built-in HSC inputs.
Siemens S7-1200 and S7-1500 have built-in HSC function blocks (CTRL_HSC) configurable on dedicated high-speed input terminals.
For standard production lines counting parts per minute, software counters work fine. Reserve HSC for encoder positioning and high-speed flow measurement.
Counter and Timer Combined Example
A common pattern pairs CTU with TON timer. Counter defines quantity, timer defines dwell time after quantity is reached.
Application: Conveyor deposits parts into a box. After 10 parts, conveyor stops for 5 seconds to allow box removal. Conveyor restarts automatically for next batch.
Sensor increments C5:0.ACC. At 10 parts, C5:0/DN turns on. Rung 2 stops conveyor. Rung 1 enables timer. Timer counts to 5 seconds. T4:0/DN fires. Rung 3 and 4 reset both counter and timer. C5:0/DN drops, Rung 2 restarts conveyor. Cycle repeats.
Counters vs Timers
| Counter | Timer |
|---|---|
| Counts discrete events | Measures elapsed time |
| Accumulates rising edges | Accumulates milliseconds or seconds |
| Done when ACC equals preset count | Done when ACC equals preset time |
| Use for parts counted, cycles completed | Use for delays, timed outputs |
If the question is “how many times did this happen,” use a counter. If the question is “how long has this been true,” use a timer.
Platform Naming Reference
Allen-Bradley RSLogix 500 / SLC-500
- Counter types: CTU, CTD
- Preset: PRE
- Accumulator: ACC
- Done bit: DN (address C5:x/DN)
- Reset: RES instruction on separate rung
- File addressing: C5:0.ACC, C5:0.PRE, C5:0/DN
Allen-Bradley Studio 5000 / ControlLogix
- Counter types: CTU, CTD, CTUD
- Tag addressing: MyCounter.PRE, MyCounter.ACC, MyCounter.DN
- Done bits on CTUD: QU (count up done), QD (count down done)
- Reset: Write 0 to ACC or use RES input
IEC 61131-3 / Siemens TIA Portal / CODESYS
- Function blocks: CTU, CTD, CTUD
- Preset: PV
- Accumulator: CV
- Done bits: Q (CTU), QD (CTD), QU and QD (CTUD)
- Reset: R input
- Load: LD input
Real Production Examples
Bottle Packaging Line
24 bottles per case. Sensor at I:1/3 pulses once per bottle. At 24 bottles, diverter gate O:1/4 pushes full case onto exit conveyor. Empty case sensor I:1/5 resets counter.
Diverter stays on as long as DN is set.
Press Maintenance Alert
Sensor detects press ram at bottom position. CTU counts strokes. At 50,000 strokes, done bit triggers maintenance message.
Technician presses reset after servicing. Counter restarts from zero for next 50,000 cycles.
Common Questions
What is a PLC counter?
A counter tracks discrete events. Each time the count input sees a rising edge, the counter increments or decrements an integer accumulator. When the accumulator reaches a preset value, a done bit energizes.
What is the difference between CTU and CTD?
CTU starts at zero and increments toward preset. CTD starts at preset and decrements toward zero.
How do you reset a PLC counter?
Allen-Bradley uses RES instruction on separate rung. IEC platforms use R input on function block. Some PLCs allow direct write to ACC.
Can you count above the preset value?
Yes, unless you gate the count input. CTU continues incrementing past preset. Done bit stays on as long as accumulator is at or above preset.
What happens if CTD counts below zero?
Accumulator goes negative. Done bit stays on as long as accumulator is at or below zero. Gate count-down input to prevent this.
Counters appear in food packaging, automotive assembly, water treatment, pharmaceutical production, and mining operations. Set the preset to match your batch size, wire the count input to your sensor, add a reset rung, and test one pulse at a time.
Learn the fundamentals of ladder logic in our complete guide: Ladder Logic Programming – Contacts, Coils, Timers & Counters.
Before working with counters, understand how timers work: PLC Timer Instructions (TON, TOF, RTO).
Start building your project correctly with this step-by-step tutorial: Create Project in RSLogix 5000.
Troubleshoot common issues that can affect counters and communication: PLC Communication Errors – Causes & Fixes.
Explore the different Allen-Bradley controllers that use these counter instructions: Allen-Bradley PLC Controllers Guide.
For official reference on counter instructions, see the Rockwell Automation Literature Library.





