16. PLC Counters: CTU, CTD, and One-Shots


0
Categories : PLC Foundations

In industrial automation, PLC counters are used when a machine needs to count events.

A counter can count:

Parts
Boxes
Bottles
Cycles
Machine strokes
Rejects
Pallets
Sensor pulses
Production totals

A counter does not count time.
A counter counts how many times an event happens.

According to Programmable Logic Controllers, 6th Edition, PLC counter instructions include Count Up (CTU), Count Down (CTD), cascading counters, encoder/counter applications, high-speed counters, and applications that combine counters and timers. The book also connects the use of counters with one-shot logic, which is important because a PLC scan can count the same signal multiple times if the signal stays ON.


What Is a PLC Counter?

A PLC counter is an instruction used to count transitions of a signal.

In simple terms:

Each valid pulse = counter increases or decreases

For example:

A photoeye detects one box
        ↓
PLC counter counts 1

If 10 boxes pass the sensor:

Counter accumulated value = 10

Counters are very common in packaging lines, conveyors, filling systems, palletizers, indexing machines, and reject systems.


Basic Counter Terms

Most PLC counter instructions have important values and status bits.

PRE — Preset Value

The PRE is the target value.

Example:

Counter preset = 12

This means the counter is waiting until it counts 12 events.


ACC — Accumulated Value

The ACC is the current count.

Example:

Counter ACC = 7

This means the counter has counted 7 events so far.


DN — Done Bit

The DN bit turns ON when the accumulated value reaches the preset value.

Example:

PRE = 12
ACC = 12
DN = ON

The done bit is commonly used to trigger the next action in the machine.

Example:

If Box_Counter.DN = ON
Then stop conveyor or index pallet

CTU — Count Up Counter

A CTU counter counts upward.

Each time the counter input changes from false to true, the counter increments by 1.

0 → 1 → 2 → 3 → 4 → 5

Common uses:

Count bottles entering a conveyor
Count boxes going into a case
Count machine cycles
Count rejected parts
Count pallets completed

CTU Example: Counting Boxes

Imagine a conveyor with a photoeye.

Every time a box passes the photoeye, the PLC should count one box.

Box photoeye detects box
        ↓
Counter increments by 1

Example:

Counter PRE = 10
Counter ACC = 0

After one box:

ACC = 1

After ten boxes:

ACC = 10
DN = ON

Then the PLC may stop the conveyor, start a pusher, close a gate, or signal that the case is full.


CTU Logic Concept

