PWM Frequency and Noise

I’m using a PIC micro controller and PWM to control my Pololu 210:1 micro metal gear motor (pn 1096) and at 245 Hz the motor makes a loud noise. I’ve seen 1000 Hz used but can someone recommend a suitable range of frequencies with this motor that will reduce the noise as much as possible? For my use, the motor will be on continually at very low rpm (around 30 for the Dutycycle so 1/8 of max rpm)

Hello.

The best way to reduce audible (PWM-related) motor whine is to use an ultrasonic PWM frequency, like 20 kHz. Do you know if your motor driver can support frequencies this high?

- Ben

Thanks Ben. Right now, I’m driving the motor directly from the PIC via a transistor but I will shortly be moving to the SN motor driver I purchased from Pololu.

I tried 22 kHz this morning and it didn’t seem to make any difference.

How confident are you that you were actually generating a 22 kHz PWM? If you change the PWM frequency, you should be able to hear some change in the sound of the motor noise. By the way, the SN754410 driver is pretty old technology, so I’m not sure how well it will handle such high PWM frequencies. If you run into trouble with it, I suggest you try the new DRV8833 dual motor driver carrier.

- Ben

I’m using a rotary encoder to change the duty cycle, but not the frequency - I don’t know if it is sending it out at the coded frequency. I’ve switched to using a 20Mhz ceramic resonator (it was originally set up to use the 4Mhz internal oscillator) but I still hear noise. How can I differentiate ‘whine’ from the normal motor mechanical noise? The motor will be inside a model and I don’t want the sound to be heard; if its really mechanical noise I’m hearing can I insulate around it?

BTW, I was planning on using the SN754410 with a 74ALS04N hex driver to use just two ports from the PIC to control speed/direction for each motor. Is that possible with the DRV8833?

You can connect the motor directly to a battery to get a sense for the mechanical noise it produces.

I’m not sure if the DRV8833 will work with your hex driver; the DRV8833 product page describes its interface and links to the datasheet, so you should be able to determine whether it is a suitable alternative for you.

- Ben

The noise appears to be similar as to directly connecting to a 9V battery when I use the max duty cycle. If it’s only the mechanical noise that’s left, can I wrap the motor in insulation?

I don’t have to use a separate hex driver to do the forward/reverse switching if the driver can do that itself. Are there any examples of how to use the DRV8833 (schematic, code)?

My main concern about wrapping the motor in insulation would be heat dissipation. If you will be using a low duty cycle, that probably isn’t going to be an issue. Also, you should make sure that the insulation doesn’t get into the gearbox.

The DRV8833 product page has a minimum connection diagram, descriptions of all the pins, and a schematic. If you supply a PWM to AIN1 and hold AIN2 low, channel A outputs will PWM the motor at the duty cycle of the PWM supplied to AIN1.

- Ben

Thanks Ben. I’ve now got it (mostly) working with the DRV8833 and PWM. I followed your connection suggestion (low on AIN2, PWM on AIN1) it works as expected. But when I make AIN2 high (I want to reverse direction but still rotate the motor at the same RPM/PWM as in forward), it behaves strangely (doesn’t spin at the same speed, and turning my rotary encoder to increase speed results in it slowing down - the opposite of when it was in forward direction).

Any ideas?

The truth table in the DRV8833 datasheet sheds some light on what you’re observing. If the two inputs are high, the driver is in a slow-decay/brake mode where the two motor outputs are effectively shorted together. If the two outputs are low, the driver is in a fast-decay/coast mode where the two motor outputs are disabled.

Given that, if you PWM one input while holding the other low, you are alternating between drive forward and coast. If you instead PWM that input while holding the other high, you are alternating between drive reverse and brake (and your PWM is inverted: 100% duty cycle means full brake). In general, drive-brake operation leads to more a more linear relationship between duty cycle and motor speed than drive-coast operation, and it allows the motor to start turning at lower duty cycles due to the slower decay of motor current. Does this make sense, or would you like me to explain in a bit more detail?

Do you have the ability to connect a PWM output to each input? For example, PWM AIN1 and drive BIN1 high to go forward, and PWM BIN 1 while driving AIN1 low to go in reverse. Another option would be to use a few logic gates to control which input receives the PWM based on a direction input.

- Ben

Hi Ben,

Not sure how using the ‘B’ inputs would help - wouldn’t I have to hook up the same motor to both ‘A’ and ‘B’ outputs? My project involves 2 motors each spinning at exactly the same RPM but with the ability to reverse direction of only 1 motor.

My PIC has 4 PWM output pins available.

And yes, the more detail the merrier!

Thanks,
Ross

Oops, that’s my mistake. I incorrectly assumed that the two outputs for each channel distinguished by A and B rather than 1 and 2.

Please look at table 3 at the bottom of page 8 of the DRV8833 datasheet. I suggest you set up your system so that you can do “forward PWM, slow decay” (second table row) and “reverse PWM, slow decay” (fourth table row). This requires that you have a two PWM outputs, one connected to AIN1 and the other to AIN2. To drive forward, you set the AIN1 PWM to 100% duty cycle (i.e. the line is always high) and the AIN2 PWM to the inverse of the output duty cycle you want (i.e. 100% - desired motor speed). To drive in reverse, you flip it: set the AIN2 PWM to 100% duty cycle and the AIN1 PWM to the inverse of the output duty cycle you want.

If you need bidirectional control of the B channel, you would set it up the same way. If you only need the B channel to turn a motor in a single direction, you could supply a PWM to one channel input and tie the other one permanently high.

You also might want to look at table 2 in the datasheet, as table 3 is a consequence of table 2. If you have a PWM signal with an X% duty cycle, the line is high X% of the cycle and low for the rest (100% - X%). When the two channel inputs have different values, the motor outputs are driving in a direction determined by which of the two pins is high. When the two channels have the same value, the motor outputs are either shorted together (brake, when both inputs are high) or disconnected (coast, when both inputs are low). So, if one channel input is being held high and you supply a PWM to the other input, the motor will be driving whenever the PWM signal is low, which happens 100%-X% of each cycle, otherwise it will be braking, which happens X% of the cycle. By swapping the inputs, you change the motor direction.

If you still find any of this confusing, please don’t hesitate to ask for clarification.

- Ben

Hi Ben,

My microcontroller has only two PMW pins but i need to run two motors in both directions. I tried out and encountered the problem you explained. You also mentioned that this could be solved using logic gates. Would be so kind as to explain how it works? Is there any other way?

Thanks,
Vinod

Hello, Vinod.

Are you asking specifically about the DRV8833 motor driver? I think the easiest solution would be to use the DRV8835 motor driver, which has similar performance but offers a speed/direction interface. You would supply a PWM to each channel’s ENABLE pin and use an I/O line to control direction via each channel’s PHASE pin.

If you already have a DRV8833 and are looking to make it work with your system, you could consider adding external logic gates to give it a speed/direction interface. For an example, please see the schematic for our dual MC33926 motor driver shield:

pololu.com/file/download/dua … e_id=0J559

Specifically, look at the components connected to the IN1 and IN2 pins of each MC33926 motor drivers (the circuit uses two AND gates and a MOSFET acts as an inverter). The way it works is that one IN pin is connected to the direction input AND the PWM input while the other IN pin is connected to !direction AND PWM. When direction is high, the PWM signal makes it to IN1 and IN2 is low; when direction is low, the PWM signal makes it to IN2 and IN1 is low.

- Ben

Hi Vinod,

I was really struggling with this, too, until I met a robotics hobbyist here in Toronto. He sells robot kits, but he showed me how to use a SN754410 motor driver and control the motor’s speed and direction (have a look at his schematic at robotxdesigns.ca/wp-content/uploads/2011/05/µBotino_V3_Guide.pdf - I used this hook up as shown, but without the jumpers on pin 8; I just connected that straight to +6v).

As you can see in the schematic, there are 2 inputs per motor - one for PWM (speed) and one for direction. Set the direction pin for the motor HIGH and it spins one way; set it to LOW and it spins the other; set both PWM & DIR pins to low and the motor stops (also, when you switch direction you need to use (255-motor_speed)). It’s recommended that you electrically stop the motors (both PWM & DIR pins LOW) before changing direction.

HTH,
Ross

Hi Ben,

Thanks for explaining the solution for me. I found that there is another driver from pololu from toshiba: TB6612FNG. I just browsed through the logic table and found that it would need only two PMW for controlling two motors just like DRV8835.

INA, INB and PMW for each motor control. Would you please confirm?

How different is it from DRV8835?

Thanks,
Vinod

Hi Ross,

Thanks for your suggestion. I am using DRV8833 because it’s operating voltage starts from 2.7 whereas for SN754410 its from 5v. I am building a low voltage gadget to operate from 3.7V lithium ion battery.

Thanks again,
Vinod

Yes, you can control the TB6612FNG with two PWM signals, one for each motor channel. The product pages and datasheets for the DRV8835 and TB6612FNG contain detailed information about the drivers that explains any differences more comprehensively than I could. If you have any specific questions, please ask.

To briefly sum up, though: the two drivers can deliver a similar amount of continuous current, but the TB6612 can handle higher peak currents (3.2 A vs 1.5 A). The DRV8835 is smaller and offers two possible control modes, and, probably more importantly for your application, it operates down to 2 V. I have seen conflicting information about how low of a voltage the TB6612 will run at, but I do not recommend using it below 4.5 V.

- Ben

Hi Ben,

Thanks for the information.

Thanks,
Vinod