2010-09-13 08:18 AM
while loop problem
2011-05-17 05:06 AM
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.2011-05-17 05:06 AM
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.
2011-05-17 05:06 AM
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 Trevor2011-05-17 05:06 AM
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.