Hi All,
I was wondering if it were possible to generate a high frequency of 8Mhz with a 33% duty cycle on my Arduino Mega 2560?
However, I'm starting to understand the the fact that having a high frequency has the trade-off of a lower PWM resolution. Hence I'm beginning to believe it's simply not possible to achieve.
The program below (hopefully) describes a 8Mhz PWM signal at a 50% duty cycle in mode 14 (fast PWM):
// set OC5C (pin 44) as PWM output
// fast PWM: PWM_frequency = clock_speed / [Prescaler_value * (1 + TOP_Value) ]
// mode 14 - fast PWM - frequency = 16MHz / (1*(1+1)) = 8Mhz
#include <avr/io.h>
void setup
{
pinMode(44, OUTPUT);
// fast PWM, set on match, clear on TOP, ICR5 holds TOP
TCCR5A |= (1<<COM5A1) | (1<<COM5A0) | (1<<WGM51);
// use ICR5 as TOP and CLK/1 as prescaler
TCCR5B |= (1<<WGM53) | (1<<WGM52) | (1<<CS50);
// 50% duty cycle
OCR5A = 0;
ICR5 = 1;
}
Similarly, in mode 7 (fast PWM) at 8Mhz with the same 50% duty cycle:
void setup()
{
pinMode (44, OUTPUT);
// enabling OCR5A and OCR5B in mode 15, fast PWM with OCR5A as TOP
TCCR5A |= (1<<COM5A1) | (1<<COM5B0) | (1<<WGM51) | (1<<WGM50);
// no prescaling CLK/1
TCCR5B |= (1<< WGM52) | (1 << CS50);
// 50% duty cycle
OCR5A = 1; // count to 2, zero-relative
OCR0B = 0; // duty cycle
}
My code is likely to have mistakes in it but I hope it shows the jist of what I'm asking. For instance, in the last example, I could change OCR5A = 3 and OCR5B could then take on the values 0, 1 or 2, in turn enabling duty cycles of 66% or 33% respectfully.
My question again, is whether it's possible to have an 8Mhz PWM signal with a 33% duty cycle?