Problem with having multiple PWM otuputs running at the same time

I am having trouble have 6 PWM signals running at the same time on the arduino mega 2560. I have changed the frequecy of these to run at ~200KHz. All works well when pin 5 and 6 arent enabled.

When I have pin 5 or 6 enabled though all of the 6 pins just stay high and dont pulse. I cant use other pins as they are being used for lower frequecy PWM, but I am trying to get these to work first.

My code is attached below, and any help would be greatly apprecited.

void setup() {
  // put your setup code here, to run once:

pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);

TCCR3A = 0x23;
TCCR3B = 0x99;
OCR3A = 80-1; // Sets value to count up to - 200KHz
OCR3B = 0;

TCCR4A = 0x23;
TCCR4B = 0x99;
OCR4A = 80-1; // Sets value to count up to - 200KHz
OCR4B = 0;
}

void loop() {
  // put your main code here, to run repeatedly:
analogWrite(2,40);
analogWrite(3,40);
analogWrite(5,40);

analogWrite(6,40);
analogWrite(7,40);
analogWrite(8,40);
}

There was a problem with pwm on the Mega.

It should be fixed by avr core 1.8.3 + IDE 1.8.13

Are you using these latest versions? If not, then when you update to 1.8.13 avr core 1.83 will update as well. The Boards Manager in the IDE will tell you what core is being used.

I have updated the IDE to version 1.8.13 and the AVR 1.8.3 is being used, but I still have the same issue.

You are in a pwm mode where the frequency is set by the OCR3A and OCR4A used as TOP. Those are pins 5 and 6. You can not use them for PWM output in that mode.

Change the pwm mode to one which uses ICR3 or ICR4 as TOP.

If you want Mode 14 which uses ICRx for TOP you should change 0x23 to 0x22. Then put the TOP value in ICRx instead of OCRxA.

Cheers, that has sorted the issue!