AVR Timer1 OCR1A controls TIMER1_COMPB_vect interrupt! I was struggling with timer interrupts in my project. I couldn't make it work properly. So I decided writing a simple code and I saw a very interesting case.

ISR(TIMER1_COMPB_vect)
{
        PORTB ^= (1 &lt;&lt; PORTB5);
}


int main(void)
{
    cli();          // disable global interrupts
    TCCR1A = 0;     // set entire TCCR1A register to 0
    TCCR1B = 0;     // same for TCCR1B

    OCR1A = 10000;
    OCR1B = 100;

    TCCR1B |= (1 &lt;&lt; WGM12);

    TCCR1B |= (1 &lt;&lt; CS10);
    TCCR1B |= (1 &lt;&lt; CS12);

    TIMSK1 |= (1 &lt;&lt; OCIE1A);
    TIMSK1 |= (1 &lt;&lt; OCIE1B);
    DDRB= 0xFF;

    #define F_CPU 16000000
    sei();
    while (1)
    {

    }
}


Here is my code. When I change OCR1B value, nothing happens, but if I change OCR1A value then blinking gets faster. Is there a logical explanation for this?
By setting WGM12, you set the time to CTC mode. In this mode the timer will restart when it reaches that value set to OCR1A. So the lower the value, the faster it restarts, so the higher the frequency.

The OCR1B value only changes where in this cycle the interrupt occurs. It will however still only be called once per timer1 overflow.