Function Block - Down counter.


CD : BOOL     Enable counting. Counter is decreased on each call when CU is TRUE
LOAD : BOOL   Re-load command. Counter is set to PV when called with LOAD to TRUE
PV : DINT     Programmed maximum value


Q : BOOL      TRUE when counter is empty, i.e. when CV = 0
CV : DINT     Current value of the counter


The counter is empty (CV = 0) when the application starts. The counter does not include a pulse detection for CD input. Use R_TRIG or F_TRIG function block for counting pulses of CD input signal. In LD language, CD is the input rung. The output rung is the Q output.

CTUr, CTDr, CTUDr function blocks operate exactly as other counters, except that all boolean inputs (CU, CD, RESET, LOAD) have an implicit rising edge detection included. Not that these counters may be not supported on some target systems.

ST Language

(* MyCounter is a declared instance of CTD function block *)
MyCounter (CD, LOAD, PV);
Q := MyCounter.Q;
CV := MyCounter.CV;

FBD Language

CtdFbd.gif (1361 octets)

LD Language

CtdLd.gif (1478 octets)

IL Language:

(* MyCounter is a declared instance of CTD function block *)
Op1: CAL    MyCounter (CD, LOAD, PV)
     LD     MyCounter.Q
     ST     Q
     LD     MyCounter.CV
     ST     CV

See also