CTD — Count Down
CTD (Count Down) in rungs.dev decrements .ACC by 1 on each rising edge of the rung. Typically paired with CTU on the same COUNTER tag for bidirectional counting.
CTD
Counter
counter
Preset
?
Accum
?
Decrements .ACC by 1 on each rising edge of the rung. Typically paired with CTU on the same COUNTER tag.
Operands
| Name | Type |
|---|---|
counter | COUNTER |
How It Works
| Event | .ACC | .CD | .DN |
|---|---|---|---|
| Rising edge of rung | -1 | 1 | 1 when .ACC ≥ .PRE |
| Rung stays true | unchanged | 1 | unchanged |
| Rung false | unchanged | 0 | unchanged |
RES on the tag | 0 | 0 | 0 |
.ACC can go negative. .DN tracks the preset comparison regardless of direction.
Example — Remaining Slots
A parking lot has 20 slots. A CTU counts cars entering; a CTD counts cars leaving. Both write to the same tag.
0
EntrySensor
CTU
Counter
CarsInLot
Preset
20
Accum
0
1
ExitSensor
CTD
Counter
CarsInLot
Preset
20
Accum
0
2
CarsInLot.DN
LotFull
Practice
Try counting both directions in the Count Up/Down exercise — track a count that rises and falls on one tag.
Common Mistakes
- Expecting
CTDto stop at zero — it does not. Use a comparison (GE/LE) if you need a floor. - Pairing
CTUandCTDon different tags — both instructions must target the sameCOUNTERtag for the counts to net out.
Related
- Counters overview
- CTU — count-up counterpart
- RES — clears the accumulator
- Compare instructions — bound-checking
CTU — Count Up
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.
RES — Reset
RES in rungs.dev clears the accumulator and status bits of a TIMER or COUNTER tag back to zero — typically paired with RTO, CTU, or CTD on the same tag.