Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Counter/Timer Question

2005-06-20 by jeff_smith_8992

When I use the AVR's internal oscillator or an external crystal
oscillator, like 1.0 MHz, is the frequency 1,000,000 Hz (give or take
a few Hz for accuracy, temp, etc)?  And not a power of 2, like 2 to
the 20th = 1,048,576?

The reason I'm asking, is because the prescaler divisors are all
powers of 2 (i.e., 2, 4, 8, 16, 32, etc), and this makes it difficult
to use the prescaler to get whole number frequencies.  For instance,
if I use a 1 MHz clock and the 1024 prescaler, it gives an interval of
0.001024 seconds instead of a nice, even number like 0.001 seconds.

I guess my real question is, "Given a particular input clock, how can
I make a timer that counts in, say, one millisecond intervals"?  And
how can I keep it as accurate as possible over a long period of time?

Thanks for any help.

Jeff

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.