In RSLogix 5000, counter instructions are used to perform counting operations such as increasing, decreasing, or resetting a value based on input conditions. The three main counter instructions available are CTU (Count Up), CTD (Count Down), and CTUD (counter up down). Each instruction plays a crucial role in various automation tasks like item counting, batching, or event tracking.
This guide explains the structure, usage, parameters, and programming examples of each counter instruction in simple terms—perfect for beginners as well as experienced PLC programmers working with Allen Bradley controllers.
The CTU (Count Up) instruction is used to count events in an increasing manner. Every time the rung condition goes from false to true (rising edge), the accumulator value is incremented by 1. It is commonly used in applications like object counting, production tracking, and batch processing.
The CTD (Count Down) instruction is used to count down from a preset value. Each time the rung condition turns from false to true, the counter decreases by 1. It is useful for reverse counting applications such as countdown timers, material dispensing, or tracking remaining items.
The CTUD (Count Up/Down) instruction combines both CTU and CTD functions in one block. It allows separate inputs for count-up and count-down actions and is ideal for complex counting logic like position tracking, stock control, or cyclic operations where increments and decrements are both needed.
In RSLogix 5000, counters such as CTU, CTD, and CTUD use the DINT (Double Integer) data type for the accumulator and preset values.
The DINT data type is a 32-bit signed integer, which allows the counter to store values in the range of:
This wide range enables accurate counting in large-scale automation systems without overflow or data loss.
To use a counter instruction like CTU, CTD, or CTUD, you must first declare a counter-type tag in RSLogix 5000. Follow these simple steps:
Note: Other fields such as description, alias, and scope can be configured depending on your specific program requirements.
The Counter Up (CTU) instruction in RSLogix 5000 is used to perform incremental counting. Each time the input condition to the CTU instruction transitions from false to true (rising edge), the counter increases its accumulated value by 1.
When the accumulator value becomes equal to the preset value, the .DN (Done) bit is set to true, indicating that the counting target has been reached.
When using a CTU (Count Up) instruction in RSLogix 5000, a structured tag of type COUNTER is created. This tag includes several important fields that represent the current status and values of the counter. Below are the key components of the CTU counter structure:
Data Type: BOOL
This bit holds the rung-condition-in status when the instruction was last executed. It indicates whether the input condition triggered the count.
Data Type: BOOL
The done bit is set when the ACC (accumulated value) reaches or exceeds the PRE (preset value). It indicates that the counting operation is complete.
Data Type: BOOL
The overflow bit is set when the accumulator exceeds the upper limit of a DINT, which is +2,147,483,647.
Data Type: BOOL
This bit is set if the counter decrements below the lower limit of a DINT, which is −2,147,483,648. It is more relevant in down-counting scenarios.
Data Type: DINT
The preset is the target value that the accumulator needs to reach in order to set the done bit.
Data Type: DINT
This field stores the current count value. It increments by 1 on each valid rising edge of the input condition.
The CTU (Count Up) instruction is used to count upward whenever a rising edge (false to true transition) is detected on its enabling input condition. It is commonly used to count events like pulses, items on a conveyor, or signal changes.
The CTU instruction monitors its rung condition. When the rung transitions from false to true (rising edge), the counter becomes active and increments its accumulator value by 1.
Each valid rising edge increases the value of the .ACC (accumulator) by 1. The accumulator continues to grow with each input pulse.
The counter compares the accumulator .ACC with the preset value .PRE. When the accumulator is equal to or greater than the preset, the .DN (done) bit is set to true.
To restart the counter, a RES (Reset) instruction is used. This resets the accumulator to 0 and clears the done bit.
The CTD (Count Down) instruction in RSLogix 5000 is used to perform decrementing count operations. Each time the input condition transitions from false to true (rising edge), the accumulator value decreases by 1. It is commonly used in scenarios where countdown logic is required, such as remaining items, steps, or cycles.
When the .ACC (accumulator) value becomes equal to or less than 0, the .DN (Done) bit is set to indicate that the counting has reached completion.
To reset the CTD instruction and restart counting, you must use a RES instruction linked to the same counter tag.
In RSLogix 5000, the CTD (Count Down) instruction uses a structured tag of the COUNTER data type. This tag includes several predefined fields that monitor and control the counter’s behavior. Below is an explanation of each field used in a CTD instruction:
Data Type: BOOL
This bit reflects the rung-condition-in when the instruction was last executed. It shows whether the input condition was active (true) at the last scan.
Data Type: BOOL
This bit is cleared (false) while the counter is still counting. It is set to true when the .ACC (accumulator) value reaches 0 or less, indicating that the countdown is complete.
Data Type: BOOL
Set to true when the counter exceeds the upper limit of a DINT value, which is +2,147,483,647. This is more relevant when the accumulator is mistakenly incremented past its limit.
Data Type: BOOL
This bit is set when the accumulator value goes below the DINT minimum limit, −2,147,483,648, usually in excessive decrement operations.
Data Type: DINT
This is the starting value of the countdown. The counter decrements from this value until the accumulator reaches 0 or less.
Data Type: DINT
This field holds the current value of the counter. It decreases by 1 on each valid input transition (rising edge).
The CTD (Count Down) instruction is used to perform decrementing operations. It reduces the value of the accumulator by 1 each time the input condition transitions from false to true (rising edge). This instruction is commonly used in countdown applications like tracking remaining cycles, parts, or steps.
You must define a COUNTER tag with an initial .PRE (preset) value. This value determines the starting point for the countdown. The .ACC (accumulator) is initially set to this value.
The CTD monitors the rung condition. Each time it detects a rising edge (false to true), it decrements the .ACC value by 1.
Each valid input pulse decreases the accumulator. The current value is always stored in the .ACC field, and it continues to decrease with every rising edge.
When the .ACC value becomes less than or equal to zero, the .DN (done) bit is set to true. This indicates that the countdown process has completed.
To restart the countdown, use the RES instruction linked to the same counter tag. It resets the .ACC and .DN bits, allowing the counter to begin again from the preset value.