Attiny45 Timer0 prescaler issue

Hello everyone!

I would like to ask a question about programming an Attiny45 via Arduino as ISP.
I attempted to write a simple software to create a PWM signal on pin 5 via manipulating the timer0 registers. The code looks the following:

void setup()
{
DDRB = (1<<PB0);

TCCR0A |= (1 << COM0A1) | (1 << WGM01) | (1 << WGM00);
OCR0A = 150;

//Set timer0 prescaler:
TCCR0B |= (1 << CS00);

}

void loop()
{
}

No matter if I change the board to another attiny45 or an attiny85, I cannot manupulate the prescaler when I try to set those bits which can divide the internal counter clock. With 16MHz internal clock setting, burning the bootloader to the chip, then uploading this sketch, I can measure a 1kHz signal with variable duty cycle on the mentioned leg (by changing OCR0A between 0 and 255). What did I miss?

Thank you for the help in advance!

:Niz

Try:
TCCR0B = (1 << CS00 ) ;
Instead of
TCCR0B |= (1 << CS00) ;

Depending on the Arduino core, timer 0 can already be set up for millis() etc.

If that doesn’t get you anywhere, load the blink sketch and confirm the blink rate is about once per second.

Do not assume registers are in their power-on state at the beginning of setup. They are not - all cores configure the available timers for use with millis and/or analogWrite for pwm.

When you take over a timer, set all the timer’s registers to the values you want.

Or override main() and do everything yourself (and be aware that nothing will be set up for you and analogWrite/tone/millis/micros/delay won’t work). If you do this, you can assume all registers start in their powerup state.