User avatar
Siwan
Posts: 26
Joined: Wed Apr 16, 2014 7:28 pm
Location: Netherlands

DC motor control help

Mon Jul 28, 2014 10:37 pm

Hello everybody,

sorry if this has been posted already, I've done my best to search for my answers, but couldn't find it :(.

I'm planning on buying a L239D motor controller to drive my two DC motors.
I've bought a car chassis like this one here:

http://www.robotshop.com/en/mini-robots ... s-kit.html

And this is the datasheet for the DC motors that come with it:

http://www.pololu.com/file/download/fa_ ... le_id=0J11

They have an operating voltage of 1.5 ~3 volt, so do I need to power the L239D motor controller's VS with an external power supply of 1.5 ~ 3 volt or can I just my batteryholder consisting of 4 AA batteries? My battery holder gives off 6 volt (5.2V when the batteries are recharged.)
I read that if you supply a DC motor more voltage than its operating voltage you can reduce its lifetime and I don't want that to happen.

Thanks in advance if anyone can help me!

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

Re: DC motor control help

Mon Jul 28, 2014 10:49 pm

Why not just put two batteries in the battery holder for the 3 volts you need? You could put two dummy batteries in.

You'd need to check that the L293D can drive motors as low as 1.5-3V.

User avatar
Siwan
Posts: 26
Joined: Wed Apr 16, 2014 7:28 pm
Location: Netherlands

Re: DC motor control help

Mon Jul 28, 2014 10:57 pm

joan wrote:Why not just put two batteries in the battery holder for the 3 volts you need? You could put two dummy batteries in.

You'd need to check that the L293D can drive motors as low as 1.5-3V.
oh that might be a possibility.

Also, I just found out this.
http://www.pololu.com/product/61

This is the site where I got that datasheet, but the description said this:
The two low-voltage motors run on 3-6 volts and draw up to a few amps
So now I don't which information is consistent anymore. : /

Thanks for helping me out

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

Re: DC motor control help

Tue Jul 29, 2014 6:10 am

They seem to sell more than one set of motors for the kit.

I don't like the sound of a couple of amps. Batteries won't last long.

Personally I'd just drive the motors from 6V anyhow, but use PWM to keep the effective voltage down to 3V (so PWM with 50% dutycycle).

Duane Degn
Posts: 55
Joined: Thu Jul 10, 2014 6:30 am
Location: Idaho, USA

Re: DC motor control help

Tue Jul 29, 2014 7:30 am

Siwan wrote: They have an operating voltage of 1.5 ~3 volt, so do I need to power the L239D motor controller's VS with an external power supply of 1.5 ~ 3 volt or can I just my batteryholder consisting of 4 AA batteries? My battery holder gives off 6 volt (5.2V when the batteries are recharged.)
The L293D needs at least 4.5V for both the logic power and motor power. I think you're 4AA would work fine. The L293D will drop the voltage down by 1.4V or more so your 5.2V pack will only deliver 3.8V to the motors. If you're worried about the voltage being higher than 3V you can limit the PWM duty cycle as Joan suggested. Since you're only dealing with 3.8V to the motor, an 80% duty cycle would probably be safe.

Running the motor at full 100% duty cycle would likely shorten the life of the motor. Pololu sells lots of little motors. I bet they sell a replacement motor which would work well at a higher voltage.

You should only draw 600mA continuous current from a L298D. If you haven't already purchased the L298D, you might want to consider a different motor driver.

User avatar
Siwan
Posts: 26
Joined: Wed Apr 16, 2014 7:28 pm
Location: Netherlands

Re: DC motor control help

Tue Jul 29, 2014 10:29 am

Duane Degn wrote:
Siwan wrote: They have an operating voltage of 1.5 ~3 volt, so do I need to power the L239D motor controller's VS with an external power supply of 1.5 ~ 3 volt or can I just my batteryholder consisting of 4 AA batteries? My battery holder gives off 6 volt (5.2V when the batteries are recharged.)
The L293D needs at least 4.5V for both the logic power and motor power. I think you're 4AA would work fine. The L293D will drop the voltage down by 1.4V or more so your 5.2V pack will only deliver 3.8V to the motors. If you're worried about the voltage being higher than 3V you can limit the PWM duty cycle as Joan suggested. Since you're only dealing with 3.8V to the motor, an 80% duty cycle would probably be safe.

Running the motor at full 100% duty cycle would likely shorten the life of the motor. Pololu sells lots of little motors. I bet they sell a replacement motor which would work well at a higher voltage.

You should only draw 600mA continuous current from a L298D. If you haven't already purchased the L298D, you might want to consider a different motor driver.
Oh I see, thanks.

Is it possible to limit the current from the motors by using PWM or is it wrong what I'm saying?
I haven't bought an L293D yet, but I do have an L298N in house, but it's not the same model as the other ones I have seen here:

http://www.robotshop.com/en/l298-dual-h ... oller.html

I haven't got the balls yet to wire this up as I'm scared something will happen.
I need to do a lil bit more research on that :p

Cheers

BMS Doug
Posts: 3823
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: DC motor control help

Tue Jul 29, 2014 11:06 am

Siwan wrote:
Oh I see, thanks.

Is it possible to limit the current from the motors by using PWM or is it wrong what I'm saying?
I haven't bought an L293D yet, but I do have an L298N in house, but it's not the same model as the other ones I have seen here:

http://www.robotshop.com/en/l298-dual-h ... oller.html

I haven't got the balls yet to wire this up as I'm scared something will happen.
I need to do a lil bit more research on that :p

Cheers

that's a sweet looking L298N, I love the black colour.
The bottom picture from the list tells you all you need to know about how to connect to the board.
It has a nice selector switch (blue) to choose whether to power the board from an external 5v or its internal voltage regulator (as you want to use 3V to run the motors you will need to provide the 5V from the Pi)

the enable pins are shown as jumpered to 5V, if you want to control the enable then remove the jumper and connect a GPIO to that pin. (only needed if you are controlling the speed by PWM).
Doug.
Building Management Systems Engineer.

User avatar
Siwan
Posts: 26
Joined: Wed Apr 16, 2014 7:28 pm
Location: Netherlands

Re: DC motor control help

Tue Jul 29, 2014 2:23 pm

Oh nice, did not see that. Thanks man.
It has a nice selector switch (blue) to choose whether to power the board from an external 5v or its internal voltage regulator (as you want to use 3V to run the motors you will need to provide the 5V from the Pi)
So if I understand correctly, I don't need to wire the Vin and +5V both at the same time?
If so, then I just need to find out which switch state belongs to Vin and +5V.

Btw I must not connect any GPIO to the 5V pins right? (Need to make sure again, before doing anything.)

Also, one last thing, this H-bridge has a motor supply of 7~24VDC, what can happen if I supply anything below the 7V?
Last edited by Siwan on Tue Jul 29, 2014 10:56 pm, edited 1 time in total.

BMS Doug
Posts: 3823
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: DC motor control help

Tue Jul 29, 2014 3:19 pm

Siwan wrote:
the enable pins are shown as jumpered to 5V, if you want to control the enable then remove the jumper and connect a GPIO to that pin. (only needed if you are controlling the speed by PWM).
Oh nice, did not see that. Thanks man.
It has a nice selector switch (blue) to choose whether to power the board from an external 5v or its internal voltage regulator (as you want to use 3V to run the motors you will need to provide the 5V from the Pi)
So if I understand correctly, I don't need to wire the Vin and +5V both at the same time?
If so, then I just need to find out which switch state belongs to Vin and +5V.

Btw I must not connect any GPIO to the 5V pins right? (Need to make sure again, before doing anything.)

Also, one last thing, this H-bridge has a motor supply of 7~24VDC, what can happen if I supply anything below the 7V?
I think that the 7-24VDC is needed for the on-board switching power supply to make the required 5V operating voltage needed to run the board, you can switch the board to use a separate 5V supply if Vin is outside of the 7-24VDC range. This is what the 5V terminal is for. In this application we can connect the RPi 5V GPIO to this terminal (as we are using the 5V from the Pi to power the board).

Your Battery Pack connects to the Vin (3v for 2AA cells) which will be used as the power for the motors. I'm pretty sure that this arrangement will work.
Doug.
Building Management Systems Engineer.

User avatar
Siwan
Posts: 26
Joined: Wed Apr 16, 2014 7:28 pm
Location: Netherlands

Re: DC motor control help

Tue Jul 29, 2014 5:27 pm

ok ok I see.

so if I understand correctly, I need to use pin 2 and connect it to the +5V.
(I also need to supply the ENA en ENB with 5V, I can also do that with pin 2 afaik)
Vin is the supply for the motors. Afaik I read somewhere that the L298N drops the voltage down by 2.5V or something close to this. So I can probrably use all my 4AA which provide 6V - 2.5V = 3.5V to the motors or 5.2V - 2.5V = 2.7V which is perfect.

BMS Doug
Posts: 3823
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: DC motor control help

Wed Jul 30, 2014 8:28 am

Siwan wrote:ok ok I see.

so if I understand correctly, I need to use pin 2 and connect it to the +5V.
Yes.

Siwan wrote:(I also need to supply the ENA en ENB with 5V, I can also do that with pin 2 afaik).
No, just leave the jumper on if you want to have them enabled all the time, or you can use PWM from a Pi GPIO for speed control.
(PWM is pulse width modulation, rapidly turning the output on and off)
Siwan wrote:Vin is the supply for the motors.

Yes.
Siwan wrote:Afaik I read somewhere that the L298N drops the voltage down by 2.5V or something close to this. So I can probrably use all my 4AA which provide 6V - 2.5V = 3.5V to the motors or 5.2V - 2.5V = 2.7V which is perfect.
I'm not sure about this.
Last edited by BMS Doug on Wed Jul 30, 2014 9:11 am, edited 1 time in total.
Doug.
Building Management Systems Engineer.

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

Re: DC motor control help

Wed Jul 30, 2014 8:38 am

Siwan wrote:Afaik I read somewhere that the L298N drops the voltage down by 2.5V or something close to this. So I can probrably use all my 4AA which provide 6V - 2.5V = 3.5V to the motors or 5.2V - 2.5V = 2.7V which is perfect.
Well I've used the smaller L293D and it loses (very approximately) 2 Volts. That is the voltage actually fed to the motors is a few volts lower than the supply you feed to the motors and drivers. (The waste effectively becomes heat in the driver chip itself.)

So with yours you will probably find the same thing. I doubt the motors are that demanding though - they will probably be fine with something reasonably close to the voltage that's stated.

User avatar
Siwan
Posts: 26
Joined: Wed Apr 16, 2014 7:28 pm
Location: Netherlands

Re: DC motor control help

Wed Jul 30, 2014 4:41 pm

No, just leave the jumper on if you want to have them enabled all the time, or you can use PWM from a Pi GPIO for speed control.
(PWM is pulse width modulation, rapidly turning the output on and off)

My thoughts exactly when I gave it some more thought yesterday.
One last thing about the PWM, I thought you should use PWM on the IN pins only and not the EN pins or am I reading wrong?

I saw a video of Gaven Macdonald doing this, but then on the L239D, so I thought it might be the same with the L298N.

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

Re: DC motor control help

Wed Jul 30, 2014 5:19 pm

Siwan wrote:
No, just leave the jumper on if you want to have them enabled all the time, or you can use PWM from a Pi GPIO for speed control.
(PWM is pulse width modulation, rapidly turning the output on and off)

My thoughts exactly when I gave it some more thought yesterday.
One last thing about the PWM, I thought you should use PWM on the IN pins only and not the EN pins or am I reading wrong?

I saw a video of Gaven Macdonald doing this, but then on the L239D, so I thought it might be the same with the L298N.
You can vary the motor speed by using PWM on the EN pin or the IN pins.

Case 1: If you use the EN pin you need to use three gpios per motor (EN, IN1, IN2).

Case 2: If you strap EN high you need to use two gpios per motor (IN1, IN2).

In case 1 you may vary the motor speed by varying PWM on EN or by using PWM on the IN pins. 1 or 3 PWM capable gpios required.

In case 2 you vary the motor speed by varying PWM on IN1 or IN2. 2 PWM capable gpios required.

There may be times when case 1 or 2 is better than the other. I expect those cases are outside most hobbyist usage.

Duane Degn
Posts: 55
Joined: Thu Jul 10, 2014 6:30 am
Location: Idaho, USA

Re: DC motor control help

Wed Jul 30, 2014 5:44 pm

joan wrote: There may be times when case 1 or 2 is better than the other. I expect those cases are outside most hobbyist usage .
I'm hesitant to disagree with Joan, but I would say the following is more true. Edit: I see I was disagreeing about the wrong thing. I do think the difference is significant enough for hobbyists to worry about it. See final edit below. Sorry for not reading correctly.)

There may be times when case 2 is better than case 1. I expect those cases are outside most hobbyist usage.
Edit: I need to take the time to read posts more carefully.

I encourage people to try comparing the two ways for themselves. I've done such a comparison and the difference was dramatic. (I think the difference is more noticeable with a load on a geared down motor.)

I hope you don't mind Siwan if I reply to your PM here. I don't like to give help over a PM since then there wouldn't be a way for someone to suggest a better alternative. I also like in the forum, a single reply can help multiple people.

I didn't understand your question about the 5V or 3.3V rail. You shouldn't need to power the L298N from the R Pi at all.

I'm not exactly sure what you asked about the grounds either. The ground of the L298N and the ground of the R Pi need to be connected. You don't want the current flowing through the (L298N and motor) passing through the Raspberry Pi board. There should be a path back to the battery's ground (from the motor) which doesn't pass though the Raspberry Pi board.

Edit: The PM was about the L298N but this thread appears to be about the L293D. The control logic is the same for both chips but my answer above assumed a L298N PCB was used similar to the one shown in this video.

Edit again: I need to read more carefully. I see Joan wasn't saying one case was better than the other but I am. IMO (and in my experience), there's a dramatic performance difference between pulsing the enable pin (good performance) and pulsing the IN pin (bad performance). Pulsing the IN pins is like slamming on the brake with each low pulse. Try the two ways while monitoring the current. I think those who put the two types of pulsing to the test, will join me in singing the praises of pulse/coast over pulse/brake. On my motor, pulsing the IN pins sounded horrible (at 200Hz PWM).
Last edited by Duane Degn on Wed Jul 30, 2014 10:15 pm, edited 5 times in total.

User avatar
Siwan
Posts: 26
Joined: Wed Apr 16, 2014 7:28 pm
Location: Netherlands

Re: DC motor control help

Wed Jul 30, 2014 6:05 pm

Ok I'll go test the two cases when I've got the time.
I hope you don't mind Siwan if I reply to your PM here.
Oh that's no problem at all.
I didn't understand your question about the 5V or 3.3V rail. You shouldn't need to power the L298N from the R Pi at all.
On that was about the EN pins, but I have those jumpers which I can leave there to keep the EN pins powered.
About the "You shouldn't need to power the L298N from the R Pi at all.", that is only the case when that jumper is still on the L298N right? I've got a different model which has a switch. If closed then the terminal'll provide 5V, else you need to supply it with 5V which come from the Pi afaik.

Return to “Beginners”