Electronic – ATTiny 841 PWM at 450kHz

atmelattinypwm

I have managed to output 500kHz PWM at 50% duty cycle on PA2 TOCC1 of ATTiny841.

DDRA = (1 << PA2);//PA2 pin as an output
TOCPMSA0 = (1 << TOCC1S0);//TOCC1 linkage
TOCPMCOE = (1 << TOCC1OE);//Enable PWM
TCCR1A = (1 << COM1A1) | (1 << WGM11);//Fast PWM 1110
TCCR1B = (1 << CS10) | (1 << WGM12) | (1 << WGM13);//Fast PWM 1110
ICR1 = 1;//Not sure how clock is calculated but this gives me 500kHz on scope

I would like now to generate a 450kHz PWM on that same pin. 444.44kHz = 8MHz/18 would be acceptable. How can I do that?

The datasheet of ATTiny 841 is available here: http://www.atmel.com/Images/Atmel-8495-8-bit-AVR-Microcontrollers-ATtiny441-ATtiny841_Datasheet.pdf

Best Answer

First, either unprogram the CKDIV8 fuse or set the clock prescaler to /1 so that you're actually running at 8MHz instead of 1MHz. Then set ICR1 to 17 in order to get the timer to count 18 clock pulses per cycle.

Related Topic