| ??? 04/05/03 04:37 Read: times |
#42920 - RE: RTC and timer question--long Responding to: ???'s previous message |
Going back to the original question, Gabriel was looking for a RTC solution. Personally, I care more about accuracy than precision when referring to the time of day, which I suppose is why we have leap years.
Anyway, using the leap year methodology, accurate timekeeping can be obtained by making adjustments. And as others have mentioned--by not resetting the timer value! Ok, let's say my 11.0592 MHz crystal is actually running at 11.086849 MHz or so. Assuming it to be as advertised would cause my RTC to be fast by 216 seconds/day. 4 Minutes a day! I would throw out any timepiece that was off that much. An 8-bit timer would overflow approx. 3600 times per second. I like to have my clock display precision to 0.01s. That would be every 36 overflows. For greater accuracy, determine the actual speed of your crystal by counting the number of cycles over a long period (1 day, or week even). Using my 11.086849 MHz example, 1/100 sec would take 9239.0408 cycles. That's 23.04xxx more cycles than the 9216 cycles from a perfect 11.0592 MHz crystal. No Worry. I'll just stop the timer for 23 clock cycles every 1/100 sec. Here's one of those adjustments I referred to earlier. Now my MCU executes an extra 0.04 cycles every 1/100 sec, or 4 cycles every second. You guessed it, after I increment the second counter in the timekeeping routine, I'll stop the timer for a total of 4 cycles. That's not bad. Its now off by 0.000833 cycles per 1/100 sec (299.88 cycles per hour, or 1/100 sec every 30 hours). I can live with that. Some things to keep in mind: - since the timer is being stopped, the timekeeping routine better not be interrupted; give it the highest interrupt priority - its easier to wait than to catch up; if your crystal is slow, decrease the number of overflows before servicing the timekeeping routine - a lot of processor time is spent servicing the RTC, especially servicing an interrupt at 3600 times/second Alternatively, you could change the stored time as opposed to stopping/starting the timer. In this example, your timekeeping routine could simply double-increment the 0.01-sec counter every 4 increments of the 1-second counter. |
| Topic | Author | Date |
| RTC and timer question | 01/01/70 00:00 | |
| RE: RTC and timer question | 01/01/70 00:00 | |
| RE: RTC and timer question | 01/01/70 00:00 | |
| RE: RTC and timer question | 01/01/70 00:00 | |
| RE: RTC and timer question | 01/01/70 00:00 | |
| RE: RTC and timer question | 01/01/70 00:00 | |
| RE: RTC and timer question | 01/01/70 00:00 | |
| RE: RTC and timer question | 01/01/70 00:00 | |
| RE: RTC and timer question | 01/01/70 00:00 | |
| RE: RTC and timer question | 01/01/70 00:00 | |
| RE: RTC and timer question | 01/01/70 00:00 | |
| RE: RTC and timer question....Donald | 01/01/70 00:00 | |
| RE: RTC and timer question....Donald | 01/01/70 00:00 | |
RE: RTC and timer question--long | 01/01/70 00:00 |



