Back to tutorials
Beginner

PLC Programming Intermediate Instructions – CTU | Count Up

By
Vladimir Romanov
|
August 14, 2018
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

Got a question or comment?

Related Tutorials

Beginner

Opto 22 groov RIO Getting Started

The groov RIO module from Opto 22 has been released only a few months ago. The groov RIO is a feature packed piece of hardware that is easy to install, configure and deploy for many different field applications. The module comes pre-loaded with an array of software tools used across the industry and is ready to hit the floor running out of the box. Furthermore, the module is equipped with user configurable input and output nodes that have the capability unlike anything else on the market.

August 2, 2020
|
By
Vladimir Romanov
Beginner

Micro800 PLC Programming Getting Started

The Micro800 Control Systems by Rockwell Automation provide a cost effective solution for small to medium automation systems. The controllers within this family are typically used on stand alone machines or small process applications. The family offers five distinct controller types that are further customizable through add-on modules: Micro810, Micro820, Micro830, Micro850 and Micro870.Micro800 Programmable Logic Controllers Getting StartedUnlike the other Rockwell Automation controllers, this line of PLCs is programmed through a dedicated software: Connected Components Workbench. From within this tool, the programmer can flash the firmware, load the program and monitor the state of the controller. Furthermore, Connected Components Workbench (CCW) is often used to program other non-PLC Rockwell Automation devices such as Variable Frequency Drives (VFDs) and certain Safety Relays.

July 26, 2020
|
By
Vladimir Romanov
Beginner

An Introduction to DeviceNet Industrial Networks

In this tutorial you will learn about the DeviceNet industrial network, go over a basic offline configuration, and explore some advanced features.

July 24, 2020
|
By
Jacques Venter