Learn PLCs free
CountersBeginnerIEC 61131-3

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

Implementation note: This page uses a common IEC-style teaching interface. Confirm the actual PV and CV types in your library: current CODESYS Standard documentation, for example, exposes WORD, while other IEC and vendor implementations provide INT, DINT or dedicated counter structures.

Inputs

NameTypeDescription
CUBOOLCount up input - increments on rising edge
RBOOLReset input - sets CV to 0
PVINTPreset value (target count)

Outputs

NameTypeDescription
QBOOLCounter done - TRUE when CV >= PV
CVINTCurrent 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.

CTU rising-edge count diagramCV increases only on rising edges of CU. With PV = 3, Q turns on at the third edge and stays on until reset.CUQCV0123 = PV
Blue is the input, green is the boolean output, and amber is elapsed time or current count. Transitions are shown at task executions; real timing resolution depends on the controller and task.

State table

MomentInputInternal stateOutputEngineering meaning
ResetR/RESET = TRUECV = 0Q = FALSEReset has priority and clears the batch state.
First edgeCU changes FALSE → TRUECV: 0 → 1Q = FALSE for PV = 3One event, not one scan, is counted.
CU held TRUECU remains TRUECV remains 1Q unchangedThe internal edge memory prevents scan-by-scan increments.
Preset edgeThird FALSE → TRUE edgeCV reaches 3Q = TRUEThe 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.

PlatformInstructionWhat maps cleanlyCaveat to verify
Siemens IEC countersCTU with IEC counter instancePositive CU edge increments CV; Q is TRUE when CV ≥ PVAvailable counter variants and upper limits depend on CPU/instruction selection. Use one instance at one program location.
Rockwell LogixCTU with COUNTER structureFalse-to-true rung transitions increment ACC and DN indicates ACC ≥ PRELogix can continue beyond PRE and exposes overflow behavior; it does not use the IEC PV/CV signature.
CODESYS / IEC librariesCTU or a typed CTU variantRising CU edge increments and RESET clears the valueCurrent 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

  1. 1Apply one clean rising edge and confirm CV increases by exactly one.
  2. 2Hold CU true for several scans and confirm CV does not keep increasing.
  3. 3Test reset while CU is false and while CU is true.
  4. 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.

  1. 1Reset the counter and confirm CV = 0 and Q = false.
  2. 2Apply four separated false-to-true sensor transitions.
  3. 3Apply the fifth transition.
  4. 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.

Platform-Specific Implementation

S

Siemens (TIA Portal)

Use CTU instruction in TIA Portal. Counter data type is IEC_Counter. Also available as legacy S7 counter (C#).

AB

Allen-Bradley (Studio 5000)

Use CTU instruction in Studio 5000. Counter data type is COUNTER. Access .DN (done), .ACC (accumulated), .PRE (preset).

C

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.

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 →