TON .ACC seconds to hours/minutes/seconds

JZerb

Member
Join Date
Oct 2016
Location
Here
Posts
423
so i have a program where i have operator input on the HMI for hours, minutes, seconds for a given cycle time. i wanted to have a bar graph/shape with a fill animation on the HMI for the total elapsed cycle time as well as a numeric countdown on screen for how much time is left in the cycle, so i decided to take the hours, minutes, seconds inputs from the HMI....which all have their own integer data files...and use MUL, ADD and MOV instructions to get the overall .PRE seconds for the Cycle Timer. all of that math works out well, my issue is where i need to take the .ACC timer value, subtract it from the .PRE timer value and then break it up into the remaining hours, minutes, and seconds. any advice is appreciated. Micrologix 1400 is the PLC in use here.
 
First off, if your hours counter is based on one timer in a Micrologix with a 1 second time-base, the preset can't be for more than about 9.1 hours. If this cycle time entry is limited to less than that, then let's move on...

Just use the ACC of the timer as your fill animation driver. You should be able to fill from top or from the bottom depending on whether you want the animation to look full or empty at the beginning when the ACC is low. Doing this means that the range of the filled object must be dynamic. If this isn't possible, then make it a float and divide the ACC by the PRE to get "percent" complete in the form of 0.0 to 1.0. You could do that division in the HMI or the PLC with a separate tag.

Making the value of remaining (or elapsed) seconds appear as HH:MM:SS is a little more work if you need that too. You can use the modulus function to find the remainder where the divisor is 60. Example: there are 365 seconds remaining (or elapsed) 365 MOD 60 = 5, so the seconds value displayed will be 5. Set up that field on the display for two digits with leading zeros. Use regular division and round down to get the whole minutes left. Take that result (whole minutes) and MOD 60 to get minutes up to an hour field populated. Divide the whole minutes left (or elapsed) by 60 and round down to get the number of whole hours...
 
Last edited:
First off, if your hours counter is based on one timer in a Micrologix with a 1 second time-base, the preset can't be for more than about 9.1 hours. If this cycle time entry is limited to less than that, then let's move on...

the customer will most likely not run the cycle for more then 20-30 minutes, its just that with the outlines of the project requirements that i was given from customer they have H:M:S in what they desire to be able to set so im just covering all of my bases

Just use the ACC of the timer as your fill animation driver. You should be able to fill from top or from the bottom depending on whether you want the animation to look full or empty at the beginning when the ACC is low. Doing this means that the range of the filled object must be dynamic. If this isn't possible, then make it a float and divide the ACC by the PRE to get "percent" complete in the form of 0.0 to 1.0. You could do that division in the HMI or the PLC with a separate tag.

i have not worked with the fill animation or bar graph on the PVP but my plan was to do the former of what you said. i was looking at the bar graph and planned on just tying the .ACC of the timer to an SCP that had a scaled out of 0-100 and then pointing the output of that SCP to the Value tag on the bar graph. really i just need a bar to grow across the screen thats tied to the cycle timers .acc, so at quick glance you can see how far along in the process you are.

Making the value of remaining (or elapsed) seconds appear as HH:MM:SS is a little more work if you need that too. You can use the modulus function to find the remainder where the divisor is 60. Example: there are 365 seconds remaining (or elapsed) 365 MOD 60 = 5, so the seconds value displayed will be 5. Set up that field on the display for two digits with leading zeros. Use regular division and round down to get the whole minutes left. Take that result (whole minutes) and MOD 60 to get minutes up to an hour field populated. Divide the whole minutes left (or elapsed) by 60 and round down to get the number of whole hours...

I havent ever used this modulus function that you mention, i will look into that because it sounds like that will be a good solution. where i got jammed up was i originally had separate timers for the H:M:S and they would just have a CTU attached to the .DN bits of their respective timers and the logic would just execute down the line one timer after the other. issue with that was i didnt have an easy way to get an OVERALL timer remaining value to attach to the graph im looking to place on the HMI.
 
I would not use a timer at all.


