Increasing frequency on this abomination of code.

Hi.

I have created a piece of code which produces 2 PWM signals which are phase-shifted 180°. Duty cycle is variable from 0 to around 50%. Using Arduino UNO

Problem is, that I would like to know how to increase frequency to around 40kHz or even something higher.

I have tried reading different guides and documents, but having practically no experience with Arduino and direct port manipulation, I have hard time understading it.

So far I understand that I am using timer0 and it is in phase-correct PWM mode. If I change it to fast-pwm I increase frequency, BUT signal won’t be phase shifted. I need signals to be shifted 180°

int dutyCycle;
int a;
void setup() // do something with timers.
 {
  pinMode (5, OUTPUT);
  pinMode (6, OUTPUT);

  //TCCR0A = bit (WGM10) | bit (COM0B1) | bit (COM0A1) | bit (COM0A0);    
  TCCR0A = bit (COM0B1) | bit (COM0A1) | bit (COM0A0); 
  TCCR0A |= (1 << WGM10);
  TCCR0B = 0x01;
  
 }
 
void loop() {
  a = map(analogRead(A0), 0, 1023, 140, 255);
  dutyCycle = a;

  OCR0A = dutyCycle;           // duty cycle out of 255 
  OCR0B = 255 - dutyCycle;     // duty cycle out of 255
  }

Duty cycle is adjusted with a pot on analog 0 pin. Output pins are 5 and 6. Adjusting duty cycle doesn’t affect shift between signals.

So I would like have some directions or ideas how to solve it. I would appreciate it very much.

You are already clocking Timer0 as fast as possible.

It isn't clear what you are trying to do, so sit down and come up with a reasonable description of your actual goal, and the desired output signal. Why does the PWM frequency even matter?

Then perhaps someone can think of a way to accomplish it.