Back to tutorials
Beginner

PLC Programming Intermediate Instructions – CTU | Count Up

By
Vladimir Romanov
Table of Contents

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:

CTU Instruction RSLogix 500 Demo

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.
  • Note2: To avoid overloading the counter, make sure to program proper measures into your software.
  • .UN – Boolean value which is set to HIGH when the counter is underflown.
  • Note: The underflow status signifies that the counter has reached the logical limit of -32768 and had to wrap back to the value of 32767.
  • Note2: To avoid overloading the counter, make sure to program proper measures into your software.

Important Notes

  • Note 1 – The CTU instruction uses a counter which is specified internally to the PLC. The user may choose to set the values covered above through the PLC interface instead of working with them in the instruction. Furthermore, the CTU instruction will not display the current set of all the bits discussed above; they will be set on the PLC only.
  • Note 2 – Counter may overload and cause the PLC to shut-down into a fault state. To prevent this from happening, you must monitor your counters and reset them appropriately. You can easily create a “trap” which would reset each counter as it reached the limit.
  • Note 3 – Each counter must be unique to a CTU/CTD instruction. Using the same counter in multiple locations may cause performance issues. Avoid doing so by leveraging a single CTU or CTD instruction for a different set of conditions.

Video Tutorial

Back to tutorials

Related Tutorials

Intermediate

MicroLogix 1100 RSLogix 500 External IO PLC Programming Tutorial

The MicroLogix 1100 PLC is still heavily used in the industry and is one of the most recommended PLCs for learning PLC programming. The MicroLogix 1100 PLC is compact, offers a variety of I/O configurations and is inexpensive relative to other Rockwell options. Furthermore, the MicroLogix 1100 PLC is programmable using the free version of RSLogix 500 that can be downloaded from the official Rockwell website.

By
Vladimir Romanov
Beginner

PLC Simulator - PLC Programming & Testing within a Simulated Environment

A PLC Simulator is an excellent avenue to practice PLC ladder logic programming. Although the software environment is not the perfect substitute for hands on experience on an actual PLC, the simulation delivers a very accurate representation of ladder logic execution.

By
Vladimir Romanov
Intermediate

HMI Software - Different Tools, Applications and Solutions to Meet Your Needs

HMI Software is commonly referred to as the development application that will be used to create the runtime application for an HMI terminal. It’s important to understand this distinction as we will be going over the HMI development environments used by PLC and HMI programmers to create the screens rather than the end-user applications you will see at the plant level.Numerous HMI programming software solutions are found on the market. Although they aim to achieve the same result, different packages have a distinct advantage over others in terms of price, reliability, ease-of-use and technical capability. It is therefore possible to find the right solution that will fit your specific application if you spend the time to research all options.

By
Vladimir Romanov