Learn PLCs free
CountersIntermediateIEC 61131-3

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

NameTypeDescription
CUBOOLCount up input
CDBOOLCount down input
RBOOLReset input - sets CV to 0
LDBOOLLoad input - sets CV to PV
PVINTPreset value

Outputs

NameTypeDescription
QUBOOLUp-count done - TRUE when CV >= PV
QDBOOLDown-count done - TRUE when CV <= 0
CVINTCurrent 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

S

Siemens (TIA Portal)

Use CTUD instruction in TIA Portal. Combines up and down counting in one block.

AB

Allen-Bradley (Studio 5000)

No native CTUD; use separate CTU and CTD or implement with math instructions.

C

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.

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.

20
Ready-Made Templates
LD + ST
Both Languages Included
$29
One-Time Purchase
Get Instant Access -- $29

Instant download - 30-day money-back guarantee - Use on unlimited projects

Free PLC simulator

Wire this block up and run it

Drop the instruction into a rung, hit Run, and watch it execute in your browser. 12 guided lessons across 8 PLC dialects — free account, no credit card.

Practice PLCs free →