andretost
Posts: 6
Joined: Sat Jun 01, 2013 3:00 pm

Controlling DC motor and servo

Mon Jan 13, 2014 5:32 am

This may be more of an electronics question than about the Pi, but I'm sure someone here can at least give me a pointer.

I have a setup with an L293D controlling a small DC motor. I'm using the RPIO Python library to create the PWM signal that lets me control the motor speed. I have a separate battery pack connected to the L293D V(motor) pin to supply power to the motor (the Pi is connected via its regular power plugin, not to the battery pack).
My setup works exactly as I expected, so that's all good.

I also have a different setup, controlling a little servo, also with RPIO sending a PWM signal to the servo. The servo is also separately power by the battery pack. And it works well, too.

My problem is that I cannot run both at the same time. As soon as I start the motor, the servo starts jittering and won't let me control it via the PWM signal anymore. This even happens if the control line for the servo is connected to anything at all. So I suspect that what's causing this is the motor creating spikes in the voltage off the battery pack, which in turn influences the servo that is connected to the same battery pack.

Does this make any sense, and if so, how I can stop it from happening?

Thanks much in advance,
Andre

User avatar
joan
Posts: 14959
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Controlling DC motor and servo

Mon Jan 13, 2014 8:48 am

I'd suggest an experiment.

Keep your set up as is but don't use PWM for the motor, just write high or low to wherever you send the motor PWM signal. Perhaps try that in a busy motor on 0.01, motor off 0.01 loop.

andretost
Posts: 6
Joined: Sat Jun 01, 2013 3:00 pm

Re: Controlling DC motor and servo

Mon Jan 13, 2014 4:27 pm

Thanks joan, I tried that, and indeed, when I don't use PWM but simply turn the pin for the motor on and off, there is no jitter on the servo at all. I also put it in a loop as you suggested, and again, there is no jitter on the servo.

And that makes me even more curious. Supposedly, PWM is not much different from turning the pin on and off in a specific time window. So how come that the behavior of the system is so different? Is the Pi not handling the PWM very well, or is it the L293D?

User avatar
joan
Posts: 14959
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Controlling DC motor and servo

Mon Jan 13, 2014 4:35 pm

I suspect there is a conflict between two DMA streams (the method being used to generate PWM) running from the same clock source.

I realise this probably doesn't mean anything to you, however if you contact the software module's author it will mean something to them and they may have a solution.

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

Re: Controlling DC motor and servo

Mon Jan 13, 2014 4:37 pm

I wonder if there's a hardware timer somewhere in the pi that is being shared by both the PWM library you're using, and the servo library you're using...

EDIT: I think joan's comment made just now is a better way of explaining what I tried to say, but yes I suspect the two operations are conflicting somewhere.

andretost
Posts: 6
Joined: Sat Jun 01, 2013 3:00 pm

Re: Controlling DC motor and servo

Mon Jan 13, 2014 8:05 pm

Thanks for the comments.

But this 'jittering' of the servo also happens if the control line of the servo is not connected. In other words, the only connection to the servo is via the battery pack! I also am not running two PWM programs at the same time, I am running just the one for the motor, and that is enough to make the servo flip out.

Anyway, one thing I can certainly try is use another way of generating the PWM signal. but I still have the feeling that the L293D somehow feeds back a bad signal via the power pins, and that this shaky power signal makes the servo unresponsive.

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

Re: Controlling DC motor and servo

Tue Jan 14, 2014 8:57 am

It's possible the extra load of having the 293 running is dropping the battery voltage, causing problems with the servo... well maybe. (If you have a meter, check the battery voltage close to the servo and see if it's dropping when the motor's on. Or maybe even try a second battery for the servo, just to test.)

Or, perhaps there is a lot of electrical noise around being picked up by the servo wires (less likely I think, but might be possible)

All just guessing...

Miranda
Posts: 1
Joined: Mon Jul 28, 2014 12:10 am

Re: Controlling DC motor and servo

Mon Jul 28, 2014 12:15 am

I am trying to implement a similar setup: controlling two dc motors with the L293D and a servo at the the same time. I am using the breakout cable and wiring everything through a breadboard at the moment. I am new to Raspberry Pi and electronics and would love to see how you wired your setup. Would you mind sharing?

Thanks,
Miranda

Return to “Troubleshooting”