Seconds since 8am - best way to do this?

rollex

Member
Join Date
Mar 2014
Location
Australia
Posts
55
I have created a task that executes every 10ms, it uses a GSV to determine the time and set a flag once 8am has occurred. I use a periodic task to not flood the CPU with GSV commands more often than I need to.

9bVrVvZ.png


In another routine I then run a timer and count the number of seconds, when this flag is true I reset my counter.

YzWCjbU.png


Is this the best way to do this? Will this be reasonably accurate over the course of a day? Obviously if they change their clock it will break the routine but I'm not fussed by that at the moment.
 
Last edited:
Why not just compute how long it ha been since 0800 from your localdatetime udt tag?
I imagine that a timer resetting every second is not going to give you great accuracy.
It will end up quite a bit slower than it should be over a whole 24hours.
 
I guess because of the roll over at 12:00 it seemed like it would be a pain in the ***. But you are right, it will be more accurate.

edit: Actually it is pretty easy to do, I'll just do that.
 
Last edited:
I think you may have a discontinuity in your equation. In the less than 8 case you want to add 16 to the hour, not 8. 23:59 - 8 is 15:59.

Keith
 
Periodic task with a 1000 ms interval.
ADD SecsSince0800 1 SecsSince0800

In your main or continuous task, check for the time to pass 0800 and oneshot CLR SecsSince0800.

There are a ton of other ways, you could probably just count milliseconds with a single timer that resets at 8 a.m. and DIV the ACC by 1000. I just woke up so I am not sure how many milliseconds there are in a day and if that fits in a DINT...coffee...coffee...

86,400,000 milliseconds in a 24 hour period. That will fit in a DINT (-/+ 2.14 billion). KISS.
 
Last edited:
Each time you reset a timer, you stand to lose a few microseconds. Don't reset your timer any more often than absolutely necessary. Time does not stop ticking while the CPU goes out and wipes away what it had stored, and once the timer is DN, you can be sure a few microseconds up to a few milliseconds have passed you by. Resetting the timer will erase that timer overrun from your intended accumulation over a long period.

If you want to keep your existing work and the one second timer, rather than RESet it, when the acc >= 1000, subtract 1000 from the accumulator and let it keep rolling. At the same time, fire off a oneshot to act as the "DN" bit. Then set the preset to a number it will never reach and let it roll on...

Different platform, but the same principles apply unless there is some magic in Controllogix that circumvents scan time...
http://www.plctalk.net/qanda/showthread.php?t=87079&highlight=timer+overrun
 
Last edited:
Periodic task with a 1000 ms interval.
ADD SecsSince0800 1 SecsSince0800

In your main or continuous task, check for the time to pass 0800 and oneshot CLR SecsSince0800.

Why not reset the SecsSince0800 at 08:00:00 in the 1000mS periodic task, you only need to to check the Hour and use a oneshot.

GSV WallClockTime LocalDateTime LocaDateTime.Year
ADD SecsSince0800 1 SecsSince0800
EQU Hour 8 ONS Oneshot CLR SecsSince0800

There's no need for a faster GSV than 1 Second, since the WallClock Seconds anly changes once a second...
 
Last edited:
Why not reset the SecsSince0800 at 08:00:00 in the 1000mS periodic task, you only need to to check the Hour and use a oneshot.

GSV WallClockTime LocalDateTime LocaDateTime.Year
ADD SecsSince0800 1 SecsSince0800
EQU Hour 8 ONS Oneshot CLR SecsSince0800

There's no need for a faster GSV than 1 Second, since the WallClock Seconds anly changes once a second...

(y)
 

Similar Topics

I have 8 of these systems all running the same code. Just this one seem to gain about 30 seconds in time everyday. So in 48hrs time will be...
Replies
3
Views
656
Hi all, I am working with an IO link sensor (measuring current across motor)and need to read in and store the sensor values for 5 seconds, then...
Replies
13
Views
1,209
Hi, I have a bit of PLC experience in Siemens and have unfortunately been blessed with working on Automation Studio and B&R which has been a big...
Replies
5
Views
1,364
I am using a Rockwell control logic L63 processor. For communicating with an encoder I started migrating from SST module to Prosoft MVI56-PDPMV1...
Replies
1
Views
551
Guys, so I have doing cicode function, to execute excel file, the the values from the excel and extract it to the tags. The problem is, I dont...
Replies
4
Views
1,040
Back
Top Bottom