Box_Detected_OneShot        Box_Counter CTU
--------] [----------------------[ CTU ]----
                              PRE = 10
                              ACC = Current Count

Plain English:

Each time a box is detected one time,
increase the box counter by 1.

CTD — Count Down Counter

A CTD counter counts downward.

10 → 9 → 8 → 7 → 6 → 5

A CTD is useful when you want to count remaining items.

Common uses:

Count remaining boxes in a batch
Count down parts left to process
Track items leaving a buffer
Subtract parts as they exit

CTD Example: Buffer Zone

Imagine a buffer conveyor.

One photoeye counts boxes entering.
Another photoeye counts boxes leaving.

Box enters buffer → Count Up
Box exits buffer  → Count Down

This allows the PLC to estimate how many boxes are inside the buffer.

Example:

Boxes entered = 15
Boxes exited = 6
Boxes inside buffer = 9

This type of logic is useful in conveyor systems, accumulation tables, and packaging lines.


CTU and CTD Together

CTU and CTD can work together to track quantity.

Example:

Entry_Photoeye → CTU
Exit_Photoeye  → CTD

The counter value can represent the number of products inside a machine zone.

ACC = current number of boxes in zone

This is useful for:

Buffer control
Jam detection
Zone occupancy
Reject tracking
Product tracking

Resetting a Counter

Counters usually need a reset instruction.

The reset clears the accumulated value back to zero.

Example:

Counter ACC = 10
Reset = ON
Counter ACC = 0
Counter DN = OFF

Common reset conditions:

Operator presses Reset
Batch complete
Machine changes mode
New product run starts
Fault reset
End of cycle

Reset Logic Example
Reset_Button        RES Box_Counter
----] [-----------------[ RES ]----

Plain English:

When Reset_Button is pressed,
clear the counter accumulated value.

Why One-Shots Are Important

This is one of the most important counter concepts.

A PLC scan runs very fast. If a sensor stays ON for several scans, the counter may count more than once unless the counter instruction or logic handles transitions correctly.

Example problem:

A box blocks the photoeye for 300 ms.
PLC scan time = 10 ms.
The photoeye stays ON for about 30 scans.

Without proper one-shot logic, the PLC may count the same box multiple times.

That is why we use a one-shot.


What Is a One-Shot?

A one-shot turns ON for only one PLC scan when a signal changes state.

In simple terms:

Input turns ON
        ↓
One-shot turns ON for one scan only
        ↓
Counter counts one time

Even if the sensor stays ON, the one-shot only gives the counter one pulse.


Without One-Shot
Photoeye ON for 20 scans
Counter may count too many times

Problem:

One box = many counts

With One-Shot
Photoeye turns ON
One-shot pulse occurs once
Counter counts one time

Correct result:

One box = one count

One-Shot Example

Raw Sensor
DI_Box_Photoeye
One-Shot Bit
OSR_Box_Photoeye
Counter
Box_Counter

Logic concept:

DI_Box_Photoeye → One-Shot → CTU Box_Counter

Plain English:

When the photoeye changes from OFF to ON,
generate one pulse,
then count one box.

Rising Edge vs Falling Edge

One-shots can be based on different transitions.

Rising Edge

A rising edge happens when a signal changes:

OFF → ON

This is commonly used to count when a sensor first detects a product.

Example:

Photoeye changes OFF to ON
Count one box

Falling Edge

A falling edge happens when a signal changes:

ON → OFF

This may be used when you want to count when the product leaves the sensor.

Example:

Photoeye changes ON to OFF
Count one box after it clears the sensor

Both methods can work. The best one depends on the machine behavior.


Practical Example: Counting Bottles

Machine Requirement

A conveyor moves bottles past a photoeye.

The PLC must count 24 bottles, then stop the conveyor.

Inputs
DI_Start_PB
DI_Stop_PB_OK
DI_Bottle_Photoeye
DI_Reset_PB
Outputs
DO_Conveyor_Run
DO_Batch_Complete_Light
Internal Tags
Bottle_Count_OS
Bottle_Counter
Batch_Complete
Logic Concept
1. Start conveyor.
2. Each bottle creates one photoeye pulse.
3. One-shot prevents multiple counts.
4. CTU counts bottles.
5. When ACC reaches 24, DN turns ON.
6. Conveyor stops.
7. Batch complete light turns ON.
8. Reset clears counter.

Example Sequence

Bottle 1 passes photoeye  → ACC = 1
Bottle 2 passes photoeye  → ACC = 2
Bottle 3 passes photoeye  → ACC = 3
...
Bottle 24 passes photoeye → ACC = 24
Counter.DN = ON
Conveyor stops
Batch complete light turns ON

Counter Done Bit in Machine Logic

The counter done bit can be used as a machine condition.

Example:

If Bottle_Counter.DN = ON
Then Batch_Complete = ON

Or:

If Bottle_Counter.DN = ON
Then Stop Conveyor

But a good program usually separates:

Counter done status
Machine command logic
Physical output mapping

Better structure:

Bottle_Counter.DN → Batch_Complete
Batch_Complete → Conveyor_Run_Command OFF
Conveyor_Run_Command → DO_Conveyor_Run

This makes troubleshooting cleaner.


Counters and Fault Logic

Counters can also help detect faults.

Example:

If conveyor is running
AND no boxes are counted for 30 seconds
THEN generate No Product Detected fault

Or:

If too many boxes are counted too quickly
THEN possible sensor bounce or double-feed fault

Counters are not only for production totals. They can also support diagnostics.


Common Counter Problems

1. Counter Counts Too Many

Possible causes:

No one-shot
Sensor bouncing
Photoeye chattering
Product vibration
Signal noise
Input not debounced
Sensor sees the same product multiple times
Logic scanned in wrong place

2. Counter Does Not Count

Possible causes:

Sensor not detecting
Input LED not turning ON
Wrong input tag
One-shot logic incorrect
Counter rung not being scanned
Counter already done and logic blocked
Reset active
PLC in wrong mode

3. Counter Resets Unexpectedly

Possible causes:

Reset button stuck
HMI reset tag active
Fault reset clearing counter
Auto reset logic active
Batch complete logic resetting too soon
Duplicate reset instruction

4. Counter Done Bit Never Turns ON

Possible causes:

Preset too high
Counter not incrementing
Counter reset before reaching preset
Wrong counter tag used
Wrong comparison logic
ACC value not retained

Counter Troubleshooting Path

When a counter is not working correctly, check the complete signal path.

Field sensor
        ↓
Input module LED
        ↓
PLC input tag
        ↓
Debounce logic
        ↓
One-shot logic
        ↓
Counter instruction
        ↓
ACC value
        ↓
DN bit
        ↓
Machine action

This is the best way to avoid guessing.


Automation Technician Notes

When troubleshooting counter logic, always ask:

Is the field sensor detecting correctly?
Is the PLC input changing state?
Is the signal stable or bouncing?
Is a one-shot needed?
Is the one-shot triggering?
Is the counter ACC changing?
Is the counter being reset?
Is the preset correct?
Is the done bit being used correctly?
Is the physical output controlled by the counter logic?

The key idea:

A counter is only as reliable as the signal being counted.

A bad sensor signal will create bad counter results.


Best Practices for PLC Counters

1. Use One-Shots for Product Counting

Do not allow one product to create multiple counts.

Photoeye → One-shot → Counter

2. Use Clear Tag Names

Good examples:

DI_Box_Present_PE
OSR_Box_Count
CTU_Box_Counter
Box_Count_Complete
DO_Conveyor_Run

Avoid unclear names like:

B3:0/1
Counter1
Sensor_A
Output_2

3. Reset Counters Intentionally

Do not reset counters from too many places.

Better:

Reset counter only from:
Operator Reset
Batch Complete Reset
Recipe Change
Machine Initialization

4. Separate Count Logic from Output Logic

Avoid controlling physical outputs directly from counter rungs all over the program.

Better structure:

Counter Logic
        ↓
Batch Complete Bit
        ↓
Motor Command Logic
        ↓
Output Mapping

5. Watch for Sensor Bounce

If the sensor signal is unstable, use:

Debounce timer
Input filter
One-shot
Better sensor alignment
Shielded cable if needed
Mechanical correction

Simple Ladder Concept

Counter Logic
Box_Photoeye_OS        CTU Box_Counter
----] [--------------------[ CTU ]----
                         PRE = 10
                         ACC = Current Count
Batch Complete Logic
Box_Counter.DN        Batch_Complete
----] [--------------------( )----
Reset Logic
Reset_PB              RES Box_Counter
----] [--------------------[ RES ]----

Real Industrial Example: Case Packing

A case packer needs to place 12 bottles into each case.

Inputs
Bottle Photoeye
Case Present Sensor
Reset Button
Machine Auto Mode
Fault Reset
Counter
Bottle_Counter
PRE = 12
Outputs
Conveyor Run
Pusher Solenoid
Case Complete Light
Operation
1. Case is present.
2. Conveyor runs.
3. Bottle photoeye counts bottles.
4. Counter reaches 12.
5. Conveyor stops.
6. Pusher activates.
7. Counter resets for next case.

This is a very common type of counter application.


High-Speed Counting Note

Standard PLC counters work well for many normal-speed machine signals.

But very fast signals may require special hardware or special programming.

Examples:

Encoders
Very fast part detection
High-speed packaging lines
Pulse train signals
Motion feedback

For these cases, you may need:

High-speed counter module
Event task
Immediate input instruction
Encoder module
Motion module

Do not assume a normal ladder counter can count every fast signal.


Key Terms

TermMeaning
CounterPLC instruction used to count events
CTUCount Up instruction
CTDCount Down instruction
PREPreset target value
ACCAccumulated current count
DNDone bit, turns ON when ACC reaches PRE
RESReset instruction
One-ShotSignal pulse active for only one scan
Rising EdgeSignal transition from OFF to ON
Falling EdgeSignal transition from ON to OFF
PhotoeyeSensor often used for product counting
DebounceLogic used to stabilize noisy signals
High-Speed CounterSpecial counter for fast pulses

Final Thoughts

PLC counters are essential in industrial automation. They are used to count products, cycles, rejects, machine strokes, and production totals.

The most common counter instructions are CTU for counting up and CTD for counting down.

But the real key to reliable counting is understanding the signal being counted. A sensor that stays ON too long, bounces, or changes too fast can cause incorrect counts.

That is why one-shots are so important. They help make sure one event creates one count.

For an Automation Technician, mastering counters means understanding not only the PLC instruction, but also the field sensor, scan cycle, reset logic, and machine sequence.

Leave a Reply

Your email address will not be published. Required fields are marked *