Your theory seems correct so it's either hardware or software. If hardware, the most common problem would be using a series cut crystal instead of a parallel cut. To check the software use the Microchip simulator. Set a break point in the interrupt routine where you increment your 1 ms counter, run to the break point, open the stopwatch and reset it, run to next break point. you should be within a cycle of 1000, run it a few times more to be sure of the behavior. Even though I have an ICE2000, I test as much of the code as I can during development with the simulator first. Bob Bullock Embedded Systems Consultant (currently available) At 07:44 AM 11/26/2002 -0500, you wrote: > >> >I'm running PIC with 4MHz crystal oscillator and I've been trying to >implement a clock using TMR2 interrupt. I initialized TMR2 with >prescaler 4, postscaler 1:1 and period 250. So, I'm getting interrupts >every millisecond. When a counter inside ISR reaches 1000 I increment >seconds and zero the counter. Am I right so far? ><< > >Yep. I've done this many times. Your clock should be as accurate as your >crystal. > > >> >Anyway, clock lags >behind about a second in 4 minutes. ><< > >There is something seriously wrong here. Either your crystal isn't what you >think it is (is it specified for parallel operation?), or you have a bug >that missing some ticks. > > >***************************************************************** >Embed Inc, embedded system specialists in Littleton Massachusetts >(978) 742-9014, http://www.embedinc.com > >-- >http://www.piclist.com#nomail Going offline? Don't AutoReply us! >email listserv@mitvma.mit.edu with SET PICList DIGEST in the body -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body