I've been working with PWM in TIMER0 of my nano board.

So, it's working now and I know how to set OCR0A or OCR0B.

Then, I went to play with Clock Select Bits CS02 CS01 CS00 in TCCR0B.

0, 8 and 64 prescaler configurations worked as I also don't see the effect on the LED fade speed.

But the more problem I get is that 256 and 1024 prescaler don't work at all and the LED goes on all the time.

What is the problem?

The code:

void setup() {
    DDRD |= (1<<DDD6);
    TCCR0A |= 0xC1;
    TCCR0B |= 0x00; // this works for 0x01, 0x02, 0x03 only

    void loop() {
    uint8_t i;
    for (i=0;i<256;i++)
      OCR0A = i;


  • Do you have the real code? And if you are using Arduino framework, don't forget Timer0 is used for counting millis(), so you might just messed up some delay time
    – KIIV
    Commented Nov 3, 2016 at 16:31
  • Code added :) it's working with the delay as you mentioned that timer0 is used for counting millis, but I'm working with true C coding. Is it still used for _delay_ms and _delay_us? Thank you,
    – R1S8K
    Commented Nov 3, 2016 at 16:36
  • You have been waiting 4 or 16 times as long to try to see any change, right? Commented Nov 3, 2016 at 16:40
  • No, _delay_*() are implemented with assembly code loops (which means that F_CPU must be set correctly). Commented Nov 3, 2016 at 16:41
  • I was waiting 4 or 16 times for what exactly ?
    – R1S8K
    Commented Nov 3, 2016 at 16:43

1 Answer 1


The main problem is the prescaler on Timer0 is already configured to divide clock source by 64 CS01 and CS00 are set (0b00000011).

And you are using bitwise OR to "change" prescaler: TCCR0B |= 0x05; or TCCR0B |= 0x04;. But this'll result into the clock source 7 (0b00000111) - clock source is expected on T0 input counting on rising edge.

  • WOW :) you absolutely right. The bitwise OR was the problem. OK so when to use the bitwise OR when I'm testing different codes and when not to use it? I use it with DDRs PORTs which works well, so here it did a problem !! Thank you very much for the help 3>
    – R1S8K
    Commented Nov 3, 2016 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.