Technical Article

Understanding PLC Program Commands: Timers

May 31, 2022 by Jon Peterson

The timer is a fundamental function of ladder logic programming. In this article, we discuss on- and off-delay as well as retentive timers and define the inputs and outputs required to properly use them.

Timers are used in virtually all PLC programs out in the world of industry. A couple of example applications in which I have used them personally are oiler systems for motor arbor shafts, messaging system schedules, photo-eye debounces, and there are a good deal of others. The timer is a fundamental function and critical component for any programmer to understand. We will address ladder logic timers from the primary perspective of Rockwell Automation’s Studio 5000. At the end, I will also give a brief description of expectations for other PLC platforms that may look a little different.

Before we proceed, let me give a quick definition of some terms that might not be known by all readers. If you don’t know these terms, check out some articles on Control.com regarding data types used in PLC programming.

  • Boolean (also called BOOL) - The name of a data type that can either be true or false, 1 or 0, off or on. A BOOL only two states.
  • Double Integer (also called DINT or Double Word) - The name of a data type that uses 32 individual BOOLs to create a very large decimal number that people can easily understand and utilize. DINTs let us count, absolutely critical for timers.
  • True - This is a statement expressing a logical circuit is complete. It’s like a switch that has been closed, providing power to the device.
  • False - This is a statement expressing a logical circuit is incomplete. Imagine turning a light switch off. You flip it off and the circuit goes “false”.
  • In the following text, ‘True’ and ‘False’, as well as the tag names, will be listed with capitalized spelling for emphasis and clarity of reading.

Understanding Timer Data

We will start our discussion of timers with Rockwell’s Studio 5000 Logix Designer. Studio 5000 uses three different types of timers: Timer-On-Delay (TON), Timer-Off-Delay (TOF), and Retentive-Timer-On-Delay (RTO). All three of these instructions use a common data type structure simply called TIMER in the Studio 5000 program.

As shown in Figure 1 below, the TIMER Data Type consists of five individual tags:

  • Enable BOOL (EN)
  • Timer Timing BOOL (TT)
  • Done BOOL (DN)
  • Preset DINT (PRE)
  • Accumulated DINT (ACC)
 
PLC Timer Tags
Figure 1. Tags contained within a ‘TIMER’ data type. All images courtesy of the author.

 

The Enable bit is True whenever the timer instruction is active, no matter how much time has elapsed. The Timer Timing bit is True when the timer is actively performing the timing operation. The Done bit goes TRUE when the timer has counted up to reach its Preset. The Preset is an input that allows the user to ‘set the timer’ for how long it lasts before completion. Finally, the Accumulated number shows the user how high it is in its current count.

Another function that is important to note is what is called time base. The time base refers to the units that are counted as a timer counts up. In Studio 5000, we always count in milliseconds. There is no other option. Other programs might allow you to change your time base. In Productivity Suite (by Automation Direct), you can choose milliseconds, seconds, minutes, or hours. In RSLogix500 you can choose from 100ths, 10ths, or 1 second time bases.

Each instruction we will discuss uses each of these bits in different ways to create different results that you can use in your programs.

Timer-On-Delay (TON)

The TON instruction is likely to be the one you will see the most. Its function is very simple. When the rung powering this timer is True, it begins counting up in millisecond intervals.

 

TON Example

Figure 2. TON instruction example

 

In the logic in Figure 2, you can see the TON instruction. Because I am using a Normally Closed (also called Examine If Open or XIO) Instruction in front of it, the timer begins counting up whenever the timer is NOT Done. When it counts up all the way up to 5 seconds, the timer enables the Done bit. On the very next scan of the program, since the timer is activated when the timer is NOT done, the PLC will immediately shut off the timer, reset it, and trigger the Arbor1Oiler system for one brief pulse. On the next scan, the Done bit will be switched off and the timer begins to count up to 5000 again. In other logic, the timer may be turned on by a temperature sensor or a push button. The trigger and reset are determined by how your program needs to function.

The TON instruction begins counting up when the rung is True, triggers the Done bit when the Preset is reached, and resets the count to zero when the rung goes False.

Timer-Off-Delay (TOF)

The Timer-Off-Delay instruction is not as common as the On-Delay, but is applicable in many special cases where a load must be kept running for a short time after a machine turns off. Surprisingly, and often confusingly, this timer’s Done bit becomes True as soon as the rung goes True and it holds the Done bit until the timer has finished counting. The timer begins counting when its rung goes False.

This is especially useful when you need to maintain something running for a while after an event takes place. An example of this might be if a motor shuts off, but you need to hold its cooling system on for 4 seconds after it shuts down.

 

