How to Use Counter in Ladder Logic for PLC Programming
In ladder logic, use a
CTU (Count Up) or CTD (Count Down) instruction to create a counter that increments or decrements a value each time a condition is met. The counter tracks events and can trigger outputs when it reaches a preset value.Syntax
The basic syntax for a counter in ladder logic includes the counter type, counter address, preset value, and current count. For example, a Count Up counter (CTU) uses:
- Counter Name: Unique identifier for the counter.
- CU (Count Up) Input: The condition that triggers the count increment.
- Preset (PV): The target count value to reach.
- Current Count (CV): The current count value stored by the counter.
- Reset (R) Input: Resets the counter to zero when activated.
plaintext
CTU CounterName CU R PV CV
Example
This example shows a Count Up (CTU) counter that increments each time a start button is pressed. When the count reaches 5, an output lamp turns on. Pressing the reset button clears the count.
plaintext
(* Ladder Logic Example *) | Start_Button |----[ CTU Counter1 ]----( Lamp ) | Reset_Button |----[ R Counter1 ] (* Counter1 Parameters: *) (* PV = 5 *) (* CV increments by 1 each Start_Button press *)
Output
When Start_Button is pressed 5 times, Lamp turns ON. Reset_Button resets count to 0 and Lamp turns OFF.
Common Pitfalls
Common mistakes when using counters in ladder logic include:
- Not resetting the counter, causing it to stay at the preset value and never count again.
- Using the count input (CU) incorrectly, such as holding the input instead of pulsing it, which causes multiple counts.
- Confusing Count Up (CTU) with Count Down (CTD) counters.
Always use a pulse (momentary signal) to increment the counter and include a reset condition.
plaintext
(* Wrong: Holding input causes multiple counts *)
| Start_Button |----[ CTU Counter1 ]
(* Right: Use a pulse or edge detection for counting *)
| Start_Button_Pulse |----[ CTU Counter1 ]Quick Reference
| Term | Description |
|---|---|
| CTU | Count Up counter increments on each input pulse |
| CTD | Count Down counter decrements on each input pulse |
| PV | Preset Value - target count to trigger output |
| CV | Current Value - current count stored |
| CU | Count Up input - triggers increment |
| CD | Count Down input - triggers decrement |
| R | Reset input - resets counter to zero |
Key Takeaways
Use CTU or CTD instructions to count events in ladder logic.
Always trigger counters with a pulse, not a continuous signal.
Reset counters to reuse them and avoid stuck counts.
Set a preset value to define when the counter output activates.
Understand the difference between Count Up and Count Down counters.