MD01B at 32kHz PWM frequency

Hi,

I have two MD01Bs hooked up to an Arduino to drive my robot, and I’ve played with the PWM frequencies a bit. The MD01B is specified up to 10kHz, which is in the audible range, and the Arduino gives me a choice of 30, 122, 244, 488, 976, 3906 or 31250Hz (approximate values). 30 and 122 are too low for smooth control, everything else within specification gives a very loud hum / whine at the specified frequency. The wife is not at all amused. :frowning:

However, I’ve also tried 31250Hz, which gives no hum and seems to work. At least the motors don’t react in any way different than at the other frequencies, and I’ve had my robot driving for 10 minutes now without the controllers getting very hot (I’d say about 50°C judging by touch). I know very little about electronics, so I’m asking here – can anyone tell me if I’ll eventually break them by running them at 31kHz, or what problems could arise?

Thanks in advance!
Regards,
Björn

Hello.

You have not specified which motor driver you have, though the 10kHz makes it sound like you are talking about the VNH3SP30, which has bad shoot-through issues as the voltage goes up. The main problem with higher switching frequencies is more heating in the motor driver and less power to your motor; if that is not a problem for you, the 31 kHz should be fine. The motor driver life might be affected, but if you can touch it, it’s probably not going to be an issue.

Keep in mind that this could be a problem if you want to move to a more powerful motor or a higher motor voltage in the future.

- Jan

Hi,

yes, it’s a VNH3SP30, which I use at 12V. It’s very unlikely I will ever go up to a higher voltage. My motors are http://www.jaycar.com.au/productView.asp?ID=YG2738, with a maximum current draw of 14A. I haven’t let the robot drive up ramps or otherwise test motor power, but it goes up to top speed just fine. So if you say this is probably OK, I’m going to monitor controller heat-up closely for a while longer and just leave it at that.

Thanks a lot!

Regards,
Björn

Sounds good. If you do run into some limits, the VNH2SP30 version is a a drop-in replacement that can give you a few dozen percent of extra performance.

- Jan

OK, not good. Some testing reveals that the controller does get too hot at 32kHz (it just turns off after a while). I’ve tried lower frequencies but they’re too loud for living-room usage. So I’m going to try the VNH2SP30. That one still has a too-low maximum PWM frequency (20kHz; the Arduino can generate either 4kHz or 32kHz) but I hope it can take 32kHz without overheating.

Hello.

While the Arduino’s library functions might only offer 4 or 32 kHz PWM frequencies, the AVR on the Arduino is capable ultrasonic PWM frequencies that are in-spec for the VNH2SP30. Have you considered writing your own PWM code?

- Ben

Hi,

I didn’t know that. The Arduino library functions don’t really support changing the PWM frequency, I did that tweaking the timer control registers, but I’m by no means an expert on this. Do you have a link on how to achieve this and what frequencies are possible using the hardware timers? (Of course, I could bit-bang, but the Arduino has a lot more to do than just generating PWMs.)

We did some experiments using a signal generator on the weekend, and while I am totally deaf above 14kHz (blame heavy metal), the wife hears up to 17kHz, which is dangerously close to the VNH2SP30’s 20kHz spec.

Thanks,
Björn

I know 20 kHz sounds like it’s close to 17 kHz, but I don’t think you have to worry about it. Even if your wife can hear 17 kHz, I expect it to be very faint, and I think she won’t be able to hear 18 kHz, let alone 20 kHz.

I think the best resource is the source code for Arduino’s analogWrite() function coupled with the ATmega328 datasheet (or whatever MCU is on your Arduino). Specifically, you can control the frequency by setting how fast the timer ticks as a prescaled fraction of the CPU clock along with the value at which the timer overflows. For example, the Arduino has a 16 MHz clock, so if you use the timer in fast PWM mode with a timer prescaler of 8 (clock ticks at 2 MHz) and a TOP (or overflow count) of 99, your PWM will have a frequency of 20 MHz / (99+1) = 20 kHz and you will have 100 different available speeds (if you count speed 0).

If you want more speed resolution, you can use the Arduino’s 16-bit timer (timer 1) at full speed with a larger top. Specifically, a timer 1 prescaler of 1 (16 MHz tick rate) and a TOP of 799 will product a frequency of 20 kHz in fast PWM mode with 800 available speeds. You could also consider using a phase-correct PWM, which has some benefits over the fast PWM, but it might be a bit more confusing for you to understand. Sections 14.7.3 and 14.7.4 of the ATmega328P datasheet explain the fast and phase-correct PWM modes.

If you have specific questions, please don’t hesitate to ask.

- Ben

Hi,

wow. Thanks a lot for all that info! I’m looking through the data sheet right now; will try that. I’ve ordered two VNH2 boards. I’ll report here how those work out.

Regards,
Björn