I would create an STI routine, preset to execute once per second, anduse counters to countseconds, 0-59, count minutes, 0-59, and hours, 0-23. You can extend this to days, weeks, years etc. if you had to.



The counter .ACC values are what you put on your HMI, not calculated values
 
I would not use a timer at all.


I would create an STI routine, preset to execute once per second, anduse counters to countseconds, 0-59, count minutes, 0-59, and hours, 0-23. You can extend this to days, weeks, years etc. if you had to.



The counter .ACC values are what you put on your HMI, not calculated values

Ive never worked with an STI before, but from what i can gather in the Micrologix 1400s its just a standard subroutine in its creation. then in S:31 i would enter the number of said subroutine and in S:30 i would enter when that STI scans?

when i spoke with someone else about this dilemma they recommended me to do just as you said, use the .ACC values of some counters to determine the remaining timer time thats left. they actually said to just try and subtract 60 from the .ACC value and then each time i was able to SUB 60 use a CTU and that CTU .ACC would determine my leftover minutes, once i couldnt get 60 from the leftover number with a SUB instruction then that remaining time would be my leftover seconds. my issue is that what i had thought in my head would work did not. i will play with it a bit tonight and just test out and see what i get on my test PLC i have.
 
STI: More accurate, less obvious to the reader, eliminates having to create complex expressions in the PV+ or extra PLC code.

Simple Timer with HMI expressions; Easier to understand for unfamiliar readers, easy enough to implement in some HMI applications.

Since you're dealing with a PV+, I would probably use the STI method or regular ladder logic to do the math.

You do not want to use a JSR instruction to call the STI routine, however, I will sometimes put one in the main ladder file and make it always false so that I can comment it and explain what is in it. Name it STI too so that it is clear that is what the ladder file is purposed for.

I don't have software handy right now, but yes, you put in the file number and the number of milliseconds between executions. I believe this is all part of an STI Function file (which probably is a structured view of those same system address you have mentioned). I believe you also need to turn on an enable bit which can be done with ladder logic or just by toggling the bit...I tend to always put in ladder logic to drive any special system bits so that they're guaranteed to be in the state I want and searchable in the program.
 
so, i got my bar graph setup on the HMI to work with the SCP instruction as i hoped it would.

but my timer remaining logic still doesnt work. i just ended up writing a bunch more logic that took the original input from the HMI into N7 files, made that up into three separate timers for Hours:Minutes:Seconds, with CTU instructions on the output side of each of those timers DN bits, then was able to keep track of the time remaining on each subsequent Timer/Counter that way, not ideal but it works for the time being.
 
i just wanted to put in here what i ended up doing to accomplish what i wanted in the end. after searching a few more older posts i came across a suggestion of using the S:13 and S:14 Math Registers in the ML1400, so i read the manual on that specific function and its use while DIV and came up with this logic, which seems to be working just fine.

SUB T4:1.Pre
T4:1.ACC
N10:0

DIV N10:0
60
S:13

MOV S:13
N10:12 (seconds remaining)

DIV S:14
60
S:13

MOV S:13
N10:11 (Min remaining)

MOV S:14
N10:10 (Hours remaining)

havent faulted the PLC yet, so i assume its going to workout for me in the long run. just wanted to share in case others in the future are looking for a method to accomplish something like this.
 

Similar Topics

I am using RSLogix Emulate 5000 to test my program. There are several timers in my application. Whenever I run my program, ACC in one of the TON...
Replies
6
Views
4,550
Hello, I'm using FactoryTalk View ME V10. I created a valve as a global object with multiple parameters and when the object is being used at the...
Replies
2
Views
121
Hi, I'm quite new to Rockwell PLC and currently trying to implement the following if Sw1 then for i:=1 to 20 by 1 do xEnable := 1...
Replies
9
Views
357
FactoryTalk View ME running on PanelView Plus 7, connected to Compact GuardLogix 5380 PLC Customer is asking for a physical push button to be...
Replies
6
Views
181
Hi everyone Is it possible to change a button image in FactoryTalk View SE (v13.00) using VBA?
Replies
0
Views
80
Back
Top Bottom