24 hour timer

DonW42

Member
Join Date
Dec 2011
Location
Oregon
Posts
8
I am using a CompactLogix. I need to know whether it has been at least 24 hours since a certain event happened. I want to use the wallclock so the timer keeps going if the power was out overnight or if the program gets downloaded again for some reason. Using year/month/day/hour gets complicated because it may be a few hours or a few years between events. Using the raw microseconds timestamp seems like the obvious choice, but it gets complicated because of the LINT (2 DINTS). If I could do simple math on a LINT I could just look for a difference of 60,000,000 or more in the timestamp. Does anyone know of a simple way to subtract LINTs?
 
You could use the CPT function to calculate a DINT called , say Time_Now ( Muliply hours x 60 + min from GSV ) . When the event occurs Latch it as , say , EventOccured, store the value of Time_Now as Time_Event and also store Day as Day_Event . Use a rung with the EventOccured bit AND NEQ Day Now with Day_Event AND EQU Time_Now with Time_Event . Set a latch for EventPlus24Hrs and unlatch the EventOccured bit .

You could even calcute to seconds in a Dint if you want more accuracy .

Paul
 
Paul,
Thanks for the reply. Just to clarify, when you said "Muliply hours x 60" Do you mean from the DINT array where you have years, months, days, hours etc.? If so, that hours value only goes from 0 to 23 and then rolls over. If the last event was 26 hours ago, it would calculate as 2 x 60. As I said before this could potentially go years without triggering.

Keep those ideas coming!

Thanks,
Don
 
To hopefully clarify , I am suggesting you convert the hours from GSV to minutes and and add the GSV value of minutes ie at 10:30AM you have a value of 630 minutes . Should the event occur at this time you store this value as the event time and also store the day number from the GSV . Set ( latch ) a bit to record Event occured . Keep computing the current time in minutes .
On the following rung , use the event has occured bit to enable the rung . The next instruction is NEQ day number from GSV and day number of the event . The rung will only go true on the following day ( The day number increments at the same time as the hours go to zero ). The next instruction compares the time computed in minutes from the GSV with the stored time in minutes . When these values become equal , the time will be 10:30 on the following day . The output of this rung Sets a bit to say 24hrs have passed and unlatches the event occured bit .

I appologise for not showing the actual rung , but I only subscribe to the forum at home not allowed internet at work for security and don't have a copy of RS LOgix 5000 at home .

Paul
 
Why not just use the wallclock store the time for the event and on the next event subtract the stored record and if it over 24 hours then flag it for an alarm

If I understand correctly you are trying to create an event log and that by its self is Fairley simple
But if you are trying to log when power is lost then that a problem. You can't write the data while the processor in powering down. The second problem is that when you download the backup program all of your tag data will be overwritten and your log will be lost.
The solution would be to power the processor with a UPS system to keep the power on when the incoming power is lost. Then program the events as an alarm to an HMI that can log the events to a flash drive. Although some of the new logix processors can right data directly to an SD card and store the log. That may be solution to consider.
 
Thanks everyone for your suggestions. You have given me a lot to chew on.

widelto,
I learned some interesting things from the sample code at the link you posted, but it only uses the lower DINT, so it only goes a little over an hour. That is we below what I need. You did trigger some more search terms in my head so I found some more sample code on the Rockwell site. One says it converts microseconds in a LINT to seconds in a DINT with some clever bit shifting. I am still trying to decipher how it works to be sure it actually will count up to years if needed. If I decide it works, I will post it back here for anyone searching the forum later.

Pal,
I was hoping to only check the elapsed time when the second event occurred instead of periodically checking. If I can't come up with something better, I may end up using your suggestion.

Gary,
I am not creating an event log. What I am trying to do is find out how frequently I am getting a certain alarm. If it is only occasionally, I will treat it as a normal alarm. If it starts happening frequently, I want to lock out the operator and force him to call engineering. The 24 hours is arbitrary, as is the number of alarms in that time period considered "normal".

~Don
 
Don , sorry , I misunderstood your question and thought you wanted a signal 24 hrs after an event occured . I am still confused . do you want to count the alarms in a 24 hr period and if it is for example 3 then force the operator to notify someone ? You mention a time period of 1 year . Are you therefore trying to count the events in a year and normalise to 24 hrs ?
It is difficult to help with code suggestions when your objective is not clearly defined .

Paul
 
