cancel
Showing results for 
Search instead for 
Did you mean: 

while loop problem

aeolia_amha
Associate II
Posted on September 13, 2010 at 17:18

while loop problem

4 REPLIES 4
Posted on May 17, 2011 at 14:06

Well, the code does seem to do a lot of unnecessary math, given the window in seconds is understood well before it starts looping.

And the code seems to ignore the fact that the RTC is ticking in one second increments, so the loop will spin around a few million times on the 'exact' second cases.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
aeolia_amha
Associate II
Posted on May 17, 2011 at 14:06

What do you mean unnecessary math, is the code for getting the RTC_getcounter and getting the corresponding hours, minutes and seconds unimportant. Why does it ignore the RTC increments, what is the better solution for this one, I haven't seen any example applications for this. Thanks.

trevor23
Associate III
Posted on May 17, 2011 at 14:06

I think what Clive means is that your code would be simpler, more efficient, smaller  and certainly more robust if you just used time represented by a number for all comparisons. I'm pretty sure I posted something on one of your posts previously on how to convert time to a number -- I'll search the forum to see if I can find it and report back. RTC_get_xxxxx already returns a number. All you have to do is turn your hours, minutes and seconds (entered via your UART_scanf) for the current day into  numbers and all the math becomes trivial.

Regards

Trevor
Posted on May 17, 2011 at 14:06

What do you mean unnecessary math, is the code for getting the RTC_getcounter and getting the corresponding hours, minutes and seconds unimportant. Why does it ignore the RTC increments, what is the better solution for this one, I haven't seen any example applications for this. Thanks.

Time is linear, forward moving.

Time-of-Day (ToD) can be measured in seconds.

Hours/Minutes are only relevant in the human interface code.

How many times can you read the RTC counter in one second? A few million,

perhaps a couple of thousand if you are IO limited with data going out the serial port.

Perhaps you should wait for the RTC counter to actually change before recomputing H:M:S repetitively. For the comparisons you can use ToD in seconds.

What happens if your code is expected to cross 23:59:59 - 00:00:00? Pretty sure it's going to fail.

Sometime examples don't exist for the job you have to do, and then you have to write it yourself.

I'm not keen on coding your project.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..