the code doesn't work in different type microcontrollers

#define pwm1 5
#define pwm2 6

void setup(){
   pinMode(pwm1, OUTPUT);
   pinMode(pwm2, OUTPUT);
}

void loop()
{
   analogWrite(pwm1, 0);
   analogWrite(pwm2, 200);
   delay(1000);

   analogWrite(pwm1, 200);
   analogWrite(pwm2, 0);
   delay(1000);
}

I tried to run the dynamo with bts7960 motor driver with this code. When I use it with Arduino UNO, the coding works well. but when I use Arduino Mega 2560, the opposite happens. I simplified my coding by only moving the dynamo in one direction and it worked on Arduino Mega. can you help tell me what error caused it?

There is some sort of bug with the current AVR boards core for the MEGA.

I think some of the last posts mention a possible fix/work around.