Searching \ for '[PIC]: Controlling two L298 Motor Drivers' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ios.htm?key=motor
Search entire site for: 'Controlling two L298 Motor Drivers'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Controlling two L298 Motor Drivers'
2005\11\11@213637 by James James

picon face
Hi everyone,

I am trying to control two L298 motor drivers (need 4 PWM outputs) from a PIC18F2620 MCU. However, the PIC only has 2 independent hardware PWM channels. Is there anyway to multiplex the 2 PWM channels to 4 independent PWM channels? Is there any other PIC that has 4 (or more) independent PWM channels?  Thanks!
               
---------------------------------
Yahoo! FareChase - Search multiple travel sites in one click.  

2005\11\11@232527 by Andrew Kieran

picon face

James,
I'm working on a similar project right now (using discrete
MOSFETS rather than the L298).  The current version runs fine on
the breadboard, but I can't say it's a tested, finished,
approach.

I'm using two PWM channels and some 74HCxx glue logic to take
one PWM signal for each motor and apply it to the correct
high/low MOSFET combination.  

In the first version, I used two control lines; F
(forward/!forward) and E (Enable/Disable drivers -- the PWM
pulses).

Looking at one channel (one motor) an H-Bridge could be labelled
as follows:

A      B
|      |
+-M  M-+
|      |
C      D


The truth table is
F E   A B C D
0 0   0 1 0 0
0 1   0 1 1 0
1 0   1 0 0 0
1 1   1 0 0 1

The latest version adds an active brake control signal, "B".
When B is zero, it has no effect.  When it's a one, A and B are
off and C and D are on. (Yes, I'm using kickback protection
diodes).

I am a tinkerer, not an Electrical Engineer so I don't know if
this the best solution, or even if it's a good one.  As always,
I hope to learn from the feedback on this list.

Andrew


________________________________________________
Get your own "800" number
Voicemail, fax, email, and a lot more
http://www.ureach.com/reg/tag


---- On Fri, 11 Nov 2005, James James (spam_OUTjames_iboxTakeThisOuTspamyahoo.com)
wrote:

> Hi everyone,
>
> I am trying to control two L298 motor drivers (need 4 PWM
outputs) from a PIC18F2620 MCU. However,
> the PIC only has 2 independent hardware PWM channels. Is there
anyway to multiplex the 2 PWM channels
> to 4 independent PWM channels? Is there any other PIC that has
4 (or more) independent PWM channels?
> Thanks!
>                
> ---------------------------------
>  Yahoo! FareChase - Search multiple travel sites in one click.

> --

2005\11\12@002548 by William Chops Westfield

face picon face
On Nov 11, 2005, at 8:25 PM, Andrew Kieran wrote:

>> I am trying to control two L298 motor drivers (need 4 PWM outputs)
>> from a PIC18F2620 MCU. However,the PIC only has 2 independent
>> hardware PWM channels.
>
> I'm using two PWM channels and some 74HCxx glue logic to take
> one PWM signal for each motor and apply it to the correct
> high/low MOSFET combination.
>
I didn't look at Andrew's design in detail, but he certainly has
the right idea.  If you have two motors, you only need two PWM
channels; you don't need to PWM both sides of each motor...

BillW

2005\11\14@061416 by Alan B. Pearce

face picon face
>I am trying to control two L298 motor drivers (need
>4 PWM outputs) from a PIC18F2620 MCU. However, the
>PIC only has 2 independent hardware PWM channels.
>Is there anyway to multiplex the 2 PWM channels to
>4 independent PWM channels?

Not that would maintain a continous PWM stream.

>Is there any other PIC that has 4 (or more)
>independent PWM channels?  Thanks!

Look at some of the dsPic chips. I think some of the 18F may also, but I
believe you can only use these for motor driving, and not as independent
channels. The dsPic ones seem to be able to have multiple independent
channels.

another route would be Scotts software PWM that is on the Piclist.com site.

2005\11\14@063922 by Gerhard Fiedler

picon face
Alan B. Pearce wrote:

>> Is there any other PIC that has 4 (or more) independent PWM channels?
>
> I think some of the 18F may also, but I believe you can only use these
> for motor driving, and not as independent channels.

There are a number of PICs with 4 and more semi-independent PWM channels.
Look for numbers of (E)CCP modules. They are independent in that you can
run every (E)CCP module with a different duty cycle, but they are not fully
independent in the selection of PWM frequencies -- you only have one or at
most two different frequencies. (The 18F6722 is one with 5 (E)CCP channels
that can be driven from two different timer sets.)