widelto,
I learned some interesting things from the sample code at the link you posted, but it only uses the lower DINT, so it only goes a little over an hour. That is we below what I need. You did trigger some more search terms in my head so I found some more sample code on the Rockwell site. One says it converts microseconds in a LINT to seconds in a DINT with some clever bit shifting. I am still trying to decipher how it works to be sure it actually will count up to years if needed. If I decide it works, I will post it back here for anyone searching the forum later.
~Don
I do not get you what proposed can measured elapsed time from micro seconds up to years:
yy:mm:dd:hh:mm:ss:us exactly as wallclocktime data, in other words it uses an array of seven DINTS.
 
Paul,
I am trying to see whether I am having a particular alarm too frequently. Have I had too many of a particular alarm in the last 24 hours (or less)? If I have my quota in 5 minutes, I want to stop right there. This was my general idea: When I get one of these alarms, I want to copy the current time into the "Start time". The next time I get the same alarm, I want to subtract the "Start time" from the current time. If it is more than 24 hours, I want to copy the current time into the "Start time", set the count to 1 and allow the operator to reset the alarm. If it has been less than 24 hours, I want to add 1 to the count. If the count is less than 3, I want to let the operator reset the alarm and keep the original "Start time". If the count was 3 or more, I want to lock the operator out. I don't want to check this every scan, only when I have the alarm. The alarm could occur several times in 24 hours or not for several years. I have to be able to deal with it either way.

Widelto,
You can get the wall clock as an array of DINTs as you described, or you can get it as a single LINT containing the number of microseconds since some time in the 1970s (depending on your firmware version). If I can find a way to subtract 2 LINTs, that would be simpler than trying to deal with the different number of days in a month, leap year etc.

~Don
 
OK now I understand . If you use the same idea from #6 , but use the event and a one-shot to trigger the calculation of the DINT "CurrentTime" in minutes outlined in post #6 and the "CurrentDay" .

Put a branch in the rung after the one shot and EQU "CurrentDay" , "PreviousDay" . ADD 5 to the stored time to another DINT called , for example , "PrevTimePlus5Minutes" . Use LIM ( High limit "PrevTimePlus5Minutes" , Low limit "PreviousTime" ) to test if the current time is within 5 min . If true , set a latch "Within5Minutes" and use this for your required logic .

Start a new branch after the EQU instruction . XIO ( not ) "Within5Minutes" and set a latch "Between5MinAnd24Hrs"

Add another branch to the original branchand XIO ( not ) "Within5Minutes" , NEQ "CurrentDay" , "PreviousDay" . LES "CurrentTime" , "PreviousTime" . Set the latch "Between5MinAnd24Hrs" . Use this for your required logic .

If neither of the latches are set , then the previous event is more than 24Hrs ago so with the event and a one-shot , increment your count and store the "CurrentDay" as "PreviousDay" & "CurrentTime" as "PreviousTime" .

The GSV is now only used when an event occurs .

Paul
 
Paul,
This is the route I was taking before I posted here, but it gets very complex when you start to consider all of the possible scenarios. If I understand correctly what you meant, it won’t work. Consider this example:
Previous Day = 12
Current Day =14
Previous Time = 5:00
Current Time =3:00
The times are not within 5 minutes. The days are not equal, but the current time is less than the previous time, so we get the result that it is less than 24 hours. Looking at the days, it is clearly over 24 hours. OK, we can test for greater than 1 day difference, but what happens when we roll over at the end of the month. When we go from 23:00 on the 31st to 1:00 on the 1st, we get a day difference of 30 days, but it is really only 2 hours. Not all months have the same number of days, so we have to specifically deal with that. Then we have to deal with end of year rollover. We have to deal with month 1 two years ago compared to month 8 this year. What about month 8 two years ago and month 1 this year? What about leap year. This is why I said I can do it this way if I really have to, but I would rather make LINT math work.

~Don
 

Similar Topics

Hello everyone, i have searched this forum and looked here for advice before but this time i wasn't able to find an exact answer for what i'm...
Replies
14
Views
10,426
Hi there, I have an SLC503 that I'd like to control an external contact with. Basically I'd like to assert my local contact on the 503 every 12...
Replies
14
Views
7,188
hello I have a system to program in which there are two HVAC's.Always one is standby and the other is running.The HVAC RUN command is given from...
Replies
4
Views
2,268
Need help a source code to make timer display into hour:min descending from a time of delay 1 sec base timer. Thanks
Replies
22
Views
5,945
I have never worked on a Seimens controller before. This is a simple job, but I'm a little confused on a timer issue. The customer wants to...
Replies
2
Views
2,393
Back
Top Bottom