Software PWM for driving motors?

Hey there,

Here's my situation: I need to drive 10 h-bridges to control motors of various sizes (windshield wipers, etc.) in a servo-type configuration. In essence, I need 20
PWM pins, and I'm using an Arduino Mega, which I believe only has 12. Initially, I tried simply using the guts of a hobby servo to drive the h-bridge, but this failed horribly - apparently most of these hobby servos using an alternating PWM to control the DC motor - in essence not on and off pulses, but forward and backward pulses. Therefore, the motor vibrated horribly and will surely shake the robot to pieces if I use that configuration.

Therefore, I'm now trying to "roll my own" servos. I've already got some PID code up and running, and my initial test with a single motor and pot on A0 went well. Is there any possible way to create a "software PWM" setup to control all of these h-bridges? I've seen other forum posts like this one: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1278251011/all that deal with this, but the problem is, the program essentially has to stop while the pulsing is going on. I need to be able to update each of the 10 motors with the PID value at least every 15 ms. Is there any way to do this?

Thanks!

Edit: To clear any confusion, the PWM I need is being used to control DC motors directly, without a servo mechanism/IC in between. Therefore, I do need analogWrite-type functionality; i.e. whereas in a servo the position is updated every 20 ms, in my application the dc motor itself needs to be updated continuously, and as fast as possible.

Hi,
I am not sure what your application is, but if you need servo type PWM which is a pulse of between 1 and 2 ms sent every 20ms you can use the servo library which will drive upto 12 Servos on an UNO or 48 on a Mega.

If you need an analogWrite type PWM, this is not going to work for you.

For some background that might help you decide or give you an idea of how to modify the servo library to your application, see the following links -

EDIT: Thinking about it, I can't see why you could not create an library to extend analogWrite to any pin using the same concept as the servo library, essentially all it is doing is toggling pins according to a schedule managed on a hardware timer.

Duane B

rcarduino.blogspot.com