ADICON Support Forum Applied Digital, Inc.
Page 1 of 1 1
Topic Options
#18808 - 10/01/07 07:26 PM Half-Hourly Code
Just Another Joe Offline
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
#18809 - 10/04/07 02:17 PM Re: Half-Hourly Code [Re: Just Another Joe]
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6548
Loc: Montreal, QC, Canada
It seems the "IF Time of Day is NOT = " command does not have the same "becomes" behavior of the "IF Time of Day becomes = " command. One way to get what you want would be to capture the time of day in a temporary variable instead of testing it directly and then testing it as a variable to variable comparison, like this:

0179 - // *** ONCE-PER-MINUTE CODE ***
new - IF Time of Day is > 0:00 // Test Time-Of-Day
new - THEN Load Data to: v59-Scratch //save value in v59
new - ELSE Load Data to: v59-Scratch //in all cases
0180 - IF v59-Scratch becomes NOT = v9-Time_Of_Day // If Time-Of-Day has changed since last pass
0181 - ELSE Skip to line 216 // Otherwise, skip Once-Per-Minute code
0182 - THEN v9-Time_Of_Day = v59-Scratch // Then save new Time-Of-Day for next pass
...
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#18810 - 10/04/07 11:17 PM Re: Half-Hourly Code [Re: Guy Lavoie]
Just Another Joe Offline
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
Page 1 of 1 1


Moderator:  Dan Smith, Monte G, ADI Tech Support, Guy Lavoie 
Hop to:
Who's Online
0 registered and 51 anonymous users online.
Recent Posts
Shout Box

Newest Members
brigiel, vevevie, zhutree, 416, saiqul
3003 Registered Users
Forum Stats
3003 Members
19 Forums
4004 Topics
23442 Posts

Max Online: 132 @ 11/13/16 10:07 AM
December
Su M Tu W Th F Sa
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 30
31