But as others have said before, for two motors you only need two PWM
channels, a few standard digital outputs (for direction and possibly
breaking) and a bit of glue logic.

Gerhard

2005\11\15@013239 by James James

picon face
Thank you everyone for your reply.  I just want to
clarify that the L298 is a DUAL Full-Bridge driver.
Driving 2 of them means I need 4 PWM channels.  All
channels can be at the same frequency, as long as I
can vary the duty cyle for each channels.  I think I
am going to use the PIC18F4431 since it also have a
Quadrature Encoder Interface (QEI).  Too bad it has
only one QEI.  I need two!

Is the frequency for the PWM matter?  Is there a "rule
of thump" on what frequency is good?  Since I am
running the PIC at 40Mhz, it looks like 2.4Khz is the
slowest it will go.
Regards,

--- Gerhard Fiedler <.....listsKILLspamspam@spam@connectionbrazil.com>
wrote:

{Quote hidden}

> --

2005\11\15@024621 by Julio Jumpa

picon face
Hi,
You can generate many PWM channels with any PIC that can provide a regular
interruption.
For example, if you set an interruption every 8us and have a variable (say
T) that increments on each interrupt and resets when it gets to 63 you will
have a period of about 2KHz.
If you want 4 PWM channels you would need 4 extra counting variables.
So, the idea is to set all the PWMs high each time T resets and set them
down independently according to the desired duty cycle.
The code in C would look something like this:
void periodic_interrupt (void) {
T++; U1++; U2++; U3++; //increment counters
 if (T>=63) {
T=0; U1=0; U2=0; U3=0; //clear counters
PWM1=1;PW2=1;PW3=1; //set pwm outputs high
}
if (U1>=DC1) { //DC1 is where you save the desired duty cycle
PWM1=0;
U1=0;
}
....and so on
 Julio


2005/11/15, James James <james_iboxspamKILLspamyahoo.com>:
{Quote hidden}

> > --

2005\11\15@055817 by Gerhard Fiedler

picon face
James James wrote:

> Thank you everyone for your reply.  I just want to clarify that the L298
> is a DUAL Full-Bridge driver. Driving 2 of them means I need 4 PWM
> channels.  

I'm not sure, and please excuse me if I'm wrong, but I don't think you
understood the suggestions about how to reduce the number of PWM channels
required.

The pairs of inputs for each channel are not driven independently. In
normal PWM operation, one is the inverse of the other. Look at figure 6 in
http://www.st.com/stonline/products/literature/ds/1773.pdf, for example. It
is easier to provide this type of encoding with hard-wired logic (or a
CPLD) than with the PIC's CCP modules. It would have one PWM input, an
enable and possibly a break input, and two outputs for the driver inputs,
and in between a few gates.

To me, it seems that providing the required signals using the PIC's CCP
modules is not exactly easy: they are designed to set their outputs all
high at the same time. (The, or maybe some, ECCP modules have a polarity
selection, but not the CCP modules.)


> Is the frequency for the PWM matter?  Is there a "rule of thump" on what
> frequency is good?  Since I am running the PIC at 40Mhz, it looks like
> 2.4Khz is the slowest it will go.

The driver seems to be fast enough for that frequency. Given that, this
depends probably mostly on your motor. Normal DC motors seem to run fine
with this frequency.

Gerhard

2005\11\15@061321 by Jan-Erik Soderholm

face picon face
James James wrote:

> Is the frequency for the PWM matter?

Higher pwm freq usualy also means higher
power loss in the switching mosfet's. Depends
to some degree on how hard/fast they are driven.
Note that the special "mosfet-drivers" often can
supply short bursts of 1-2 A to make the
driven power mosfet switch as fast as possible.

Jan-Erik.



2005\11\15@072430 by Alan B. Pearce
face picon face
>It is easier to provide this type of encoding with hard-wired
>logic (or a CPLD) than with the PIC's CCP modules.

I seem to remember that some of the CCP modules can provide the
complementary outputs, with a dead time set up between the two outputs. This
may require the ECCP module.

2005\11\15@094514 by Mike Young

picon face
From: "Gerhard Fiedler" <EraseMElistsspam_OUTspamTakeThisOuTconnectionbrazil.com>


> James James wrote:
>
>> Thank you everyone for your reply.  I just want to clarify that the L298
>> is a DUAL Full-Bridge driver. Driving 2 of them means I need 4 PWM
>> channels.

I missed the preceding discussion, so don't know what was suggested. You can
drive each half using just one PWM per bridge. Modulate the enable line with
PWM, while holding steady levels on the two In pins. The In pins select
direction, while Enable modulates speed. That's two digital output lines per
bridge, plus one PWM line.

I find it odd that the Fig. 6 truth table is set up that way. Enable would
be more sensibly useful as a current sense limiter, except modulating the In
lines would cause braking rather than free-wheel coasting during the off
periods. Ick.

{Quote hidden}

I wouldn't bother putting gates in there for that. You still need a third
state for braking, so it needs a second digital line for full control
anyway.

> To me, it seems that providing the required signals using the PIC's CCP
> modules is not exactly easy: they are designed to set their outputs all
> high at the same time. (The, or maybe some, ECCP modules have a polarity
> selection, but not the CCP modules.)

ECCP doesn't add much for Fig. 6 control. Full-bridge mode can drive the
L298 In lines for direction control, but you would need an OR or XOR gate to
modulate the B-D lines on the Enable pin. The only real gain is using the
auto-shutdown comparators as a current limiter. Alas, I don't believe any of
any mid-range or 18F come with dual ECCPs, at most one each of the enhanced
and regular.

To conclude, I think all you need is two independent, plain, ordinary CCPs.
Each PWM line modulates the Enable line on one channel for speed control.
You'll control the In lines directly for direction and braking.

2005\11\15@232337 by James James

picon face
Thanks again for everyone help.  I think I got many of
you confused.  I am sorry about that.  What I meant
was I want to drive two L298 ICs, so that's 4
full-bridges in total.

Mike Young wrote: “I missed the preceding discussion,
so don't know what was suggested. You can drive each
half using just one PWM per bridge …”

James: Yes, but I am using TWO L298 ICs and each IC
has two full-bridges.  So the total is “4 half”, which
means I will need 4 PWM channels, right?

Julio Jumpa wrote: “you set an interruption every
8us…”

James:  This would work, but the PIC will have to
spend a lot of time servicing the interrupts.  It
might not have enough time to update the LCD, read
encoder, do some math, serial comm, etc.  I am
thinking of a dedicated PIC just to drive the two L298
ICs…

--- Mike Young <mikewhyspamspam_OUTsbcglobal.net> wrote:

{Quote hidden}

www.st.com/stonline/products/literature/ds/1773.pdf,
{Quote hidden}

> -

2005\11\16@012344 by Mike Young

picon face
----- Original Message -----
From: "James James" <KILLspamjames_iboxKILLspamspamyahoo.com>
> Mike Young wrote: "I missed the preceding discussion,
> so don't know what was suggested. You can drive each
> half using just one PWM per bridge ."
>
> James: Yes, but I am using TWO L298 ICs and each IC
> has two full-bridges.  So the total is "4 half", which
> means I will need 4 PWM channels, right?

That's right, one PWM for each bridge. Four bridges, four PWM. Four
independent PWM if you're controlling 4 motors. You can use fewer if you're
controlling, say, two steppers instead.

> Julio Jumpa wrote: "you set an interruption every
> 8us."
>
> James:  This would work, but the PIC will have to
> spend a lot of time servicing the interrupts.  It
> might not have enough time to update the LCD, read
> encoder, do some math, serial comm, etc.  I am
> thinking of a dedicated PIC just to drive the two L298
> ICs.

I keep a small bag of 12F683 and 16F690 around, like jelly-beans. I wouldn't
think twice about putting one 12F per bridge on the board. But with all that
going on, I'd seriously consider an AVR or ARM. The ATmega169 has dedicated
LCD control, USART, 4 PWM channels, probably enough ADC, and one instruction
per clock compared to PIC's 4 Tosc. The Butterfly eval board is $20, and
comes with a '169 and LCD panel. If you like C, you'll find free GCC based
tools, a nice change from the pay-in-blood PIC world. The serial ISP is $30;
a soon to be released USB ISP is expected to be a few dollars more. It only
comes in a 64 pin TQFP, which is either a deal breaker or a likable bonus.
(If you don't already etch your own boards, maybe it's time to start
thinking about it.)

More... (looser matching)
- Last day of these posts
- In 2005 , 2006 only
- Today
- New search...