On Tue, 24 Jun 1997 22:56:59 -0400 "Thomas A. Coonan" writes: >I understand that part. >I am little more interested in the algorithms in actually maintaining >a Real Time Clock using what you just described. I was expecting >to use a 32-bit counter. I'm interested in how often to do this >self-calibration in order to track the temperature, etc. I guess >I'm also interested in hearing any experiences about tolerances >and other errors that creep into the scheme as a whole. I haven't done it but it should work. Set WDT prescaler to 1, CLRWDT, and increment counter as fast as possible until interrupted by reset. It probably takes about 5 cycles to increment a multiple-byte counter, so using a 4 MHz xtal and a typical 18 ms timeout would be 18000 counts or about a 15-bit result. Then set the prescaler to maximum and go to sleep, the time to wakeup will be approximately 128 times the measured count. The oscillator start-up time is another unknown, offhand I can't think of a way to measure it without an external reference. Also all the little delays in measuring, starting, stopping and resetting need to be accounted for. Even with that, the process won't be immune from cumulative long-term error, so using it to keep time of day over days or weeks is going to be dubious (a 1:18000 error is 4.8 seconds per day). Also, most cheap 4 MHz xtals are 50 or 100 ppm tolerance (4.3 or 8.6 seconds per day respectively) The power required to run the PIC continuously from a 32 KHz crystal with the WDT disabled is close to the power of a sleep then run at high speed scheme. Unless the high speed is needed for short intervals it may be better to just run the PIC slow but continuous.