CTUD (Counter Up/Down)
Counts both up and down with separate done outputs for each direction.
The CTUD (Counter Up/Down) function block combines both up-counting and down-counting in a single block. It increments CV on a rising edge of CU and decrements CV on a rising edge of CD. It has two outputs: QU goes TRUE when CV >= PV (up-count complete), and QD goes TRUE when CV <= 0 (down-count complete). A reset input (R) sets CV to 0, and a load input (LD) sets CV to PV. CTUD is ideal for tracking quantities that both increase and decrease, such as inventory in a buffer, items entering and leaving a zone, or bidirectional position tracking.
Parameters
Inputs
| Name | Type | Description |
|---|---|---|
| CU | BOOL | Count up input |
| CD | BOOL | Count down input |
| R | BOOL | Reset input - sets CV to 0 |
| LD | BOOL | Load input - sets CV to PV |
| PV | INT | Preset value |
Outputs
| Name | Type | Description |
|---|---|---|
| QU | BOOL | Up-count done - TRUE when CV >= PV |
| QD | BOOL | Down-count done - TRUE when CV <= 0 |
| CV | INT | Current counter value |
Ladder Logic Example
// Ladder Logic - CTUD (Buffer Zone Tracking) // // |----[ Entry_Sensor ]-----[CTUD Buffer_Count]----| // |----[ Exit_Sensor ] CU: Entry_Sensor | // | CD: Exit_Sensor | // | R: Reset_Count | // | PV: 20 | // | QU: Buffer_Full | // | QD: Buffer_Empty |
Structured Text Example
VAR
Buffer_Count : CTUD;
Entry_Sensor, Exit_Sensor : BOOL;
Buffer_Full, Buffer_Empty : BOOL;
Items_In_Buffer : INT;
END_VAR
Buffer_Count(CU := Entry_Sensor, CD := Exit_Sensor, R := FALSE, LD := FALSE, PV := 20);
Buffer_Full := Buffer_Count.QU;
Buffer_Empty := Buffer_Count.QD;
Items_In_Buffer := Buffer_Count.CV;20 Production-Ready Ladder Logic Templates
Stop writing the same rungs from scratch. Get copy-paste-ready templates for motor control, PID loops, safety interlocks, conveyors, and more.
Platform-Specific Implementation
Siemens (TIA Portal)
Use CTUD instruction in TIA Portal. Combines up and down counting in one block.
Allen-Bradley (Studio 5000)
No native CTUD; use separate CTU and CTD or implement with math instructions.
CODESYS
Standard CTUD in Standard library. Fully IEC 61131-3 compliant.
Common Applications
- Buffer/accumulator zone tracking
- Parking lot occupancy
- Inventory tracking
- Bidirectional position counting
- Queue management
Common Mistakes to Avoid
- Not handling simultaneous CU and CD rising edges
- Confusing QU and QD output logic
Frequently Asked Questions
What is CTUD (Counter Up/Down) in PLC programming?
Counts both up and down with separate done outputs for each direction. The CTUD (Counter Up/Down) function block combines both up-counting and down-counting in a single block. It increments CV on a rising edge of CU and decrements CV on a rising edge of CD.
What are common applications of CTUD (Counter Up/Down)?
CTUD (Counter Up/Down) is commonly used for: Buffer/accumulator zone tracking, Parking lot occupancy, Inventory tracking, Bidirectional position counting, Queue management.
How do I use CTUD (Counter Up/Down) in different PLC platforms?
Siemens: Use CTUD instruction in TIA Portal. Combines up and down counting in one block. Allen-Bradley: No native CTUD; use separate CTU and CTD or implement with math instructions. CODESYS: Standard CTUD in Standard library. Fully IEC 61131-3 compliant.
Related Function Blocks
CTU (Counter Up)
Counts up on each rising edge; output activates when count reaches preset.
View Reference →CTD (Counter Down)
Counts down from preset value; output activates when count reaches zero.
View Reference →CTU with Auto-Reset
Counter that automatically resets after reaching preset, creating repeating count cycles.
View Reference →HSC (High-Speed Counter)
Hardware-accelerated counter for high-frequency pulse inputs beyond normal scan rate.
View Reference →Stop Writing Ladder Logic From Scratch
Get 20 production-ready ladder logic templates for $29 -- download instantly and use them on your next project today.
Instant download - 30-day money-back guarantee - Use on unlimited projects