CTD — Count Down
CTD
Counter
counter
(CD)
Preset
?
(DN)
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.
Tag setup: CarsInLot is a COUNTER with .PRE = 20.
XIC(EntrySensor)CTU(CarsInLot);XIC(ExitSensor)CTD(CarsInLot);XIC(CarsInLot.DN)OTE(LotFull)
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