Like most programmable logic controllers on the market, Mitsubishi has its versions of both timers and counters.
These are similar but not necessarily set up the same as the other manufacturers.
There are two critical pieces to programming each timer or counter.
The first being the label creation when inserting the function into your code. This is where the data type is selected.
The second is that you can set the global or local scope as well as if it is strictly a variable, a constant, or a retained variable class type.
With timers, there are commonly used Time ON timers (TON) and Time OFF timers (TOF).
There are versions (Data Types) of the timer functions that have an added EN (enable) added to the input to control when the time starts to lapse. These functions usually have an “_E” in the name of the function definition (TON_E).
Continuing with the variations of timers, you can add the function to your program in a couple of ways. You can just start typing TON of TOF or you can drag and drop the POU (function) from the element selection bar usually on the right of the editor.
In Mitsubishi programs, there are a few ways you can use a timer function in your programming. We will stick with the ladder and the functional block diagram formats for this article. Both styles have their pros and cons, but for the timer and counter functions, they behave very similarly.
As you can see, they have similar formats when inserted into the logic. They have the same inputs and the same format for entering the preset time.
The PT input is a TIME data type. This is important to remember. With Timers, you start with a “T#” followed by the time of preset you wish to use. After the time, you will need to designate whether the time is in seconds (S) or milliseconds (ms).
With these functions, it is strictly preference but perhaps ease of integration, if you are adding logic to an existing program or selecting a preferred style of logic in a new project.
If declaring a Timer and you realize you need a large time preset, using the TIME data type for the preset on the Timer gives you the range up to a 32-bit unsigned value. The value, 0 to 2,147,483,647, is still limited to lower than the true 32-bit maximum due to the TIME data type and how it is structured in the PLC firmware.
This is one of those instances that the data type limits the value to less than the actual numeric data type. Like many other things in Mitsubishi, you can modify the setting of the long-timer value by using the engineering tool.
For example, if the setting is 0.001ms, then the preset range will be from T#1ms to T#2147483ms. If the timer setting value is at 1000ms the preset range will go up to T#1000ms to T#2147483000ms.
Just as preferences differ from programmer to programmer and even from project to project, so do the ways to use, isolate, and manipulate timers and counters.
As shown here, you can even stage the timers and counters by using the Q output to trigger a coil and the input (or enable) of another function.
One simple example of something I do frequently is set a timer to trigger a SET function. This is particularly handy when latching an alarm or warning bit that you feel should require a definite manual reset.
Now we have come this far without so much as an example of the counter functions.
In the Mitsubishi GX Works 3, you have the UDCNT function available in the ladder and the FBD programming structure.
On the ladder-style, you can see that the rung from the power rail is the same as the EN input on the FBD style block.
While the X0 is in the S1 blank and the K3, in these examples, is a constant entered for the counter preset.
The symbol used at S1 should be a Boolean type and declared as something that can be an array of two. The  position of the array is the pulse increment/decrement while the  position of the array sets the direction of the counter.
In these examples, every pulse to the S1 (rising edge of X0) will increase the count value by 1. If the value reaches 3 (or whatever is set at S2), the output will go high.
In this case, the ladder could use an N.O. contact of a C0 transition from 0 to 1 and the FBD style will turn on the COUNT_DONE coil.
One other item to remember, if the value at the array X1 goes high, the pulses seen at S1 will cause the count register to decrement.
So, it is a very simple function block that is two functions in one. How efficient!
Written by Paul Hunt
Senior Automation Engineer and Freelance Writer
Sponsor and Advertise: Get your product or service in front of our 75K followers while also supporting independent automation journalism by sponsoring or advertising with us! Learn more in our Media Guide here, or contact us using this form.
- Mitsubishi PLCs: Brief History and Hardware Overview - August 2, 2022
- Mitsubishi PLCs: FX5 vs iQ-R - February 10, 2022
- How To Register and Use a Device Profile in GX Works3 - November 9, 2021