[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] prescaler

From: Joerg Wunsch
Subject: Re: [avr-gcc-list] prescaler
Date: Wed, 12 Jun 2002 21:25:52 +0200 (MET DST)

"Brandon Tolbert" <address@hidden> wrote:

> This is a multi-part message in MIME format.

[Please don't do this, and post plain text only.]

>     Can someone help me by explain what the prescaler is for when
> using = the timer function? I know it is remedial for most of you
> but I really = am having trouble finding good info on this. thanks B

Hmm, good info?  IMHO, the datasheets precisely describe it.

Anyway, if you want to use one of the counters as a timer by counting
CPU clock cycles, the maximal time you can count is delimited by the
sice of the timer channel, and the clock frequency.  So if you're only
using an 8-bit counter, and run at a frequency of 4 MHz, you get
1 / (4000000 / 256) = 64 ┬Ás as the time until the unbiased timer will
roll over (and thus can e. g. generate you an interrupt).

For 16-bit timers, the time is longer by a factor of 256, obviously.
But then, there's only one 16-bit channel, and perhaps you might want
to use that as something else (like as a PWM, for example).

So in most situations, it's quite possible that you need a longer
timing, but don't need the high resolution you can obtain by counting
the unscaled CPU clock.  That's where the prescaler gets into the
game: it scales down the CPU clock by a fixed amount before feeding it
into the timer, thus prolonging the timing distances you get.  (As an
alternative, you can also scale down in software, e. g. by using a
static variable inside an interrupt function.  Still, the interrupt
function gets called very frequently, eating up a good bit of CPU.)

Note that the prescaler on the AVR is only available when using the
CPU clock as input (i. e., you can't prescale an external clock).

Note also that the combination of using the prescaler and the CTCn
feature (clear timer/counter on match) has some not so nice
side-effect as described in the manual, resulting in an `odd' total
scaling factor.  That's IMHO the biggest drawback of using it.

J"org Wunsch                                           Unix support engineer
address@hidden        http://www.interface-systems.de/~j/
avr-gcc-list at http://avr1.org

reply via email to

[Prev in Thread] Current Thread [Next in Thread]