piclist 2002\11\26\080304a >
Thread: Clock accuracy
face BY : Russell McMahon email (remove spam text)

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? Anyway, clock lags
behind about a second in 4 minutes. IMHO, the error is too big to fix it
only in software. So there must be something else wrong. I'm guessing
4MHz isn't 4MHz accurately enough. I don't have an oscilloscope and I've
not measured the osc frequency yet. I was using 33pF capacitors with
oscillator and replaced them with 15pF - no noticeable change in
accuracy!? I'm planning to test it with another oscillator now.


1.    You appear to have the dread "quoted printable" set. Advise you un-set
if possible (may be caused by your ISP).

   Content-Type: text/plain; charset="us-ascii"
   Content-Transfer-Encoding: quoted-printable

2.    That accuracy is FAR to bad for a crystal oscillator. They won't get
that bad even if you pay them overtime rates.
1 second in 4 minutes is about 0.4% - a ceramic resonator will do better
than that short term.
You can expect 10 to 100 ppm or a second in 3 to 30 hours.

Sherlock Holmes tells us that therefore the code is wrong! (probably :-) )
Most probable cause is that you haven't allowed for the time spent in the
ISR when reloading the counter.
If so the clock will be slow by about

   (time in ISR)/(Time between interrupts).

Best trick is to ADD a constant negative amount to the counter at each IRQ
so that it then increments up to the trip point. This works no matter how
late you do the addition (as long as your ISR exits in less than one IRQ

Counter IRQs at 0
Timeout desired every 250 counts

   misc interrupt code
   Counter = Counter - 250


http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservspam@spam@mitvma.mit.edu with SET PICList DIGEST in the body

<028701c2954b$ddf67e80$2301a8c0@Paradise> 7bit

See also: www.piclist.com/techref/microchip/time.htm?key=clock
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) Clock accuracy

month overview.

new search...