Bug in Arduinos analogWrite()

Hi there

As I saw some people mentioning analogWrite() bugs some time ago I got my first now too. I use the Elegoo board from the Most complete Starter Kit MEGA 2560 Project.

The simple code:

setup {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
analogWrite(2, 5);
analogWrite(3, 200);
}

and the connection of 2 LEDs to the Pins 2 and 3 by 220 ohm resistors result in Dimming the first one (PIN2) to 200 brightness, and disabling the second one (PIN3).

First I though that maybe there is too much current flow and I tried to use an NPN connected by a 10k resistor to base. But with the same result....

If I comment out the second "analogWrite(3, 200)", the LED on PIN 2 become darker (as it is using the value = 5).

Each of this PINs work fine with 1 LED, dimming is working as expected. But as soon as connecting the second LED to the another PIN (or one of the other PWM-pins of my MEGA), the mentioned strange behaviour occurs.

Then I wanted to know, what is going wrong and I have found this page:

There is the implementation of the analogWrite()-function. I read it and then I just used the internal implementation myself directly in my code, means:

setup {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
sbi(TCCR3A, COM3B1);
sbi(TCCR3A, COM3C1);
OCR3B = 5;
OCR3C = 200;
}

Now all is fine, I can control PWM of both LEDs independently, just using "OCR3B = " or "OCR3C = ".

So this all leads to the conclusion: There must be something wrong in the Arduino Software with the AnalogWrite.

My question: is this an already known bug and is there a bugfix, so that I can use analogWrite() again? I use the Arduino 1.8.12 IDE.

My question: is this an already known bug

Yes.