Thanks Bob, and John
1. I had a silly typing error in my code that simply stopped the
real AVR from working:
TCCR1B |= (0<<CS12) | (1<CS11) | (0<CS10); // Missing '<' !!!!
2. The AVR debugger is completely spurious in emulating this
function. When I tried to investigate the issue on the debugger I
was totally lead astray. (I need a Dragon! :-)
3. Combination of 1. and 2. had me absolutely baffled.
Thanks again and apologies to the group for wasting your time with my
silly mistakes.
Happy Easter to all!
Andrew
PS Bob, I want to do servo control, so I set ICR1 to ~40,000 to give
me the 55Hz pulse repeat, then change OCR1A and OCR1B for the channel
width. I only need 2 channels, so 16bit PWM on Timer 1 is the easy
way...
--- In AVR-Chat@yahoogroups.com, "anding_eunding"
<anding_eunding@...> wrote:
>
> Hi,
>
> I am totally perplexed! I'm trying to set up fast PWM on 16-bit
> Timer 1 of the ATMega 168 in mode 14 (i.e. fast PWM, TOP = ICR1).
>
> It "doesn't work", and three strange things are happening which
I've
> investigated thoroughly on in the AVR Studio debugger:
>
> - I cannot write 16 bit values to OCR1A or OCR1B, they get masked
off
> as 9 or 10 bit values insted during the write.
>
> - I cannot write Clock Select = 2, when I try to, the clock source
> remains zero
>
> - If I write a Clock Select = 1, I get dual slope PWM, not single
> slope fast PWM as expected for mode 14.
>
> Here is the code. Any ideas greatly appreciated!
>
> void PWM_init(void) {
>
> ICR1 = 45455;
>
> TCCR1A = (1<<COM1A1) | (0<<COM1A0) | (1<<COM1B1) |
> (0<<COM1B0) | (1<<WGM11) | (0<<WGM10);
>
> TCCR1B = (1<<WGM13) | (1<<WGM12);
>
> OCR1A = 4384; // Gets masked off to 9 or 10 bit value!!!
> OCR1B = 3600;
>
> DDRB |= (1<<1) | (1<<2);
>
> TCCR1B |= (0<<CS12) | (1<CS11) | (0<CS10); // CS remains 0!!!
>
> }
>Message
Solved! Re: ATmega 168 Timer 1 mode 14, fast PWM, problem
2007-04-09 by anding_eunding
Attachments
- No local attachments were found for this message.