Searching \ for '[PIC]: 500ms timer using 4MHz resonator and timer2' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/time.htm?key=time
Search entire site for: '500ms timer using 4MHz resonator and timer2'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: 500ms timer using 4MHz resonator and timer2'
2002\03\19@120129 by Kevin Olalde

flavicon
face
I'm trying to build a clock on a 16F870.  This will part of another project, but
starting with the clock.

I'm using some sample code found at:

http://www.piclist.com/techref/microchip/intsample.htm

The sample uses a 4MHz crystal (I'm using a 4MHz resonator) and timer2 to
generate an interupt every 1ms.  It's setting the prescaler to 4, the post
scaler to 10 and the period register to 25.

Has anyone either used this sample or technique before.  When I try to use it
for controlling a 'clock', it seems to run a little slow (looses about 2-3
seconds over a 10 minute period).

Now there part where I probably shot myself:

I modified the sample.  The original interput routine adds 1 to a 2 byte
counter.  When the counter his 500 it sets a flag.  The main routine (outside of
the interupt routine) loops on this flag waiting for it to get set, toggles an
LED when it does get set and clears the flag.

I've changed the sample interput routine to count up to 1000 (going for a 1
second flag).  When the 'one second flag' get set in the interupt routine, in
the main loop I add 1 to a single byte counter, convert the result to BCD and
shift it out to a pair of cascaded 74HC595 shift registers controlling two 7
segment displays.

The displayed seconds seem correct, but after observing the display for a some
time (10 minutes), the 'clock' seems to run slow.

Any advice would be greatly appreciated.

Thanks,
Kevin

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\03\19@125245 by Drew Vassallo

picon face
>The displayed seconds seem correct, but after observing the display for a
>some
>time (10 minutes), the 'clock' seems to run slow.

Why not just put the LED back in place, delete the code you added, and run a
stopwatch simultaneously to check the LED timing.  You can make the counter
overflow to whatever you want to make it ~20 minutes or so.  Set the time,
come back in 20 minutes and see if the LED comes on.  Of course, you'll have
to make a counter with 3 bytes to get the 20 minutes (20 * 60 * 1000 =
0x124F80).  Check the stopwatch to see the difference.  If it's still off by
4-6 seconds, your LED 7-segment display code isn't likely to be the culprit.

--Andrew

_________________________________________________________________
Join the world s largest e-mail service with MSN Hotmail.
http://www.hotmail.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\03\19@143037 by Paul Hutchinson

flavicon
face
What' the frequency accuracy for the resonator?

I've never used a resonator so, maybe they just aren't very accurate
compared to crystals.

3 seconds error in 10 minutes is only 0.5% (3/600*100).

Paul

> Has anyone either used this sample or technique before.  When I try to use
it
> for controlling a 'clock', it seems to run a little slow (looses about 2-3
> seconds over a 10 minute period).
>
<snip>
>
> The displayed seconds seem correct, but after observing the
> display for a some
> time (10 minutes), the 'clock' seems to run slow.

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\03\19@143249 by Olin Lathrop

face picon face
> The sample uses a 4MHz crystal (I'm using a 4MHz resonator) and timer2 to
> generate an interupt every 1ms.  It's setting the prescaler to 4, the post
> scaler to 10 and the period register to 25.
>
> Has anyone either used this sample or technique before.  When I try to use
it
> for controlling a 'clock', it seems to run a little slow (looses about 2-3
> seconds over a 10 minute period).

3 seconds in 10 minutes is .5%.  What is your resonator rated at?


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, spam_OUTolinTakeThisOuTspamembedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\03\19@143439 by Dale Botkin

flavicon
face
On Tue, 19 Mar 2002, Kevin Olalde wrote:

> I'm using some sample code found at:
>
> http://www.piclist.com/techref/microchip/intsample.htm

You might want to search the archives for a thread we saw last year about
"zero error" clocks.  There was a really neat method proposed, I think, by
Roman Black (I could be wrong).  You use an interrupt of whatever
frequency you want and get a clock whose "long-term" accuracy over more
than a few seconds will be equal to the crystal accuracy.  Simple, works
like a charm, and you can find a C implementation if you search for my
posts over the past 30 days or so, I just posted it for someone else.

Dale

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\03\19@174331 by Kevin Olalde

flavicon
face
Thanks for the replies!  I'll have to check the datasheet on the resonator (I'm
ashamed to admit I don't know its type.  Ok it's a hobby project so I'm not that
ashamed).

Thanks for the tips.  I have to look into the resonator specs (maybe switch to a
crystal) and the routines that Dale mentioned (probably both).  The clock will
synchronize regularly to a remote computer (that's using NTP) or adjust the
amount tracked in the interrupt, so the drift is workable.  I just thought that
18 seconds over an hour to be a bit much (assuming the accuracy remains
constant).

Without knowing what type I've got at home (I'm at work now), I checked a
similarly priced resonator, right there in big ol' print, "Initial frequency
tolerance: +-0.5%", but obviously I'll have to check my part.

So for grins, I looked at a 4MHz crystal, HC49US4.  Its datasheet says its
"frequency tolerance: +-50ppm".  Is that 0.005% or about 4 seconds/day?

As always, this list is a great resource, thanks again.

Kevin

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\03\19@175345 by Paul Hutchinson

flavicon
face
> So for grins, I looked at a 4MHz crystal, HC49US4.  Its datasheet says its
> "frequency tolerance: +-50ppm".  Is that 0.005% or about 4 seconds/day?

Yep, 50ppm = 0.005% ~= 4s/day.

Paul

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\03\19@175930 by Dave Dilatush

picon face
Kevin Olalde wrote...

>So for grins, I looked at a 4MHz crystal, HC49US4.  Its datasheet says its
>"frequency tolerance: +-50ppm".  Is that 0.005% or about 4 seconds/day?

Yep, that sure sounds right.  IIRC you can get 30ppm, too.

I usually figure ceramic resonators are fine for keeping serial
async baud rates under control, but not much else.

Dave

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\03\19@180756 by Olin Lathrop

face picon face
> So for grins, I looked at a 4MHz crystal, HC49US4.  Its datasheet says its
> "frequency tolerance: +-50ppm".  Is that 0.005% or about 4 seconds/day?

Yes.  PPM is Parts Per Million.  50ppm = 50/1000000.

(50/1000000) * 3600 sec/hour * 24 hour/day = 4.3 seconds/day


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, .....olinKILLspamspam@spam@embedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


More... (looser matching)
- Last day of these posts
- In 2002 , 2003 only
- Today
- New search...