Count Up/Down (CTUD)

This information applies to the
CompactLogix
5370,
ControlLogix
5570,
Compact GuardLogix
5370,
GuardLogix
5570,
Compact GuardLogix
5380,
CompactLogix
5380,
CompactLogix
5480,
ControlLogix
5580, and
GuardLogix
5580 controllers.
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.
Available Languages
Ladder Diagram
This instruction is not available in ladder diagram.
Function Block
Structured Text
CTUD(CTUD_tag)
Operands
Structured Text
Variable
Type
Format
Description
CTUD tag
FBD_COUNTER
Structure
CTUD structure
See Structured Text Syntax for more information on the syntax of expressions within structured text.
Function Block
Operand
Type
Format
Description
CTUD tag
FBD_COUNTER
Structure
CTUD structure
FBD_COUNTER Structure
Input Parameter
Data Type
Description
EnableIn
BOOL
If cleared, the instruction does not execute and outputs are not updated. If set, the instruction executes.
Default is set.
CUEnable
BOOL
Enable up count. When input toggles from clear to set, accumulator counts up by one.
Default is cleared
CDEnable
BOOL
Enable down count. When input toggles from clear to set, accumulator counts down by one.
Default is cleared
PRE
DINT
Counter preset value. This is the value the accumulated value must reach before DN is set.
Valid = any integer
Default is 0
Reset
BOOL
Request to reset the timer. When set, the counter resets.
Default is cleared
Output Parameter
Data Type
Description
EnableOut
BOOL
The instruction produced a valid result.
ACC
DINT
Accumulated value.
CU
BOOL
Count up enabled.
CD
BOOL
Count down enabled.
DN
BOOL
Counting done. Set when accumulated value is greater than or equal to preset.
OV
BOOL
Counter overflow. Indicates the counter exceeded the upper limit of 2,147,483,647. The counter then rolls over to -2,147,483,648 and begins counting down again.
UN
BOOL
Counter underflow. Indicates the counter exceeded the lower limit of -2,147,483,648. The counter then rolls over to 2,147,483,647 and begins counting down again.
Description
When true and CUEnable is true, the CTUD instructions 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.
Affects Math Status Flags
No
Major/Minor Faults
None specific to this instruction. See for operand-related faults.
Execution
Function Block
Condition/State
Action Taken
Prescan
EnableIn and EnableOut bits are cleared to false.
Tag.EnableIn is false
EnableIn and EnableOut bits are cleared to false. Initialize data to require a "zero to one" transition of CuEnable or CdEnable to effect ACC.
Tag.EnableIn is true
EnableIn and EnableOut bits are set to true.
The instruction executes.
Instruction first run
Initialize data to require a "zero to one" transition of CuEnable or CdEnable to effect ACC.
Instruction first scan
Initialize data to require a "zero to one" transition of CuEnable or CdEnable to effect ACC.
Postscan
EnableIn and EnableOut bits are cleared to false.
Structured Text
Condition/State
Action Taken
Prescan
See Prescan in the Function Block table.
Normal execution
See Tag.EnableIn is true in the Function Block table.
Postscan
See Postscan in the Function Block table.
Example
Function Block
Structured Text
CTUD_01.PRE := 500;
CTUD_01.Reset := Reset;
CTUD_01.CUEnable := Input;
CTUD(CTUD_01);
counter_state := CTUD_01.DN;
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.