How to alleviate DC motor whine due to PWM?

I have a DC motor connected to the Arduino Motor Shield v3. I also have a pot connected through which I can vary the speed of the motor. When I lower the speed, the motor makes a whining sound. I presume that this is due to the frequency at which the PWM is pulsing. Can I vary the rate? I am using a Due and not been able to find reliable information.

The sound is created from the motor and the shield. A solution is to change the PWM frequency on the PWM pin used. If the PWM is above 20kHz humans cant hear it. The problem with changing the PWM frequency is that timers are changed and with the timer-change functions like delay() is changed.

Different digitalPins have different PWM frequency. If you change the pin assignment you can use another set of PWM pins and another PWM frequency without manipulation of timers. My favorite PWM pins are 5,6 and 3,11 and I usually use them in pair for a set of 2 motors. They are alomost quite in the upper limit of the range 0-255. The first 0-100 in the PWM range is almost unusable. The motor dont get enought power to rotate with load.

map(wanted_Speed_in_range_0_255, 0, 255, minimum_useful_PWM, maximum_useful_PWM);

Solves alot of problems. There is no motor that moves from PWM 0 to PWM 255. Test where the lowest PWM that actually moves the motor = minimum_useful_PWM Assign the fastest speed wanted. 255 = Full ahead. Use the above code to get the PWM range 0-255 to be mapped to a useful PWM range for the actual motor. Keep in mind that wanted_Speed_in_range_0_255 = 0 is "lowest useful speed" and NOT brake and speed 0. Make an "if" to zero speed with or without brake when wanted_Speed_in_range_0_255 = 0 .

cabbagecreek: The problem with changing the PWM frequency is that timers are changed and with the timer-change functions like delay() is changed.

Different digitalPins have different PWM frequency.

Thanks for your response.

Does changing the PWM frequency still affect timers of a Due, or just the other Arduino boards?

I'd prefer not to experiment with other pins as it would mean bending pins and re-routing lines on my shield. However, can you tell me what PWM frequencies are used by the different pins?

Some motors are just whiners, no matter what you do to the PWM frequency, I think it depends on the rotor design. However setting the PWM as high as practical will minimise noise.

Using too high a frequency may cause problems.

Firstly a large motor may be less efficient at a high frequency as iron-losses
start to rise and dominate. You want a frequency that is high enough to reduce
current ripple (which causes copper losses), but no higher - some experimentation
could be useful.

Secondly each motor driver/controller has switching losses that directly depend on frequency.

Also if the PWM frequency hits a resonant frequency of the motor then the noise will be much louder -
a 10% change in frequency may then make a big difference…

In practice people tend to use 1, 2, 4, 8 or 16kHz - try each one in turn and pick the best?
16kHz is usually high enough (although some people can hear it just).

I've found a couple of threads about the problem of changing PWM frequency on the Due. It seems that it is possible to have two different frequencies running concurrently but only on pins 6,7,8 and 9. Changing the frequencies for these pins apparently does not affect any other timers and thus there are no issues on API calls such as delay().



I've managed to get this to work by bending D3 pin between the Due and shield. I then connected D6 to the shield's D3 so that I can write a PWM signal from the Due's D6 pin and route it to the correct input of the shield.

I then attached two potentiometers to the Due: one to control the speed of the motor and the second to control the PWM frequency between 500Hz and 20kz. I now have a musical motor!

The change in pitch is very noticeable. However, it is also very noticeable how increasing the frequency decreases the speed of the motor. For a particular duty cycle I have just tested (107 out of 255), simply changing from 500Hz to 800Hz caused a noticeable drop in motor speed. At certain PWM frequencies - a long way before 20kHz - the motor completely stops.

I presume that this is due to the inductance of the motor and the fact that the controller does not increase current to compensate.

A simple solution I've found with the whining, and I'm a beginner so maybe I don't know what I'm talking about... but, I found that when the motors get less power than they need, they whine. If I set my PMW to below 150, I get whining DC motors. But, if they get full power, they don't whine - between 200-255 PMW. I also think that if you're using a power supply for 12V DC motors that is 12V or lower, you might have issues but I have to test that a bit more to confirm that's true. All I know is that the PMW needs to be in the right range of juice.

That's not solving the problem, its avoiding the problem. Use 16kHz--20kHz or so will solve the problem at all duty-cycles.