Sorry, my numbers are messed up, I didn't read carefully enough. I see now that the interrupt rate is 38.14697265625 Hz. I'll try again. There are 26214.4uS per interrupt (like you said). You add 26214, so 0.4us of every 26214.4us is lost. That's only -15 ppm, plenty good enough. However, to simplify here's what I'd do-- Scale the phase accumulator so that 1 second is a power of two instead of 1000000 in the accumulator. For the most precision with 24 bits let 2^23 (8388608) counts be one second. Now you will need to add 2^23/(10E6/4/256/256) = 219902<.326> at each interrupt. When bit 23 is set, clear it and increment your one second counter. This is much simpler and faster in software, and 8X more accurate too. -Jim Jim Hartmann @MITVMA.MIT.EDU> on 01/11/2000 08:21:01 AM Please respond to pic microcontroller discussion list Sent by: pic microcontroller discussion list To: PICLIST@MITVMA.MIT.EDU cc: Subject: Re: 4MHz OSC / 1 Sec Interrupt I think the problem is not enough precision in your counter-- You are throwing away 0.4us per interrupt by rounding 26214.4 to 26214 (I assume). At an interrupt rate of 102.4uS, this causes an error of -0.4/102.4 = -0.4% multiplied by 3600 sec/hour is -14.06 seconds per hour. So your measurement is pretty close to what would be expected. To get more precision you need to scale your phase accumulator so instead of 0.4% error you get an error more like 0.0040% per period. -Jim James Cameron @MITVMA.MIT.EDU> on 01/10/2000 04:16:35 PM Please respond to quozl@us.netrek.org Sent by: pic microcontroller discussion list To: PICLIST@MITVMA.MIT.EDU cc: Subject: Re: 4MHz OSC / 1 Sec Interrupt - prescaler set to 1:256, - TMR0 interrupt enabled, - maintain a 24-bit 0.1us counter, - add 26214.4us to the counter each interrupt, - subtract 1,000,000us (1s) from the counter, - if underflow, ignore the subtract and return from interrupt, - if no underflow, retain the new value, and do the once-a-second task. Having done this, I'm a bit annoyed that the accuracy wasn't very high. Using a low profile 10MHz crystal, two 27pF capacitors, on veroboard, gave me a loss of about 9 seconds per hour. 0.2% error. What changes do I make to use a 32768Hz clock crystal? -- James Cameron mailto:quozl@us.netrek.org http://quozl.us.netrek.org/