> -----Messaggio originale----- > Da: pic microcontroller discussion list > [mailto:PICLIST@MITVMA.MIT.EDU]Per conto di dave vanhorn > Inviato: martedl 19 gennaio 1999 15.52 > A: PICLIST@MITVMA.MIT.EDU > Oggetto: Re: TMR0 compensation > > > >Why don't you just reload the TMR0 and renable interrupts as the first > >instructions of your int routine after the context save. > Assuming that you int > >routine including restoring the context is less than 125 instructions > long, you > >will get your interrupt again after the desired time, with the > instructions in > >your interrupt service routine being taken into account in the > delay. No need > >to do any fancy calculations at the end of the int service routine. > > Adding the reload value to the timer, instead of reloading the timer, will > compensate for when it is done. > The in happens on zero, so if the timer decs 3x during the isr (that's one > LONG isr!) then when you add the reload value to the timer, it will be 3 > counts short. > > It's still not perfect, but it's as close as you can get without an > auto-reload timer. > Perhaps I'm wrong ! But I think that the fault is in prescaler that is cleared when TMR0 is written and loses the number of instructions between int. and TMR0 reload .I should wait for presc.rate usec before reload the TMR0. I'm thinking to replace the xtal, probably is the more elegant solution. Tanks very much for the help Gianni