Count Up/Down (CTUD)
The CTUD instruction counts up by one when CUEnable transitions from clear to set. The
instruction counts down by one when CDEnable transitions from clear to set.
When true and CUEnable is true, the CTUD instruction increments the counter by one. When
true and CDEnable is true, the CTUD instruction decrements the counter by one.
Both the CUEnable and CDEnable input parameters can be toggled during the same scan. The
instruction executes the count up prior to the count down.
Count Up

Count Down

When disabled, the CTUD instruction retains its accumulated value. Set the Reset input
parameter to reset the instruction.
Available Languages
Ladder Diagram
This instruction is not available in ladder diagram.
Structured Text
CTUD(CTUD_tag)
Operands
Structured Text
Variable | Type | Format | Description |
---|---|---|---|
CTUD tag | COUNTER | Structure | CTUD structure |
See Structured Text syntax for more information on the syntax of
expressions within structured text.
COUNTER Structure
Mnemonic | Data Type | Description |
---|---|---|
.CD | BOOL | The countdown enable bit contains rung-condition-in when the
instruction was last executed. |
.DN | BOOL | The done bit when clear indicates the counting operation is
complete. |
.OV | BOOL | The overflow bit when set indicates the counter incremented past the
upper limit of 2,147,483,647. |
.UN | BOOL | The underflow when set indicates the counter decremented past the
lower limit of -2,147,483,648. |
.PRE | DINT | The preset value specifies the value which the accumulated value must
reach before the instruction indicates it is done. |
.ACC | DINT | The accumulated value specifies the number of transitions the
instruction has counted. |
Affects Math Status Flags
No
Major/Minor Faults
None specific to this instruction. See Common Attributes for operand-related faults.
Execution
Structured Text
Condition/State | Action Taken |
---|---|
Prescan | EnableIn and EnableOut bits are cleared to false. |
Normal execution | EnableIn and EnableOut bits are set to true. The instruction executes. |
Postscan | EnableIn and EnableOut bits are cleared to false. |
Example
Structured Text
CTUD_01.PRE := 500;
CTUD_01.Reset := Reset;
CTUD_01.CUEnable := Input;
CTUD(CTUD_01);
counter_state := CTUD_01.DN;
Provide Feedback