Yahoo Groups archive

AVR-Chat

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

Message

Re: [AVR-Chat] PWM question with ATMega128

2007-11-30 by Jim Wagner

On Thu, 29 Nov 2007 16:44:33 -0800
 "Philippe Habib" <phabib@well.com> wrote:
> I'm new to using the AVR processors and I'm trying to use
> the built in PWM
> function.
> 
>  
> 
> I have basic PWM working and I've got 2 different pwm
> signals going from two
> independent timers.  So far so good.
> 
>  
> 
> Using the pre-scaler, I can get close to the desired PWM
> frequency, and by
> setting the compare register appropriately, I can set the
> duty cycle.
> 
>  
> 
> When I use the timer as a timer, I know how to set the
> exact time I need by
> using the timer register to some value and having it
> count to overflow.  Is
> there some similar mechanism to allow me to adjust the
> PWM frequency to
> exactly what I need instead of the nearest pre-scaler
> value?

With timers that have TWO compare registers, you can use
one to set the value at which it resets; you can set this
to anything from 1 to the maximum count value of the timer.

The prescaler and the sysem clock will always set the timer
interval for one count.

Example: Clock = 10MHz, prescale = 1, one count is worth
0.1us. But, if prescale = 16, one count is worth 1.6us.
This sets the TIME RESOLUTION of the counter.

Jim Wagner
Oregon Research Electronics
Tangent, OR, USA
---------------------------------------------------------------
The Think Different Store
http://www.thinkdifferentstore.com/
For All Your Mac Gear
---------------------------------------------------------------

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.