#18808 - 10/01/07 07:26 PM
Half-Hourly Code
|
Just Another Joe
enthusiast
  
Registered: 09/02/03
Posts: 204
Loc: Adanac
|
I would like to run some code twice per hour, once at five minutes past the hour and once at thirty-five minutes past the hour. My thought was to use a variable to hold the current time-of-day, and on each pass compare the actual Time-of-Day to the variable. If not equal, then the minute has advanced, so reload the variable, copy it to a scratch variable, modulus 60 and check for 5 or 35, like this:
0179 - // *** ONCE-PER-MINUTE CODE *** 0180 - IF Time of Day is NOT = v9-Time_Of_Day // If Time-Of-Day has advanced one minute 0181 - ELSE Skip to line 216 // Otherwise, skip Once-Per-Minute code 0182 - THEN Load Data to: v9-Time_Of_Day // Then capture new Time-Of-Day 0183 - // *** Other Once-Per-Minute Code Goes Here *** 0184 - // 0185 - // *** Half-Hourly Reset Code *** 0186 - THEN v59-Scratch = v9-Time_Of_Day // Copy Time-Of-Day to Scratch 0187 - THEN v59-Scratch % 60 // And get Time-Of-Day Minute 0188 - IF v59-Scratch is = 5 // If Time-Of-Day Minute is 5 minutes past the hour 0189 - OR v59-Scratch is = 35 // Or Time-Of-Day Minute is 35 minutes past the hour 0190 - Half-Hourly Code Goes Here
The problem is that at the correct times, the half-hourly code executes on every pass for one full minute, instead of just once. Line 180 should only be true on one pass each minute--when the time advances. Using 'Debug Timers and Variables' I can see v9-Time_Of_day increment once per minute and at the same time see v59-Scratch increment as v9-Time_Of-Day modulus 60. What is wrong?
_________________________
Just Another Joe Why be politically correct, when you can be right?
|
|
Top
|
|
|
|
#18810 - 10/04/07 11:17 PM
Re: Half-Hourly Code
[Re: Guy Lavoie]
|
Just Another Joe
enthusiast
  
Registered: 09/02/03
Posts: 204
Loc: Adanac
|
Hi Guy, welcome back.
Thanks for the reply. I think you are correct. I began to suspect this to be the problem earlier when I read this post, where Rex was essentially doing the same thing I am trying to do, but used a temporary variable for the purpose in exactly the same way you posited. I wondered why he would do that when it was more direct to simply compare the time directly. I suppose his reason was to work around this problem, and I shall do the same.
But it appears to me that this is a (small and easily worked around) bug. If you look at my sample code, line 182 loads v9 whenever the times don't match, so from that point on, in line 180 the times should be the same until the clock advances at the next minute, so "becomes" shouldn't be necessary in this case. Since the times should be the same, then the NOT should make the boolean false, and the ELSE in line 181 should execute. But that doesn't seem to be the case. Thanks to you and Rex for providing the workaround.
_________________________
Just Another Joe Why be politically correct, when you can be right?
|
|
Top
|
|
|
|
Moderator: Dan Smith, Monte G, ADI Tech Support, Guy Lavoie
|
2747 Members
19 Forums
3837 Topics
22713 Posts
Max Online: 67 @ 08/16/11 03:08 PM
|
|
|
|
|
|
1
|
2
|
3
|
4
|
|
5
|
6
|
7
|
8
|
9
|
10
|
11
|
|
12
|
13
|
14
|
15
|
16
|
17
|
18
|
|
19
|
20
|
21
|
22
|
23
|
24
|
25
|
|
26
|
27
|
28
|
29
|
|
|
|
|
|