Inconsistent Timer1 output signal

Hello!

I've been trying to generate a variable frequency signal using Timer1 from ATmega328.
I cannot understand why the output signal looks like in the picture
Imgur

It's having that empty spaces at random moments when the signal is staying low for some time.
They are not appearing at the same frequencies everytime it's random.

The prescaler is set to 256 and the timer is running in Fast-PWM mode having ICR1 as top value.
The

Did someone encountered this problem before?
If yes how did you manage it?

I will post my code below. Thank you!

void setup()
{
  pinMode(9, OUTPUT);
  TCCR1A =  bit(COM1A1) | bit(COM1B1) |  bit(WGM11);
  TCCR1B = bit(WGM12) | bit(WGM13) | bit(CS12) ;
  
 // TIMSK1 |= (1 << OCIE1A); //enabling timer1 interrupt
}

unsigned int i=50000;
  
void loop()
{
  i=50000;
  
  while(10 < i)
  {
    OCR1A = i/2;
    ICR1 = i;
    i--;
    delayMicroseconds(100);
  }

  while(i < 50000)
  {
    OCR1A = i/2;
    ICR1 = i;
    i++;
    delayMicroseconds(100);
  }
}

I cannot understand why the output signal looks like in the picture
https://imgur.com/o4mhGcb

Post the picture to this forum, not some temporary web storage.

You don't synchronize your register modifications with the actual timer status. If you modify the register while the counter is in that region you loose an event.