User avatar
benderman
Posts: 15
Joined: Wed Dec 17, 2014 8:19 am

PWM to control a motor

Tue Jan 20, 2015 11:29 am

Hi all,

I have found various tutorials about how PWM works and I think I get it, so far so good.

What I am unsure of where PWM output from the Pi needs to be connected? Using a L293D chip to control a motor should the PWM output be connected to the motor enable (pin 1) on the chip or should both connections to the backward/forwards pins of the chip be the PWM outputs from the pi?

I'm sorry if this doesn't make sense but I am very new to all of this!

Thanks in advance.

Ben

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

Re: PWM to control a motor

Tue Jan 20, 2015 11:39 am

In QI terms, nobody knows (I'm sure they do).

If the chip documentation doesn't say to use one or the other then use either.

Also see http://www.raspberrypi.org/forums/viewt ... 37&t=90243

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

Re: PWM to control a motor

Tue Jan 20, 2015 11:42 am

there are multiple ways to approach PWM motor control depending on how many GPIO you wish to use (and how many you want to set as PWM).

Option 1:
3 GPIO control (of one motor)
PWM control of enable pin provides speed control
In1 and In2 control direction.

Option 2:
2 GPIO control (of one motor)
Link enable high
PWM on In1 and In2 control direction and speed

Option 3:
2 GPIO control (of one motor)
Link enable high
PWM on In1 controls speed
switching In2 controls direction.

Option 4:
1 GPIO control of one motor (one direction only)
Link enable high
PWM on In1 controls speed.
Last edited by BMS Doug on Tue Jan 20, 2015 12:07 pm, edited 1 time in total.
Doug.
Building Management Systems Engineer.

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

Re: PWM to control a motor

Tue Jan 20, 2015 12:04 pm

BMS Doug wrote: ...
Option 3:
2 GPIO control (of one motor)
Link enable high
PWM on In1 controls speed
switching GPIO 2 controls direction.

Option 4:
1 GPIO control of one motor (one direction only)
Link enable high
PWM on In1 controls speed.
Just goes to show.

I have never seen or thought of options 3 or 4 before.

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

Re: PWM to control a motor

Tue Jan 20, 2015 12:07 pm

joan wrote:
BMS Doug wrote: ...
Option 3:
2 GPIO control (of one motor)
Link enable high
PWM on In1 controls speed
switching In2 controls direction.

Option 4:
1 GPIO control of one motor (one direction only)
Link enable high
PWM on In1 controls speed.
Just goes to show.

I have never seen or thought of options 3 or 4 before.
I only saw option 3 the other day (on t'internet), option 4 was an obvious variant of 3 (but you could just use a transistor instead of a driver board).
(I edited 3 to show what I meant to write) :oops:
Doug.
Building Management Systems Engineer.

User avatar
benderman
Posts: 15
Joined: Wed Dec 17, 2014 8:19 am

Re: PWM to control a motor

Tue Jan 20, 2015 1:04 pm

That's been really helpful and kind of what I thought might be the case of multiple options. I'm going to go with the first option as it is the way that seems to fit well with tutorial.

I'll post to show how it goes!

Thanks guys.

Mark_T
Posts: 149
Joined: Sat Dec 27, 2014 10:54 am

Re: PWM to control a motor

Tue Jan 20, 2015 5:19 pm

There is a subtlety here that might be missed, and that's decay modes.

For accurate control of deceleration of a motor fast-decay mode is desirable,
and that means you don't just PWM one of the 4 switchs in an H-bridge, you
PWM all 4, which is equivalent to holding enable on and PWMing the
direction pin - but with the subtlety that 50% duty cycle is actually zero drive.

But fast decay mode isn't as efficient for normal running, slow decay mode
will suffice unless you are demanding a lot from the motor in dynamic performance
(being a high speed servo motor for instance). For the L293 slow decay mode
equals "PWM the enable"...

User avatar
benderman
Posts: 15
Joined: Wed Dec 17, 2014 8:19 am

Re: PWM to control a motor

Wed Jan 21, 2015 1:43 pm

These forums are great! thanks for the tips guys.

As a noob to all this stuff it really helps to make the learning curve a little shallower.

Return to “Automation, sensing and robotics”