# CTU — Count Up

Source: https://rungs.dev/docs/ladder-logic/instructions/ctu

> CTU (Count Up) in rungs.dev increments .ACC by 1 on each rising edge of the rung. Sets .DN when .ACC reaches .PRE and keeps counting past the preset value.

Increments `.ACC` by 1 on each rising edge of the rung. Sets `.DN` when `.ACC` reaches `.PRE`; keeps counting past the preset.

## Operands [#operands]

| Name      | Type      |
| --------- | --------- |
| `counter` | `COUNTER` |
| `preset`  | `DINT`    |
| `accum`   | `DINT`    |

`preset` and `accum` are pseudo-operands: they hold the value of `.PRE` and `.ACC` on the counter tag.

## How It Works [#how-it-works]

| Event                     | `.ACC`    | `.CU` | `.DN`                    |
| ------------------------- | --------- | ----- | ------------------------ |
| Rising edge of rung       | `+1`      | `1`   | `1` when `.ACC` ≥ `.PRE` |
| Rung stays true           | unchanged | `1`   | unchanged                |
| Rung false                | unchanged | `0`   | unchanged                |
| [`RES`](https://rungs.dev/docs/ladder-logic/instructions/res) on the tag | `0`       | `0`   | `0`                      |

`CTU` counts on the **transition** from false to true. Holding the input true does not keep counting.

A rung that is already true when the program starts does not count either. The counter only counts a change it sees while the program is running — the rung has to go false, then true. ([Prescan](https://rungs.dev/docs/scan-cycle/the-scan-cycle#before-the-first-scan) sets this up before the first scan.)

## Example — Parts Counter [#example--parts-counter]

Count boxes passing a sensor. Signal "full" at 10 boxes.

```ladder
XIC(BoxSensor)CTU(Boxes);XIC(Boxes.DN)OTE(BinFull);XIC(ResetBtn)RES(Boxes)

Boxes.PRE = 10
Boxes.ACC = 0
```

> **IDEA**
>
> **Practice**
>
> Try `CTU` in the [Count Up exercise](https://rungs.dev/exercises/count-up) — count input pulses and act when the target is reached.

## Common Mistakes [#common-mistakes]

- Adding `ONS` before a `CTU` — unnecessary. `CTU` already counts on the rising edge.
- Expecting `.DN` to block further counting — it does not. `.ACC` keeps climbing. Add a [`RES`](https://rungs.dev/docs/ladder-logic/instructions/res) or an interlock if you need to stop.

## Related [#related]

- [Counters overview](https://rungs.dev/docs/ladder-logic/instructions/counters) — members, units, shared behaviour
- [CTD](https://rungs.dev/docs/ladder-logic/instructions/ctd) — count-down counterpart
- [RES](https://rungs.dev/docs/ladder-logic/instructions/res) — clears the accumulator