CTD Down counter (CTD)

Also called: count down, CTD counter, decrementing counter

Counts down rising edges of CD from the preset PV / PRE, loaded by LD.Counts down rising edges of CD from the preset PV, loaded by LD.Counts down rising edges of CD from the preset PRE, loaded by LD.

What it does

The CTD down counter subtracts 1 from CV / ACC each time power reaches the instruction. It is loaded first: the LD input in the European style, a MOVE / MOV to ACC in the American style. European style: Q turns 1 when CV reaches 0. American style: DN is 1 while ACC ≥ PRE.The CTD down counter subtracts 1 from CV each time power reaches the instruction. It is loaded first: the LD input in the European style, a MOVE to ACC in the American style. European style: Q turns 1 when CV reaches 0. American style: DN is 1 while ACC ≥ PRE.The CTD down counter subtracts 1 from ACC each time power reaches the instruction. It is loaded first: the LD input in the European style, a MOV to ACC in the American style. European style: Q turns 1 when CV reaches 0. American style: DN is 1 while ACC ≥ PRE.

When to use it

For a decreasing stock, a number of parts left, a number of attempts allowed.

Operands

European mnemonicAmerican mnemonicNameData typeDirectionRequiredAccessMeaning
InstanceInstanceInstance (the counter’s memory)IEC_COUNTER / COUNTERInputYes—Instance (C1…): the counter's memory.
CDCDCount downBOOLInputYesRead (C1.CD)The bit to count down: it says the instruction is active. Each time power reaches the instruction (0 to 1), CV / ACC goes down by 1.
LD—LoadBOOLInputNoRead (C1.LD)Load (European style): CV / ACC takes the value PV / PRE, before counting down. In the American style, a MOVE / MOV to CV / ACC is used.
PVPREPresetDINTInputYesRead and write (C1.PV / C1.PRE)Preset: the value to reach. The program can change it with a MOVE / MOV.
Q—DoneBOOLOutputNoRead (C1.Q)1 when CV / ACC ≤ 0 (European style).
CVACCAccumulator: current valueDINTOutputNoRead and write (C1.CV / C1.ACC)Accumulator: the current value (DINT, from −2,147,483,648 to 2,147,483,647). The program can change it with a MOVE / MOV.
QUDNPreset reached (done)BOOLOutputNoRead (C1.QU / C1.DN)1 when CV / ACC ≥ PV / PRE: the American DN.
—OVOverflowBOOLOutputNoRead (C1.OV)Overflow: 1 when counting goes past 2,147,483,647 (the value stops there). Cleared by the reset or the load.
—UNUnderflowBOOLOutputNoRead (C1.UN)Underflow: 1 when counting down goes below −2,147,483,648. Cleared by the reset or the load.
MnemonicNameData typeDirectionRequiredAccessMeaning
InstanceInstance (the counter’s memory)IEC_COUNTERInputYes—Instance (C1…): the counter's memory.
CDCount downBOOLInputYesRead (C1.CD)The bit to count down: it says the instruction is active. Each time power reaches the instruction (0 to 1), CV goes down by 1.
LDLoadBOOLInputNoRead (C1.LD)Load (European style): CV takes the value PV, before counting down. In the American style, a MOVE to CV is used.
PVPresetDINTInputYesRead and write (C1.PV)Preset: the value to reach. The program can change it with a MOVE.
QDoneBOOLOutputNoRead (C1.Q)1 when CV ≤ 0 (European style).
CVAccumulator: current valueDINTOutputNoRead and write (C1.CV)Accumulator: the current value (DINT, from −2,147,483,648 to 2,147,483,647). The program can change it with a MOVE.
QUPreset reached (done)BOOLOutputNoRead (C1.QU)1 when CV ≥ PV: the American DN.
MnemonicNameData typeDirectionRequiredAccessMeaning
InstanceInstance (the counter’s memory)COUNTERInputYes—Instance (C1…): the counter's memory.
CDCount downBOOLInputYesRead (C1.CD)The bit to count down: it says the instruction is active. Each time power reaches the instruction (0 to 1), ACC goes down by 1.
PREPresetDINTInputYesRead and write (C1.PRE)Preset: the value to reach. The program can change it with a MOV.
ACCAccumulator: current valueDINTOutputNoRead and write (C1.ACC)Accumulator: the current value (DINT, from −2,147,483,648 to 2,147,483,647). The program can change it with a MOV.
DNPreset reached (done)BOOLOutputNoRead (C1.DN)1 when ACC ≥ PRE: the American DN.
OVOverflowBOOLOutputNoRead (C1.OV)Overflow: 1 when counting goes past 2,147,483,647 (the value stops there). Cleared by the reset or the load.
UNUnderflowBOOLOutputNoRead (C1.UN)Underflow: 1 when counting down goes below −2,147,483,648. Cleared by the reset or the load.

Readable anywhere in the program, for example C1.Q / C1.DN. Writable members can be changed by the program (MOVE).Readable anywhere in the program, for example C1.Q. Writable members can be changed by the program (MOVE).Readable anywhere in the program, for example C1.DN. Writable members can be changed by the program (MOVE).

Timing diagram

European style
LDCDCV03210-1QQU0123456789101112scans
American style
MOVCDACC03210-1DN0123456789101112scans

Timing diagram checked against the simulator (the same engine as the editor).

Example

European style
American style

S2 loads 5 into C1 (LD input in European, MOVE / MOV in American); each press on S1 subtracts 1; H1 turns on at 0.S2 loads 5 into C1 (LD input in European, MOVE in American); each press on S1 subtracts 1; H1 turns on at 0.S2 loads 5 into C1 (LD input in European, MOV in American); each press on S1 subtracts 1; H1 turns on at 0.

Try it in the simulatorThe example opens in the free simulator; your own program stays as it was.

Behaviour in detail

European (IEC) and American styles

European: CTD with LD (load) and Q at 1 when CV ≤ 0.

American: CTD with PRE and ACC (DINT); DN is 1 when ACC ≥ PRE, as for a CTU. ACC is loaded with a MOV (the LD input remains available here).

See also