Yahoo Groups archive

AVR-Chat

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

Message

Re: [AVR-Chat] Counter/Timer Question

2005-06-20 by James Hatley

Hello Mr. Jeff Smith,

Well as the others have mentioned the internal oscillator isn't too
accurate. 2% would be the best estimate of how fine you can tune it. But if
that is OK, it is easy to get pretty much any even number you want.

Study the Atmel manual carefully on your timer. (the following is somewhat
simplified but) Using mode 4 or the CTC, clear counter on top, you can set
most anything you want by loading the appropriate OCR register and setting
all the appropriate bits. For instance, at 1Mhz the counter is counting 1us
per tick so if you want 1000uS or 1ms you just put 1000 into the counter (
assuming you are using a 16bit counter), if not and it is an 8 bit counter,
set to divide by 4, now you have 4 uS per tick so put in 250 and you get an
interrupt every 1ms.

But the KEY here is to thoroughly understand the timer hardware and you will
find that you can do many timing tasks quite well.

Now if you really need "accuracy" ... you will have to install a crystal
like 2Mhz, 4Mhz, 8Mhz or 16Mhz or whatever fits your needs and power
desires. (Low Mhz lower power.)

Jim

----- Original Message ----- 
From: "jeff_smith_8992" <jeff_smith_8992@yahoo.com>
To: <AVR-Chat@yahoogroups.com>
Sent: Monday, June 20, 2005 9:38 AM
Subject: [AVR-Chat] Counter/Timer Question


>
> 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
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>

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.