TOF Example

Figure 3. TOF instruction example.

 

In the logic in Figure 3, you can see the TOF instruction. When MotorRunning goes True, the Done bit enables and turns on CoolingSystem. When MotorRunning goes False, the Done bit stays True until 4000 more milliseconds have passed with the cooling system running. That’s when the Done bit drops out and CoolingSystem turns off.

In review, the TOF instruction sets its Done bit to True when the rung goes True and begins counting up when the rung is False. Only after the rung has gone False for the preset duration will it drop out the Done bit. This timer auto-resets after it reaches its Preset.

Retentive Timer-On-Delay (RTO)

The Retentive Timer-On-Delay breaks away from the style of the other two timers in Studio 5000. The RTO counts when the rung is True but it does not reset when the rung goes False. It retains whatever counts it has accumulated. An easy way to visualize where this could be used is if a machine needs to be serviced every 100 hours of run time. You want the timer to accrue value when running, stop accruing when not running, but retain the count so that a notification can be displayed when the service interval has been reached.

 

PLC RTO

Figure 4. Retentive timer instruction.

 

In the logic in Figure 4, the RTO is laid out just like in the previous two examples. When the motor is running, the rung is true and we are counting. When the motor stops running, the counts are held while it waits for the next time the rung goes True. When the counts reach the preset, the Done bit goes True.

The RTO instruction begins counting when its rung goes True. It does not reset the counts when the rung goes False. It triggers the Done bit when the accumulated counts reach the preset.

Reset (RES) Instruction

Our discussion of the RTO style timer demands our need to address an instruction that can be used in a multitude of places and capacities in Studio 5000. The Reset instruction can be used to reset the counts of ANY style of timer no matter where it is in its counting cycle. When the Reset is triggered, it resets the counts of its associated timer to zero. To associate the Reset with the timer you want, simply place the timer’s tag name into the tag of the instruction.

In this line of logic, you can see I have set up a Reset to be triggered when a user hits a button to tell the PLC that the service is complete for our RTO example above.

 

PLC Reset

Figure 5. Reset instruction for timers.

 

A reset instruction will take any timer and set its accumulated value back to zero. It also can be used to reset the value of a counter to zero, but that is better left to a different article scope.

Timers Across Other Platforms

Despite the simplicity of timers, it is worth noting that there can be a wide range of differences between how a timer looks in Studio 5000 as opposed to another platform. In the following figure, you can see the timer structure used in TIA Portal from a Siemens PLC system. We have a rung entering the input of the instruction (IN) just like the Enable bit, a Preset Time (PT), an Elapsed Time (ET) which is equatable to the ACC, and finally a Q which represents the Output. The Q is comparable to Studio 5000’s Done bit.

In this instruction, the Timer Timing (TT) does not exist but can be formed with a simple series of IN being true, and Q being false.

 

TIA Portal TON

Figure 6. TON from Siemen’s STEP 7 TIA Portal software.

 

Another example is Automation Direct’s Productivity Suite, the main timer for which is pictured below.

Productivity combines a lot of functionality into their single Timer instruction. It is inherently a retentive timer like the RTO, but you can choose to auto-reset as well as monitor when the current time is less than, equal to, or greater than the preset in the menu. It also has 3 rung inputs, one counts up, another counts down, and another resets. Automation Direct does this with many instructions, combining functionality so one instruction can perform a myriad of tasks.

 

Productivity Suite Timer

Figure 7. Timer from Automation Direct’s Productivity Suite.

 

Automation Direct also has a Simple Timer that works like a TON or TOF instruction. Just like the others, you must set the preset. Both of these timers are examples of time bases that can be changed to fit your needs, note in the previous figure listing the time base in ‘sec’ for seconds.

Summary

There are a ton of interesting versions and uses of timers in the world of industry - from timer relays to PLC timers, to integrated circuitry timers. I hope this has shed some light on the use of timers across various software platforms and applications.

Featured image used courtesy of Canva
1 Comment
  • pnachtwey June 03, 2022

    The problem with “timers” is that they really aren’t “timers”.  They are delays.  This is indicated many times above.  If you put a 10 ms time preset in a PLC program and count how long it takes for the timer to time out 1000 times,  The time will be over 10 seconds.  Timed interrupts are better for better timing because 1000 timed interrupts will take verly close to 10 seconds but any error will not accumulate over time.  Timed interrupts are still prevented from triggering at exactly the time interval because sometimes the PLC goes into an “overhead” phase where interrupts are turned off.

    Like. Reply