Back to tutorials
Beginner

PLC Programming Intermediate Instructions – CTD | Count Down

By
Vladimir Romanov
|
August 15, 2018
Table of Contents

Introduction

The CTD, also known as the Count Down, instruction is used to decrement the value of the counter associated with it. This instruction will detect a FALSE to TRUE transition of the logic leading to it and decrease the “Accum” value of the counter by 1. The effect of using this instruction is the exact opposite of what the CTU Instruction does to the counter. Just like its counterpart, this instruction will be found in a rung which will count a certain number of events. Due to the fact that it decrements the value, the use cases need to be very specific in order to be clear to the next programmer.

You can use the CTD instruction for every single application of the CTU instruction. In other words, it is just a matter of preference. That being said, an experienced programmer will allow the program to flow naturally; using the instruction as it would make sense in the real world. The most basic example which comes to mind would be a start countdown where the values need to decrement from 10 down to 0.

Example & Usage of CTD

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

  1. A Micrologix 1100 Allen Bradley PLC is used to control a process.
  2. A “High Level Alarm” is indicated by an internal bit B3:0/15.
  3. A CTD instruction is tied to Counter C5:2.
  4. The Counter C5:2 has a “Preset” of -5. The number 5 represents the maximum number of times the alarm can be triggered before requiring an acknowledgment from the operator.
  5. When the bit B3:0/15 goes HIGH, the CTD instruction is energized and the counter decrements the “Preset” value.
  6. When the bit B3:0/15 goes LOW, followed by HIGH, the CTD instruction is energized and the counter decrements again.
  7. The counter will continue to increment until “Accum” = -5.
  8. When “Accum” of C5:2 Counter is equal to -5, the C5:2.DN bit is HIGH.
  9. The C5:2.DN bit is used to set an internal bit B3:1/0.
  10. The B3:1/0 bit is left HIGH until a button tied to the bit B3:1/1 is set to HIGH. This action allows the Counter to reset and resume the process.

Programming example in RSLogix 500:

CTD Count Down Instruction RSLogix 5000 2

Outcome:

The CTD instruction is tied to an internal bit B3:0/15 which represents a certain alarm within the process. As the alarm is energized, the counter will decrement the value by 1. After 5 distinct alarms, the counter will reach the limit which is set at -5. Once the limit is reached, the counter will automatically set the .DN bit. This .DN bit will set a bit which represents that the process has reached an alarm threshold.

The threshold will be set HIGH until the .DN bit is energized. The only way to reset this bit is to reset the Counter. Doing so is possible through the use of the RES Instruction which will set the “Accum” value of the counter back to 0 and the .DN bit to LOW.

Data Types Allowed for CTD

The CTD 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 CTD 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 CTD 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

PLC Programming Example Project - Batching Tank Ladder Logic PLC and HMI Tutorial

Generally speaking, there are two types of processes in manufacturing: discrete and analog. A discrete process is a manufacturing methodology that will produce separate widgets. In other words, a production line may output one item, two items, three items, etc. An analog production process is where the plant will create a quantity of product that is quantifiable by weight. Examples include the production of beverages, sauces, raw ingredients, etc. Although it is possible to design a flow that will continuously output the product, such production is often managed in batches. It is important to note that although batches are considered to be analog or continuous flow, most of them end up being packaged for consumption which converts them into a discrete manufacturing process.

September 14, 2020
|
By
Vladimir Romanov
PLC Programming Career

PLC Programming Certification - Complete Guide

You may choose to pursue a traditional college degree, learn through online tutorials, or take a course that will issue a plc programming certification upon completion. However, what is the best option, and what are the best PLC programming certifications?

August 6, 2020
|
By
Vladimir Romanov
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