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

(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

NameType
counterCOUNTER

How It Works

Event.ACC.CD.DN
Rising edge of rung-111 when .ACC.PRE
Rung stays trueunchanged1unchanged
Rung falseunchanged0unchanged
RES on the tag000

.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

(CU)

Preset

20

(DN)

Accum

0

1

ExitSensor

CTD

Counter

CarsInLot

(CD)

Preset

20

(DN)

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 CTD to stop at zero — it does not. Use a comparison (GE / LE) if you need a floor.
  • Pairing CTU and CTD on different tags — both instructions must target the same COUNTER tag for the counts to net out.

On this page