> From:
RemoveMECdB.TSPTakeThisOuT
pixie.co.za (Cobus deBeer)
> >Thanks for your responses on 16C84 interrupts, everyone.
> >This has made things much clearer.
> >I am still having some slight timing problems though.
> >I have made an LCD clock and it lost 17 secs in 2 hours.
> >Surely this is not the accuracy of the crystal?
> Two things that can go wrong.
>
> 1. When you write to the RTCC the precscaler is cleared. You must write to
> the RTCC as the first instruction in your ISR. This introduces a constant
> fiddle factor that you need to adjust your timing loops by. I solved this
> by adding a fixed number of seconds every five minutes. Not a good solution.
>
> 2. If you access the RTCC in the rest of your code there is a more subtle
> effect. (Read 'Many hours of debugging effort') By default the assembler
> uses 'Same' as the destination for a register operation. If you want to set
> the flags by using the RTCC reg as a source you should use w as the
> destination. If you use Same as the destination the write to the RTCC reg
> will cause a two instruction resynchronization error to occur (and the
> prescaler contents is lost, if its used). We used a pic16c54 as a clock and
> discovered this the hard way (no interrupt, we had to poll the RTCC).
>
> If you use the prescaler it is extremely difficult to load the RTCC and get
> precise delays. You have to precompensate (predistort) your timing for the
> two instruction cycle error caused by the write to the RTCC and this
> introduces a fraction into the calculations which is extremely awkward to
> handle. We tried to correct for this effect by loading the RTCC very early
> in an subroutine (before any conditional code) and used different values in
> the reload to get a fractional value on average. The subroutine was invoked
> as soon as we detected the overflow of the RTCC. This failed as well, reason
> unknown. We abandoned the 54 at this point.
>
> The best solution is to use a 4.096 MHz crystal and a PIC with interrupts
> and to set the prescaler to generate interrupts at a convenient rate without
> ever reloading the RTCC register with values. Count the number of
> interrupts. If you load the RTCC with values in the ISR you still get errors
> because the amount of time spent before you reach the ISR depends on the
> instruction that is executing when the interrupt occurs. If a goto or call
> instruction is in progress it takes longer before you reach the ISR and you
> lose more cycles from the prescaler when you load the RTCC. If you count
> the number of interrupts without touching the RTCC the accuracy seems to be
> limited only by the crystal.
>
> We trim the crystal with a trimcap. Remember to measure the frequency
> through a buffer which stays attached to the oscillator or the capacitance
> of the leads of the frequency counter will detune the oscillator while you
> are adjusting the frequency.
>
> Regards
>
> Cobus de Beer
>
> P.S. Please echo this to the list. It bounces from my location.