CTUD Up/down counter (CTUD)

Also called: bidirectional counter, count up/down, CTUD counter

European style only: the American style has no such instruction.

Counts up on CU, down on CD; QU / DN when CV / ACC ≥ PV / PRE, QD when CV / ACC ≤ 0.Counts up on CU, down on CD; QU when CV ≥ PV, QD when CV ≤ 0.Counts up on CU, down on CD; DN when ACC ≥ PRE, QD when ACC ≤ 0.

What it does

The CTUD up/down counter adds 1 on each rising edge of the rung (CU) and subtracts 1 on each rising edge of CD. Two outputs: QU / DN (preset reached) and QD (zero reached).The CTUD up/down counter adds 1 on each rising edge of the rung (CU) and subtracts 1 on each rising edge of CD. Two outputs: QU (preset reached) and QD (zero reached).The CTUD up/down counter adds 1 on each rising edge of the rung (CU) and subtracts 1 on each rising edge of CD. Two outputs: DN (preset reached) and QD (zero reached).

When to use it

For parts coming in and going out: cars in a parking lot, parts in a buffer zone.

Operands

European mnemonicAmerican mnemonicNameData typeDirectionRequiredAccessMeaning
InstanceInstanceInstance (the counter’s memory)IEC_COUNTER / COUNTERInputYes—Instance (C1…): the counter's memory.
CUCUCount upBOOLInputYesRead (C1.CU)Count up (rung power): rising edge = +1.
CDCDCount downBOOLInputNoRead (C1.CD)Count down: rising edge = −1.
R—ResetBOOLInputNoRead (C1.R)Reset: CV / ACC = 0 (highest priority).
LD—LoadBOOLInputNoRead (C1.LD)Load: CV / ACC takes the value PV / PRE.
PVPREPresetDINTInputYesRead and write (C1.PV / C1.PRE)Preset: the value to reach. The program can change it with a MOVE / MOV.
QUDNPreset reached (done)BOOLOutputNoRead (C1.QU / C1.DN)1 when CV / ACC ≥ PV / PRE.
QD—Zero reachedBOOLOutputNoRead (C1.QD)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.
—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.
CUCount upBOOLInputYesRead (C1.CU)Count up (rung power): rising edge = +1.
CDCount downBOOLInputNoRead (C1.CD)Count down: rising edge = −1.
RResetBOOLInputNoRead (C1.R)Reset: CV = 0 (highest priority).
LDLoadBOOLInputNoRead (C1.LD)Load: CV takes the value PV.
PVPresetDINTInputYesRead and write (C1.PV)Preset: the value to reach. The program can change it with a MOVE.
QUPreset reached (done)BOOLOutputNoRead (C1.QU)1 when CV ≥ PV.
QDZero reachedBOOLOutputNoRead (C1.QD)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.
MnemonicNameData typeDirectionRequiredAccessMeaning
InstanceInstance (the counter’s memory)COUNTERInputYes—Instance (C1…): the counter's memory.
CUCount upBOOLInputYesRead (C1.CU)Count up (rung power): rising edge = +1.
CDCount downBOOLInputNoRead (C1.CD)Count down: rising edge = −1.
PREPresetDINTInputYesRead and write (C1.PRE)Preset: the value to reach. The program can change it with a MOV.
DNPreset reached (done)BOOLOutputNoRead (C1.DN)1 when ACC ≥ PRE.
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.
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.QU / C1.DN. Writable members can be changed by the program (MOVE).Readable anywhere in the program, for example C1.QU. 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
CUCDRCV0123210QUQD01234567891011121314scans
American style
CUCDRESACC0123210DN01234567891011121314scans

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

Example

European style
American style

S1 counts up, S2 counts down, S3 resets; H1 turns on at 5.

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: CTUD, a single block.

American: there is no CTUD in ladder; a CTU and a CTD share the same COUNTER. Here it is offered in the European style only.

See also