20-30kHz phase and frequency correct PWM problem

Hello,
I want to use arduino UNO for driving induction hob -basicaly half bridge resonant converter. I have to maintain PWM with deadtimes at frequency between 20-30 kHz and for driving highside and lowside IGBT.

I found that should be suitable to use timer 1 in mode 8-phase and frequency correct PWM.
The frequency of PWM can be changed by varying ICR1. But the PWM is 31,XXX kHz no matter what value ICR1 is.

#include <avr/io.h>
#include <avr/interrupt.h> 
void InitPort(void)
{
  //Init PB1/OC1A and PB2/OC1B pins as output
  DDRB|=(1<<PORTB1)|(1<<PORTB2);   

  pinMode(13, OUTPUT);
}
void InitTimer1(void)
{
  //Set Initial Timer value
  TCNT1=0;
  //set non inverted PWM on OC1A pin
  //and inverted on OC1B
  TCCR1A|=(1<<COM1A1)|(1<<COM1B1)|(1<<COM1B0);
  //set top value to ICR1
  ICR1=250;
  //set corrcet phase and frequency PWM mode
  TCCR1B|=(1<<WGM13);
  //set compare values
  OCR1A=130;
  OCR1B=120;
}
void StartTimer1(void)
{
  //Start timer with prescaller 64
  //
  TCCR1B=(1<<CS10);
  //TCCR1B = (TCCR1B & 0b11111000) | 0x01;
}


void setup(){


}


void loop()
{//delay(10);
  InitPort();
  InitTimer1();
  StartTimer1();
  while(1)
  {
    delay(100);
    digitalWrite(10, LOW);
    digitalWrite(13, LOW);
    digitalWrite(9, LOW);
    delay(100);
    digitalWrite(13, HIGH);
    //InitPort();
    InitTimer1();
    StartTimer1();

  }
}

Could you tellme where is the problem please?

PWM_pro_plotynku.ino (951 Bytes)

I think the problem is that startTimer1 is wiping out what was in TCCR1B. Did you mean |= ?

I changed TCCR1B=(1<<CS10); to TCCR1B|=(1<<CS10); in startTimer1

ant PWM at pin 9 disappeared, there is just log1

I believe that the default values for the timer are carrying into your set up. Try clearing TCCR1A and TCCR1B before setting the values

void InitTimer1(void)
{
  //Set Initial Timer value
  TCCR1A = 0
  TCCR1B = 0
  TCNT1=0;
  //set non inverted PWM on OC1A pin
  //and inverted on OC1B
  TCCR1A|=(1<<COM1A1)|(1<<COM1B1)|(1<<COM1B0);
  //set top value to ICR1
  ICR1=250;
  //set corrcet phase and frequency PWM mode
  TCCR1B|=(1<<WGM13);
  //set compare values
  OCR1A=130;
  OCR1B=120;
}