PWM and software prescaler CLKPR

Right now, I'm running my Arduino at 1 MHz and running Timer0 PWM with a 1024 prescaler. Unfortunately, this is still now slow enough for me (debugging purposes).

I want to use the CLKPR register, but for some reason it makes no difference

#define F_CPU 8000000 // Oscillator frequency

int main(void){

  // Set Clock Prescaler
  CLKPR |= _BV(CLKPS1) | _BV(CLKPS0);  // 8 Clock Division Factor
  // Set PWM
  DDRD |= _BV(PD5); // Set pin to output
  OCR0A = 128;
  OCR0B = 64;
  TCCR0A |= _BV(COM0B1);              // Clear OC0B on Compare Match, set OC0B at TOP
  TCCR0A |= _BV(WGM01) | _BV(WGM00);  // Fast PWM Mode
  TCCR0B |= _BV(WGM02);               // Fast PWM Mode

  TCCR0B |= _BV(CS02) | _BV(CS00);   // 1024 prescaler


I'm running my Arduino at 1 MHz


#define F_CPU 8000000 // Oscillator frequency

What is correct now?

Maybe that's your problem?

This may be your problem:


• Bit 7 – CLKPCE: Clock Prescaler Change Enable The CLKPCE bit must be written to logic one to enable change of the CLKPS bits. The CLKPCE bit is only updated when the other bits in CLKPR are simultaneously written to zero. CLKPCE is cleared by hardware four cycles after it is written or when CLKPS bits are written. Rewriting the CLKPCE bit within this time-out period does neither extend the time-out period, nor clear the CLKPCE bit.

Try this instead:  CLKPR = _BV(CLKPCE);

Note: You can cut the PWM frequency in half by using one of the Phase Correct PWM modes (1 or 5) instead of the FAST PWM modes (3 or 7).

You have a 16-bit timer and you are setting TOP to 128. If you want a lower PWM frequency, set TOP to a higher number. You can go up to 65535.

What PWM frequency would you like?