CTU Counter in PLC: Rising-Edge Count and Reset
Quick answer
CTU increments its current value once for each FALSE-to-TRUE transition at CU while reset is inactive. Q becomes TRUE when CV reaches the preset comparison condition. Holding CU TRUE does not keep counting. Reset clears CV and Q, but exact types, saturation and overflow behavior differ by vendor.
The CTU (Counter Up) function block increments a counter value (CV) by 1 on each rising edge of the count input (CU). When the counter value reaches or exceeds the preset value (PV), the output (Q) goes TRUE. A reset input (R) sets CV back to 0 and Q to FALSE. CTU counters are fundamental to PLC programming and are used extensively for counting parts, tracking production quantities, sequencing operations, and batch counting.
Reviewed
Parameters
Inputs
| Name | Type | Description |
|---|---|---|
| CU | BOOL | Count up input - increments on rising edge |
| R | BOOL | Reset input - sets CV to 0 |
| PV | INT | Preset value (target count) |
Outputs
| Name | Type | Description |
|---|---|---|
| Q | BOOL | Counter done - TRUE when CV >= PV |
| CV | INT | Current counter value |
How CTU count-up counter works scan by scan
Read the waveforms and state table together. The diagram shows the sequence; the table states what the program should observe at each execution.
CTU rising-edge count diagram
CV increases only on rising edges of CU. With PV = 3, Q turns on at the third edge and stays on until reset.
State table
| Moment | Input | Internal state | Output | Engineering meaning |
|---|---|---|---|---|
| Reset | R/RESET = TRUE | CV = 0 | Q = FALSE | Reset has priority and clears the batch state. |
| First edge | CU changes FALSE → TRUE | CV: 0 → 1 | Q = FALSE for PV = 3 | One event, not one scan, is counted. |
| CU held TRUE | CU remains TRUE | CV remains 1 | Q unchanged | The internal edge memory prevents scan-by-scan increments. |
| Preset edge | Third FALSE → TRUE edge | CV reaches 3 | Q = TRUE | The target batch count is complete. |
Ladder and Structured Text examples
Count a three-part batch
|----[ Part_Sensor ]----[ CTU PartCount ]----|
| PV: 3 |
| R: Reset_Batch |
|----[ PartCount.Q ]-------( Batch_Complete )-|A clean sensor transition increments once. If the sensor chatters, the PLC can see several legitimate edges; use input filtering or debounce instead of adding a second edge detector blindly.
IEC-style Structured Text call
VAR
PartCount : CTU;
PartSensor : BOOL;
ResetBatch : BOOL;
BatchComplete : BOOL;
END_VAR
PartCount(CU := PartSensor, RESET := ResetBatch, PV := 3);
BatchComplete := PartCount.Q;Some libraries name the reset input R rather than RESET and use WORD, INT or a typed counter variant for PV/CV. Compile against the installed library instead of copying the signature unchanged.
Vendor compatibility
A shared mnemonic does not guarantee an identical interface or state machine. Confirm the instruction help for the controller, firmware, language and library version used on the project.
| Platform | Instruction | What maps cleanly | Caveat to verify |
|---|---|---|---|
| Siemens IEC counters | CTU with IEC counter instance | Positive CU edge increments CV; Q is TRUE when CV ≥ PV | Available counter variants and upper limits depend on CPU/instruction selection. Use one instance at one program location. |
| Rockwell Logix | CTU with COUNTER structure | False-to-true rung transitions increment ACC and DN indicates ACC ≥ PRE | Logix can continue beyond PRE and exposes overflow behavior; it does not use the IEC PV/CV signature. |
| CODESYS / IEC libraries | CTU or a typed CTU variant | Rising CU edge increments and RESET clears the value | Current Standard-library documentation can expose WORD for PV/CV, while other implementations use INT. Check the installed version. |
Failure modes and edge cases to test
Sensor bounce creates three rising edges
CTU counts three events. Edge-triggered does not mean debounced.
CU is TRUE while reset is removed
First-scan/prescan behavior is platform specific; require a clean FALSE state before the next intended edge.
CV reaches its numeric upper limit
Some implementations saturate and others expose overflow/rollover behavior. Test and alarm before the limit.
The same counter tag is used in two instructions
Both calls modify shared edge/state memory and can miscount. Use one owning instruction instance.
Evidence and review status
The edge-counting and reset behavior were checked against current CODESYS documentation. Parameter names and numeric types differ between vendor libraries and standard editions.
Technical review date:
Critical behavior
- CTU increments once on a false-to-true transition at CU, not once for every scan that CU remains true.
- Reset has priority according to the implementation and sets the current value back to its initial state.
- Q becomes true when the current value reaches the preset comparison condition.
- Input bounce or repeated transitions can create extra counts even though the block is edge-triggered.
Verification checklist
- 1Apply one clean rising edge and confirm CV increases by exactly one.
- 2Hold CU true for several scans and confirm CV does not keep increasing.
- 3Test reset while CU is false and while CU is true.
- 4Confirm PV and CV types, upper limit and overflow behavior in the target library.
Worked test
Count a five-part batch
Set PV = 5, drive CU from a debounced part sensor and use ResetBatch for R or RESET.
- 1Reset the counter and confirm CV = 0 and Q = false.
- 2Apply four separated false-to-true sensor transitions.
- 3Apply the fifth transition.
- 4Hold the sensor true for two more scans, then reset.
Expected result: CV reaches 4 after four edges, then 5 and Q true after the fifth. Holding the input true does not add counts; reset returns CV and Q to their initial state.
Technical sources
The target controller's version-specific instruction help remains authoritative.
- CTU Standard function block
CODESYS Development
- IEC-style CTU_INT declaration example
PLCopen — Illustrates a typed CTU implementation and saturation logic
- Count Up (CTU)
Rockwell Automation Studio 5000 — Logix COUNTER structure and overflow behavior
- CTU: Count up
Siemens STEP 7 V21 documentation — Positive-edge counting, reset and preset comparison
Platform-Specific Implementation
Siemens (TIA Portal)
Use CTU instruction in TIA Portal. Counter data type is IEC_Counter. Also available as legacy S7 counter (C#).
Allen-Bradley (Studio 5000)
Use CTU instruction in Studio 5000. Counter data type is COUNTER. Access .DN (done), .ACC (accumulated), .PRE (preset).
CODESYS
Check the installed Standard library version before declaring the instance. Current CODESYS 3.5.22.0 documentation exposes RESET, PV and CV with WORD for CTU; other typed counter blocks and library versions use different integer types.
Common Applications
- Part counting on conveyors
- Batch quantity tracking
- Production monitoring
- Event counting
- Sequence step counting
Common Mistakes to Avoid
- Not debouncing the count input (double counting)
- Forgetting to reset after batch complete
- Using wrong data type for PV (INT vs DINT for large counts)
Frequently Asked Questions
What is CTU (Counter Up) in PLC programming?
Counts up on each rising edge; output activates when count reaches preset. The CTU (Counter Up) function block increments a counter value (CV) by 1 on each rising edge of the count input (CU). When the counter value reaches or exceeds the preset value (PV), the output (Q) goes TRUE.
What are common applications of CTU (Counter Up)?
CTU (Counter Up) is commonly used for: Part counting on conveyors, Batch quantity tracking, Production monitoring, Event counting, Sequence step counting.
How do I use CTU (Counter Up) in different PLC platforms?
Siemens: Use CTU instruction in TIA Portal. Counter data type is IEC_Counter. Also available as legacy S7 counter (C#). Allen-Bradley: Use CTU instruction in Studio 5000. Counter data type is COUNTER. Access .DN (done), .ACC (accumulated), .PRE (preset). CODESYS: Check the installed Standard library version before declaring the instance. Current CODESYS 3.5.22.0 documentation exposes RESET, PV and CV with WORD for CTU; other typed counter blocks and library versions use different integer types.
Related Function Blocks
CTD (Counter Down)
Counts down from preset value; output activates when count reaches zero.
View Reference →CTUD (Counter Up/Down)
Counts both up and down with separate done outputs for each direction.
View Reference →TON (Timer On-Delay)
Starts timing on rising edge, output activates after preset delay.
View Reference →R_TRIG (Rising Edge Detection)
Detects FALSE-to-TRUE transition, outputs single-scan pulse on rising edge.
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 →