Learn › Instructions
RES: Reset timers and counters
RES puts a timer or counter back to the start. While its rung is true, it clears the accumulator to zero and turns the done bit off. It's how you start a new batch, clear a retentive timer, or restart a sequence.
What RES does
RES is an output instruction, so it goes in the last column of a rung. Its tag is a TIMER or COUNTER, the same tag used by the timer or counter you want to clear. On every scan where its rung is true, it:
| Tag type | What RES clears |
|---|---|
TIMER | ACC = 0, DN off, EN off, TT off |
COUNTER | ACC = 0, DN off, CU off, CD off |
The preset (PRE) is never changed. When the RES rung is false, RES does nothing at all.
Which instructions need a RES?
- CTU and CTD always do. A counter never resets itself, not even when it reaches its preset, so without a RES it keeps counting forever.
- RTO always does. Keeping its time when the rung goes false is the whole point of an RTO, so a RES is the only way to clear it.
- TON rarely does, since it resets itself whenever its rung goes false. A RES on a TON is only useful to restart it while its rung is still true.
- TOF can be reset to end its delay early, but if the TOF's rung is true it turns DN back on next scan.
Ways to wire a reset
A reset button. The simplest form: an operator presses a button to clear a count.
| ResetPB |
|----] [------------------------------------(RES Parts)--|
Auto-reset at the preset. A counter that resets itself when it reaches its preset makes a "every Nth item" signal:
| PE |
|----] [------------------------------[CTU Every3 PRE 3]--|
| |
| Every3.DN Divert |
|----] [------------------------------------( )----|
| |
| Every3.DN PE |
|----] [---------]/[------------------------(RES Every3)--|
Why the XIO PE on the reset rung? A simpler version that resets as soon as DN is on looks right, but it has a catch. RES also clears the counter's CU bit, so on the next scan the CTU thinks the rung has just gone true and counts the third box again, while it's still in front of the eye. Waiting until the eye is clear avoids that, and as a bonus Divert stays on for as long as the third box is at the eye instead of for a single scan.
The Divert rung also sits above the reset, so it always reads DN before the count is cleared. The scan cycle lesson explains why rung order decides this.
Reset on a mode change. Clear timers and counters when a machine is stopped, so every start begins from a known state:
| Running |
|----]/[------------+-----------------------(RES Boxes)--|
| | |
| +-----------------------(RES StepT)--|
A held reset beats everything else
Because RES acts on every scan its rung is true, holding a reset keeps the timer or counter at zero no matter what its own rung is doing. Suppose a box passes the eye while the reset button is held:
- If the RES rung is below the CTU, the counter counts to 1 and is then cleared in the same scan. You see ACC stay at 0.
- If the RES rung is above the CTU, the counter is cleared first and then counts. Because RES also clears CU, this repeats every scan, so ACC shows 1 for as long as the box is at the eye and the reset is held.
RES also clears CU (or CD), so the counter forgets the rung was already true. That has a side effect worth knowing: if the box is still blocking the eye when the RES rung goes false, the CTU sees a "new" false-to-true change and counts it. It's usually harmless, but it's the reason some programs only allow a reset when the counting sensor is clear.
Try it in the Playground
- Open the Playground and add push buttons
CountandClear. - Build rung 0:
XIC CountthenCTU C1. Build rung 1:XIC ClearthenRES C1. - Press Run, tap Count a few times, then tap Clear and watch ACC drop to zero in the Tags panel.
- Hold Clear and tap Count. Nothing counts. Then swap the rung order and repeat to see the difference described above.
Key points
- RES clears ACC and DN (plus the enable and timing bits) but never the preset.
- It acts every scan its rung is true, so a held reset holds the value at zero.
- Counters and RTOs need one; TONs almost never do.
- Watch the rung order whenever a timer or counter resets itself.