Detailed Description
This is a proposal how to handle time-keeping. Feel free to add your comments.
We have the following sources for elapsed time:
- asynchronous 32768 Hz Timer (T2), this works in the deepest (used by us) sleep mode;
- synchronous 14.7456 MHz System clock, only works in full power and idle modes.
Sources for absolute time are:
- GPS data, packets are delivered once each second;
- user adjustments (when implemented in user interface).
The functions in xpal_async32khz.c configure Timer2 to wrap-around once per second, this gives a resolution of 7.812 ms. It may be possible to use the start time of a new data packet from the GPS as indication that a second has just started (not tested yet).
Upon receipt of a message from the GPS the following steps should be taken:
- Convert time from message into internal format. Depending on GPS data protocol used, the date or the century may have to be guessed.
- For finer time resolution, remember the T2 counter value at reception of the first byte of the message bunch.
- Calculate and store the difference between GPS time and internal time.
- From several samples, a drift value of the internal clock can be calculated. (This step will be implemented in a later version.)