TIMER1 Output Compare B Match don't work for me

i'm trying to use TIMER1 to make a LED blink.
if i'm using Output Compare A Match its work but if i'm trying to use Output Compare B Match the LED turns on and stays on for some reason.

I'm using arduino mega 2560

This is my code:

void setup() {
  pinMode(13, OUTPUT);
cli();
TCCR1A=0;
TCCR1B=0;
TCCR1B |= (1<<WGM12);//set CTC on
TCCR1B |= (1<<CS12);//ser prescaller to 256
TIMSK1 =0;
TIMSK1 |= (1<<OCIE1B);//set output compare B
OCR1B = 62500;
sei();
}

void loop() {
  // put your main code here, to run repeatedly: 
  
}

ISR (TIMER1_COMPB_vect)
{
  digitalWrite(13, digitalRead(13)^1);
}

digitalWrite(13, digitalRead(13)^1);
Try
digitalWrite(13, !digitalRead(13));

LarryD:
digitalWrite(13, digitalRead(13)^1);
Try
digitalWrite(13, !digitalRead(13));

Whats the difference?
if i'm using output compare A it will work fine. but if i swich to B the LED will turn on once and stay on forever.

The datasheet states:

In Clear Timer on Compare or CTC mode (WGMn3:0 = 4 or 12), the OCRnA or ICRn Register
are used to manipulate the counter resolution. In CTC mode the counter is cleared to zero when
the counter value (TCNTn) matches either the OCRnA (WGMn3:0 = 4) or the ICRn (WGMn3:0 =
12). The OCRnA or ICRn define the top value for the counter, hence also its resolution.

There is no mention of OCRnB thus it only counts up to OCR1A. If you use OCR1A as the limit the LED flashes.

THanks :smiley: