analogWrite/PWM acting strange

Hi all,

I have been stumped by this strange problem where my Arduino Mega 2560 (brand new)'s analogWrite pins wouldn't work. I am trying to power 5V Logic input for my 3 motor drivers (VNH2SP30 Motor Driver Carrier MD01B) with PWM pins 5, 6, and 7. However, whenever I upload my program to my Arduino, the analogWrite for pin 6 would only output 5V, whereas pins 6 and 7 would output 0.14mV. Whenever I try different pins (for instance, pins 2, 3, and 4), at least one of the pins wouldn't work with an output of 0.14mV. I have tried on 3 separate different types of computers, but the results are all the same.

This may not be relevant, but whenever I add an additional analogWrite(7, 250); after the analogWrite(7, 250);, my pins would all work fine. If I add random delay(5);s here and there, pin 6 would stop working and pin 5 would start working for some reason.

Is my new Arduino Mega 2560 broken? Is the Arduino IDE software bugged due to the new 1.8.12 update? Any ideas?

Thanks in advance! :slight_smile:

Here is my program:

void setup() {
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);

void loop() {
analogWrite(5, 255);
analogWrite(6, 255);
analogWrite(7, 255);
digitalWrite(22, HIGH);
digitalWrite(23, LOW);
digitalWrite(24, HIGH);
digitalWrite(25, LOW);
digitalWrite(26, HIGH);
digitalWrite(27, LOW);

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

1 Like