328P timer0 pwm digitial pin5 problems


I am trying to use digital pin 5 as a PWM output. Whenever I try to configure the PWM the code hangs can someone point out my errors.

Here is the setup code.

// setup phase correct waveform generation.
TCCR0A |= (1<<WGM00);
TCCR0A &= ~(1<<WGM01);
TCCR0B |= (1<<WGM02);

// No prescale
TCCR0B |= (1<<CS00);
TCCR0B &= ~(1<<CS01);
TCCR0B &= ~(1<<CS02);

//attach PWM to pin
TCCR0A |= (1<<COM0B1);

What am i missing???
Can some please show me where I am going wrong :slight_smile:

Thanks in Advance

Timer 0 is used for millis, micros, delay, delayMicroseconds. Does your sketch make use of any of those functions?