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 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. |
| CD | CD | Count down | BOOL | Input | Yes | Read (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 | — | Load | BOOL | Input | No | Read (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. |
| 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 | — | Done | BOOL | Output | No | Read (C1.Q) | 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. |
| QU | DN | Preset reached (done) | BOOL | Output | No | Read (C1.QU / C1.DN) | 1 when CV / ACC ≥ PV / PRE: the American DN. |
| — | 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. |
| CD | Count down | BOOL | Input | Yes | Read (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. |
| LD | Load | BOOL | Input | No | Read (C1.LD) | Load (European style): CV takes the value PV, before counting down. In the American style, a MOVE to CV 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) | 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. |
| QU | Preset reached (done) | BOOL | Output | No | Read (C1.QU) | 1 when CV ≥ PV: the American DN. |
| Mnemonic | Name | Data type | Direction | Required | Access | Meaning |
|---|---|---|---|---|---|---|
| Instance | Instance (the counter’s memory) | COUNTER | Input | Yes | — | Instance (C1…): the counter's memory. |
| CD | Count down | BOOL | Input | Yes | Read (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. |
| PRE | Preset | DINT | Input | Yes | Read and write (C1.PRE) | Preset: the value to reach. The program can change it with a MOV. |
| 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. |
| DN | Preset reached (done) | BOOL | Output | No | Read (C1.DN) | 1 when ACC ≥ PRE: the American DN. |
| 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
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
- Load first with LD: at start CV / ACC is 0.Load first with LD: at start CV is 0.Load first with LD: at start ACC is 0.
- LD takes priority over counting down.
- CV / ACC can go negative; it stops at −2,147,483,648 (in the American style UN then turns 1).CV can go negative; it stops at −2,147,483,648 (in the American style UN then turns 1).ACC can go negative; it stops at −2,147,483,648 (in the American style UN then turns 1).
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).