CTD — Counter-Down

Pin layout

DirectionNameTypeDescription
InputCDBOOLCount Down — decrement CV on each rising edge
InputLDBOOLLoad — when TRUE, set CV := PV
InputPVINTPreset Value loaded by LD
OutputQBOOLTRUE when CV <= 0
OutputCVINTCurrent Value

Semantics

LD = TRUE  : CV := PV
CD rising  : CV := CV - 1 (saturates at INT min)
Q := CV <= 0

LD has priority over CD. Use LD to (re-)initialise the counter to its preset.

Example

VAR
    countdown : CTD;
END_VAR

countdown(CD := xPulse, LD := xReset, PV := 10);

IF countdown.Q THEN
    (* zero reached *)
    DoFinish();
END_IF;

IEC reference

IEC 61131-3 third edition (2013), Annex F.6.2.

matiec conformance

Implemented per the standard. Same edge-detection caveat as CTU: CD must see a real rising edge per increment.