Tutorials /
PLC Programming Intermediate Instructions – CTU | Count Up
Beginner

# PLC Programming Intermediate Instructions – CTU | Count Up

PLC Programming
RSLogix 500
RSLogix 5000
Studio 5000

### Introduction

The CTU, also known as the Count Up, instruction is used in pair with a Counter construct to count the number of LOW to HIGH transitions of the preceding logic. The CTU instruction will increment the “Accum” value each time the logic which leads into it is set to TRUE. Unline the Timer Instruction, the CTU will not keep incrementing until the rung is set to LOW and comes back to being HIGH. This critical element of ladder logic programming allows a programmer to keep track of how many products have passed a certain sensor, how many revolutions have been made by a certain motor, how many times a certain alarm was set and so on. It’s a widely used instruction which is extremely versatile and easy to work with.

The CTU instruction must be paired with a way to reset the counter through a RES Instruction.

## Example & Usage of CTU

Here’s a real-world scenario of a CTU instruction:

1. A Micrologix 1100 Allen Bradley PLC is used to control a process.
2. A “Product PROC Sensor ON” is indicated by an internal bit B3:0/13.
3. A CTU instruction is tied to Counter C5:0.
4. The Counter C5:0 has a “Preset” of 16. The number 16 represents the number of products in a certain batch.
5. When the bit B3:0/13 goes HIGH, the CTU instruction is energized and the counter increments the “Preset” value.
6. When the bit B3:0/16 goes LOW, followed by HIGH, the CTU instruction is energized and the counter increments again.
7. The counter will continue to increment until “Accum” = 16.
8. When “Accum” of C5:0 Counter is equal to 16, the C5:0.DN bit is HIGH.
9. The C5:0.DN bit is used to set an internal bit B3:0/14.
10. The B3:0/14 bit is used to energize C5:1. This Counter counts how many batches have been completed.
11. The B3:0/14 bit is also used to RES (Reset) the C5:0 Counter.

Programming example in RSLogix 500:

Outcome:

The CTU instruction is tied to the XIC which is energized by a proximity switch. This switch detects a certain product when it comes by on a conveyor belt. As soon as the switch detects the product, it energizes the CTU and increments the “Accum” value. This value will continue to increment every single time a new product goes by. The process will continue until the counter has reached the value of 16.

At 16, the counter will set the C5:0.DN bit because “Accum” == “Preset”. At this point, the .DN bit will set an internal bit which will energize another CTU instruction. This instruction will keep track of the batches finalized in the process. Furthermore, the .DN bit will also trigger the RES instruction which will set the “Accum” of C5:0 Counter back to 0.

The process will repeat again for each batch. Note that the counter which keeps track of the number of batches produced does not have a reset. This will need to be implemented and tied into a button which is activated at the end of a shift for example.

## Data Types Allowed for CTU

The CTU leverages a specific data structure, called the Counter, present in most PLC systems.

• Counter – The high-level instruction specification of all the inner structures.
• .PRE – Integer specifying up to which value the timer will count.
• .ACC – Integer specifying the current time value of the timer.
• .CU – Boolean value which is set to HIGH when the counter is energized to count up.
• .CD – Boolean value which is set to HIGH when the counter is energized to count down.
• .DN – Boolean value which is set to HIGH when the timer is finished counting.
• .OV – Boolean value which is set to HIGH when the counter is overflown.
• Note: The overflow status signifies that the counter has reached the logical limit of 32767 and had to wrap back to the value of -32768.