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 mnemonic | American mnemonic | Name | Data type | Direction | Required | Access | Meaning |
|---|---|---|---|---|---|---|---|
| Instance | Instance | Instance (the counter’s memory) | IEC_COUNTER / COUNTER | Input | Yes | — | Instance (C1…): the counter's memory. |
| CU | CU | Count up | BOOL | Input | Yes | Read (C1.CU) | Count up (rung power): rising edge = +1. |
| CD | CD | Count down | BOOL | Input | No | Read (C1.CD) | Count down: rising edge = −1. |
| R | — | Reset | BOOL | Input | No | Read (C1.R) | Reset: CV / ACC = 0 (highest priority). |
| LD | — | Load | BOOL | Input | No | Read (C1.LD) | Load: CV / ACC takes the value PV / PRE. |
| PV | PRE | Preset | DINT | Input | Yes | Read and write (C1.PV / C1.PRE) | Preset: the value to reach. The program can change it with a MOVE / MOV. |
| QU | DN | Preset reached (done) | BOOL | Output | No | Read (C1.QU / C1.DN) | 1 when CV / ACC ≥ PV / PRE. |
| QD | — | Zero reached | BOOL | Output | No | Read (C1.QD) | 1 when CV / ACC ≤ 0 (European style). |
| CV | ACC | Accumulator: current value | DINT | Output | No | Read 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. |
| — | OV | Overflow | BOOL | Output | No | Read (C1.OV) | Overflow: 1 when counting goes past 2,147,483,647 (the value stops there). Cleared by the reset or the load. |
| — | UN | Underflow | BOOL | Output | No | Read (C1.UN) | Underflow: 1 when counting down goes below −2,147,483,648. Cleared by the reset or the load. |
| Mnemonic | Name | Data type | Direction | Required | Access | Meaning |
|---|---|---|---|---|---|---|
| Instance | Instance (the counter’s memory) | IEC_COUNTER | Input | Yes | — | Instance (C1…): the counter's memory. |
| CU | Count up | BOOL | Input | Yes | Read (C1.CU) | Count up (rung power): rising edge = +1. |
| CD | Count down | BOOL | Input | No | Read (C1.CD) | Count down: rising edge = −1. |
| R | Reset | BOOL | Input | No | Read (C1.R) | Reset: CV = 0 (highest priority). |
| LD | Load | BOOL | Input | No | Read (C1.LD) | Load: CV takes the value PV. |
| PV | Preset | DINT | Input | Yes | Read and write (C1.PV) | Preset: the value to reach. The program can change it with a MOVE. |
| QU | Preset reached (done) | BOOL | Output | No | Read (C1.QU) | 1 when CV ≥ PV. |
| QD | Zero reached | BOOL | Output | No | Read (C1.QD) | 1 when CV ≤ 0 (European style). |
| CV | Accumulator: current value | DINT | Output | No | Read 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. |
| Mnemonic | Name | Data type | Direction | Required | Access | Meaning |
|---|---|---|---|---|---|---|
| Instance | Instance (the counter’s memory) | COUNTER | Input | Yes | — | Instance (C1…): the counter's memory. |
| CU | Count up | BOOL | Input | Yes | Read (C1.CU) | Count up (rung power): rising edge = +1. |
| CD | Count down | BOOL | Input | No | Read (C1.CD) | Count down: rising edge = −1. |
| PRE | Preset | DINT | Input | Yes | Read and write (C1.PRE) | Preset: the value to reach. The program can change it with a MOV. |
| DN | Preset reached (done) | BOOL | Output | No | Read (C1.DN) | 1 when ACC ≥ PRE. |
| ACC | Accumulator: current value | DINT | Output | No | Read 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. |
| OV | Overflow | BOOL | Output | No | Read (C1.OV) | Overflow: 1 when counting goes past 2,147,483,647 (the value stops there). Cleared by the reset or the load. |
| UN | Underflow | BOOL | Output | No | Read (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
Timing diagram checked against the simulator (the same engine as the editor).
Example
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
- Priority: R (reset to 0), then LD (load PV / PRE), then counting.Priority: R (reset to 0), then LD (load PV), then counting.Priority: R (reset to 0), then LD (load PRE), then counting.
- An edge on CU and on CD in the same scan cancel out: nothing changes.
- CV / ACC stays between −2,147,483,648 and 2,147,483,647.CV stays between −2,147,483,648 and 2,147,483,647.ACC stays between −2,147,483,648 and 2,147,483,647.
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.