Electronic – Can you set the PWM output of an Atmel AVR to a specific frequency and have control over duty cycle

attinyavrpwm

I'm trying to drive an LED at 38kHz with a low duty cycle like 10% from an Atmel ATTiny88. The chip is currently running at 8MHz, but could be adjusted for this portion of code, if need be.

Using the Timer1 with PWM I seem to either have the option to have decent control over the frequency, or I can only use the prescalers to adjust frequency and have control over the duty cycle. I have not found a way to have both the tight control over frequency and also be able to adjust the duty cycle.

Is there a solution that would allow for this, or is it not possible on these microcontrollers?

Best Answer

Wavegen mode 14 on timer 1 will allow you to control both frequency (via prescaler and ICR1) and duty cycle (via OCR1A and OCR1B).