# RES — Reset

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

> RES in rungs.dev clears the accumulator and status bits of a TIMER, COUNTER or CONTROL tag back to zero — typically paired with RTO, CTU, CTD, or an array instruction on the same tag.

Clears the accumulator and status bits of a TIMER, COUNTER or CONTROL tag back to zero. The preset — .PRE or .LEN — is kept.

## Operands [#operands]

| Name        | Type                              |
| ----------- | --------------------------------- |
| `structure` | `TIMER` \| `COUNTER` \| `CONTROL` |

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

Each structure has one field that counts up and one that says how far — and `RES` clears the
first while keeping the second.

- Rung goes true → the counting field is cleared to `0` — `.ACC` on a `TIMER` or `COUNTER`, `.POS` on a `CONTROL` — and every status bit on the structure (`.EN`, `.TT`, `.DN`, `.CU`, `.CD`, `.OV`, `.UN`, `.EU`, `.EM`, `.ER`, `.UL`, `.IN`, `.FD` as applicable) is cleared to `0`.
- The target is **not** touched: `.PRE` on a timer or counter, `.LEN` on a control.
- Rung goes false → `RES` does nothing.

`RES` is checked on every scan the rung is true, not just the rising edge. Holding the rung
true holds the structure at zero.

> **INFO**
>
> **RES does not re-derive .EM**
>
> A `CONTROL` reset to `.POS = 0` describes an empty buffer, but `RES` leaves `.EM` at `0`. The
> next load or unload instruction works it out from `.POS` and sets it then.

## Example — Clear a Counter [#example--clear-a-counter]

```ladder
XIC(Button)CTU(PartsCount);XIC(ResetCount)RES(PartsCount)

PartsCount.PRE = 10
PartsCount.ACC = 0
```

Each rising edge on `Button` increments `PartsCount.ACC`. Pressing `ResetCount` clears the accumulator and `PartsCount.DN`.

## When to Use [#when-to-use]

- Clearing a retentive timer ([`RTO`](https://rungs.dev/docs/ladder-logic/instructions/rto)) — it is the only way to drop `.ACC` back to zero.
- Resetting a counter ([`CTU`](https://rungs.dev/docs/ladder-logic/instructions/ctu), [`CTD`](https://rungs.dev/docs/ladder-logic/instructions/ctd)) — counters are retentive across rung transitions.

## When Not to Use [#when-not-to-use]

- A non-retentive timer ([`TON`](https://rungs.dev/docs/ladder-logic/instructions/ton), [`TOF`](https://rungs.dev/docs/ladder-logic/instructions/tof)) already resets when its rung drops. Calling `RES` on it is redundant.

## Common Mistakes [#common-mistakes]

- Leaving the `RES` rung always-true — that holds the structure at zero forever and the timer or counter never runs.
- Restarting a timer on its own `.DN` to make it repeat (`XIC(MyTimer.DN)RES(MyTimer)`). The scan after `RES` only restarts the timer, so every cycle runs one scan longer than `.PRE` — two with `XIO(MyTimer.DN)` in front of the timer instead. That is fine for a flashing light, but a total counted from those cycles falls further behind every cycle. To keep time, let one timer run and work from its `.ACC`.

## Related [#related]

- [Timers overview](https://rungs.dev/docs/ladder-logic/instructions/timers)
- [Counters overview](https://rungs.dev/docs/ladder-logic/instructions/counters)
- [RTO](https://rungs.dev/docs/ladder-logic/instructions/rto) — retentive timer that requires `RES`
- [CTU](https://rungs.dev/docs/ladder-logic/instructions/ctu), [CTD](https://rungs.dev/docs/ladder-logic/instructions/ctd) — retentive counters
- [BSL and BSR](https://rungs.dev/docs/ladder-logic/instructions/bsl-bsr) — array instructions that keep their state in a `CONTROL`