Change PWM frequency for DC-Motor control

Hi everyone,

I´m on a litte robot project and I´m running out of pins so I purchased this Mega-Board here.
I couldn´t find a category for MEGA Boards, so I´m hoping the Due is the closest match...

Arduino MEGA 2560 With WiFi Built-in - ESP8266 : 10 Steps - Instructables

To run the motors without the humming noise, I found this tutorial here were a code was used written by macegr. On my old Elegoo Uno R3 this code worked fine and the Motors were running perfectly without the humming noise. (You need to scroll down a lot for the modified code.)

Control Large DC Gearmotors with PWM & Arduino | DroneBot Workshop

Unfortunately this code does not work on my new board so I´m thinking of getting an original MEGA Board. Can anybody tell me if this code would work on the original MEGA board as well? Unfortunately this code is way too advanced for me to understand and modify it by my own. The beauty of this code is, that it covers all pins if called in the ().

I need to change the PWM frequency for Pins 5,6 and 9,10

Thanks a lot for your support :smiley:

Ben

PS: I also found this post here to change the frequency’s on a Due. so this would be an alternative as well.

Changing arduino Due PWM frequency for DC motor control - Hardware / Arduino Due - Arduino Forum

The reason why the code will not work on your new board is because it has a different microprocessor chip on it than the Uno and so does the original Mega

The code addresses some registers of the chip, so as written will only work with an ATMega328. I have no doubt that it is possible to change the PWM frequency of the Mega and you may well find some help using Google

Hi Bob,

Thanks for your post and explaining the background why the Uno-code is not working on my MEGA. That makes absolutely sense…

So the easiest solution for me would be to get the Arduino Due and use the code which was posted in the other thread.

All my controllers and sensors are fine with 3.3V, the only downside for me is the relatively high power consumption of the Due compared to the Mega. Its higher speed is not really relevant for me.

Are there any more points to take into account?

Or is there a board using the ATmega328(P) which has 7 analog, 4 PWM pins, 8 digital and a pair of DCL/SDA pins?

Cheers

Ben

maybe the easiest would be search for an code for Mega :wink:

Just found this one here...

mega 2560 PWM frequency - Using Arduino / Project Guidance - Arduino Forum

The original code that works on a Uno won't work on a Due because of its different processor

I would use an original Mega if I were you

Hi Bob,

Thanks the code in the above link works great, so I´m happy and at least this problem is solved.

Cheers Ben

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.