Increments a counter on each rising edge of the count input and outputs TRUE when the count reaches the preset value.
The CTU (Count-Up) instruction implements an up-counter, as defined in IEC 61131-3. Each time the count-up input .CU has a rising edge (FALSE-to-TRUE transition), the current value .CV is incremented by 1. When .CV reaches or exceeds the preset value .PV, the output .Q becomes TRUE.
Key behavior:
.CU - .CV increments by 1.CV >= .PV - output .Q becomes TRUE.CV returns to 0, .Q becomes FALSEThis is commonly used for counting parts, cycles, events, or any discrete occurrences.
The
P(pulse) qualifier is a natural choice forCTUbecause it triggers the count input once per step activation, giving you one count per cycle.
{GIF:HERE} - Adding a CTU count-up counter action to a step with name "counter_name", description "Count up", qualifier set to P (pulse), instruction set to CTU, and preset value of 100
from automation_machine import ActionQualifier, ActionInstruction
step.add_action("counter_name", "Count up", qualifier=ActionQualifier.P, instruction=ActionInstruction.CTU, preset_value=100)
ActionQualifier.P to count once per step activationActionInstruction.CTU100)Each CTU counter instance exposes the following child variables:
| Variable | Type | Description |
|---|---|---|
.CU |
BOOL | Count-up input - rising edge increments the counter |
.Q |
BOOL | Output signal - TRUE when .CV >= .PV |
.PV |
INT | Preset value - the target count |
.CV |
INT | Current value - the current count (starts at 0) |