Hi,
I am trying to generate a 4Mhz FAST PWM square wave from the ATMEGA644P that runs at 8Mhz off the internal RC clock. Is that possible? I have searched the entire site but haven't found some near my requirement.
Below is my code so far, but that does not seem to do it. Basically, I am trying to get the fast PWM signal out from the OC0B pin (pin 5, PB4) of the ATMEGA644. Thanks for any tip!
void setup4MhzClk() { TCNT0 = 0; // In the next line of code, we: // 1. Set the compare output mode to OC0B on compare match. To achieve this, // we set bits COM0B1 to high. // 2. Set the waveform generation mode to fast PWM (mode 3 in datasheet). // To achieve this, we set bits WGM01 and WGM00 to high. TCCR0A = _BV(COM0A1) | _BV(COM0B1) | _BV(WGM01) | _BV(WGM00); // In the next line of code, we: // 1. Set the waveform generation mode to fast PWM mode 7 et counter on // OCRA value instead of the default 255. To achieve this, we set bit // WGM02 to high. // 2. Set the prescaler divisor to 1, so that our counter will be fed with // the clock's full frequency (8MHz). To achieve this, we only need to // set CS00 to high. TCCR0B = _BV(WGM02) | _BV(CS00); // Half of the freq => 4Mhz. Top value for our counter to hit before // resetting. OCR0A = 127; // 50% duty cycle OCR0B = 63; }