Yahoo Groups archive

AVR-Chat

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

Thread

Re: [AVR-Chat] Re: PWM question with ATMega128

Re: [AVR-Chat] Re: PWM question with ATMega128

2007-11-30 by Dennis Clark

I would also be prepared to ignore Bascom's PWM configuration libraries.
 On newer devices they are sometimes not fully functional.  This is no
big deal since you can poke the values you want directly into the
registers and not worry about the Bascom syntax.  I needed to do this
with the ATTINY26 when I used Bascom since it didn't properly set the
registers to work.

DLC

> --- In AVR-Chat@yahoogroups.com, "Philippe Habib" <phabib@...> wrote:
>>
>> Thanks for the reply.  I looked through the data sheet for guidance
> about
>> the various counters but I wasn't able to figure out what I need.  Maybe
>> someone here can help.
>>
>> I am using an ATMega 128 clocked at 16 mhz.  What I'm trying to get is a
>> 10khz PWM from timer 1 and a 2 khz pwm from timer2.  I am using the
> Bascom
>> BASIC.
>>
>> I expect that what I need to do is to use these like I use timer0 to
> set up
>> my 10ms timer tick. For that, I set the prescale to 1024 and by
> reloading
>> the timer to 99 each time my timer ISR executes, I get a 10ms tick.
>>
>> Since this is a PWM and I don't have an ISR, I'm looking for the way
> to set
>> that reload value one time when I configure the PWM.  That's what
> I've been
>> unable to find.
>>
>> I have experimented with trying to set various timer related things but
>> haven't gotten it to work.
>>
>> Here are my declarations:
>>
>> Config Timer0 = Timer , Prescale = 1024
>> Config Timer1 = Pwm , Pwm = 10 , Compare A Pwm = Clear Up , Prescale = 1
>> Config Timer2 = Pwm , Pwm = On , Compare Pwm = Clear Up , Prescale = 8
>>
>>
>> I'd appreciate any help from someone who knows the answer on this one.
>>
>> Thanks.
>>
>
> Philippe:
>
> I believe you need to use a PWM wave generation MODE that allows you
> to specify the "TOP" value.  This value is specified in the OCRnA or
> ICRn register.
>
> While I haven't used an ATmega128, I did something similar with an
> ATmega8 to generate a PWM signal for RC servo control.  I used timer1
> in "fast PWM" mode, set the "TOP" value in the ICR1 register, and
> adjusted the duty cycle by loading different values in the OCR1A
> register.  I assume something similar can be accomplished with the
> ATmega128.
>
> Rick
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>


-- 
Dennis Clark
TTT Enterprises

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.