Yahoo Groups archive

AVR-Chat

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

Message

ATmega 168 Timer 1 mode 14, fast PWM, problem

2007-04-08 by anding_eunding

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!!!

	}

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.