Arduino Mega Can't Run 2 PWM Outputs together

Hi;
I am doing a simple project just to test Arduino mega PWM using IRF540N mosfet.
My electronic board and code are very simple. It is Arduino Mega and 2 IRF540N connected to pin 3 and 4 as PWM output pulled down with 1 k resistors. One for 12 VDC Fan and another for 12 VDC LED light.

my code is:

const int Light_Pin = 4;
const int Fan_Pin = 3;

Setup:
pinMode(Light_Pin, OUTPUT);
pinMode(Fan_Pin, OUTPUT);

Loop:

analogWrite(Light_Pin, 100);
analogWrite(Fan_Pin, 200);

Though it is a simple job, but 2 PWM output do not work together. Each one works properly when I remove another one.
I noticed that Light works only if I set the PWM of Fan to 255. It does not work for what ever else I set as Fan PWM. Also I noticed when I put both PWM in a for loop changing PWM value from 0 to 255, They work properly together..
It is too weird and my mind is blowing. I need your help to figure it out what wrong is with my job?

Tnx

Post your schematic.

Put the analogWrite() in setup() so they only run once, and not have the registers which set them up get written over and over nearly instantaneously.

There is some sort of bug with the current AVR boards core for the MEGA and you may be seeing it.

There are some work arounds proposed at the end of the thread.

https://github.com/arduino/Arduino/issues/9653

CrossRoads:
Post your schematic.

Put the analogWrite() in setup() so they only run once, and not have the registers which set them up get written over and over nearly instantaneously.

So if I put them in Setup, how can I recall them again in the loops? I mean I have to use them in somewhere in the loop to control the program.

cattledog:
There is some sort of bug with the current AVR boards core for the MEGA and you may be seeing it.

There are some work arounds proposed at the end of the thread.

https://github.com/arduino/Arduino/issues/9653

Yes you are right. The problem is not me. Arduino 1.8.12 has an issue with PWM.
I tried the older version and my code and setup[ was fine.

Thank you.