CTU Up counter (CTU)
Also called: count up, CTU counter, incrementing counter
Counts rising edges of CU; Q / DN turns 1 when CV / ACC ≥ PV / PRE.Counts rising edges of CU; Q turns 1 when CV ≥ PV.Counts rising edges of CU; DN turns 1 when ACC ≥ PRE.
What it does
The CTU counter adds 1 to CV / ACC each time power reaches the instruction (0 to 1). When CV / ACC reaches the preset (CV / ACC ≥ PV / PRE), Q / DN turns 1. Reset: the R input in the European style, the RES instruction in the American style.The CTU counter adds 1 to CV each time power reaches the instruction (0 to 1). When CV reaches the preset (CV ≥ PV), Q turns 1. Reset: the R input in the European style, the RES instruction in the American style.The CTU counter adds 1 to ACC each time power reaches the instruction (0 to 1). When ACC reaches the preset (ACC ≥ PRE), DN turns 1. Reset: the R input in the European style, the RES instruction in the American style.
When to use it
To count parts, cycles or presses; trigger an action after N events.
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) | The bit to count: it says the instruction is active. Each time power reaches the instruction (0 to 1), CV / ACC goes up by 1. |
| R | — | Reset | BOOL | Input | No | Read (C1.R) | Reset (European style): CV / ACC goes back to 0, before counting. In the American style, the RES instruction is used. |
| 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. |
| Q | DN | Done | BOOL | Output | No | Read (C1.Q / C1.DN) | When CV / ACC reaches the preset (CV / ACC ≥ PV / PRE), Q / DN turns 1. |
| 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) | The bit to count: it says the instruction is active. Each time power reaches the instruction (0 to 1), CV goes up by 1. |
| R | Reset | BOOL | Input | No | Read (C1.R) | Reset (European style): CV goes back to 0, before counting. In the American style, the RES instruction is used. |
| PV | Preset | DINT | Input | Yes | Read and write (C1.PV) | Preset: the value to reach. The program can change it with a MOVE. |
| Q | Done | BOOL | Output | No | Read (C1.Q) | When CV reaches the preset (CV ≥ PV), Q turns 1. |
| 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) | The bit to count: it says the instruction is active. Each time power reaches the instruction (0 to 1), ACC goes up by 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 | Done | BOOL | Output | No | Read (C1.DN) | When ACC reaches the preset (ACC ≥ PRE), DN turns 1. |
| 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.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
Timing diagram checked against the simulator (the same engine as the editor).
Example
S1 counts; after 5 pulses, H1 turns on. S2 resets the counter (R input in European, RES in American).
Try it in the simulatorThe example opens in the free simulator; your own program stays as it was.
Behaviour in detail
- Only edges count: a rung that stays 1 counts once.
- R takes priority: while it is 1, CV / ACC stays 0.R takes priority: while it is 1, CV stays 0.R takes priority: while it is 1, ACC stays 0.
- Counting goes on past PV / PRE (Q / DN stays 1).Counting goes on past PV (Q stays 1).Counting goes on past PRE (DN stays 1).
- CV / ACC stops at 2,147,483,647; in the American style OV then turns 1.CV stops at 2,147,483,647; in the American style OV then turns 1.ACC stops at 2,147,483,647; in the American style OV then turns 1.
- On the first scan the edge memory is 0: a rung already at 1 counts as 1.
European (IEC) and American styles
European: CTU with an R input and a Q output.
American: CTU with PRE, ACC (DINT) and the DN, OV, UN bits, reset by a RES instruction (the R input remains available here).