Can you set the PWM output of an Atmel AVR to a specific frequency and have control over duty cycle?
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?
2 Answers 2
Wavegen mode 14 on timer 1 will allow you to control both frequency (via prescaler and ICR1) and duty cycle (via OCR1A and OCR1B).
-
\$\begingroup\$ Thanks. Once I knew which mode to look at it was pretty straight forward to get it going. \$\endgroup\$ArraysStartAtSeven– ArraysStartAtSeven2014年11月18日 23:49:46 +00:00Commented Nov 18, 2014 at 23:49
Perhaps you could use an external clock source but I'm not sure how ATTiny reacts to variable frequency.
What exactly do you want to achieve? I hope you're not re-inventing Phase Correct PWM :)