go_away

Author Topic: PWM with H-brigde L298  (Read 13036 times)

0 Members and 1 Guest are viewing this topic.

Offline BANETopic starter

  • Supreme Robot
  • *****
  • Posts: 639
  • Helpful? 4
  • E=roboticsC^2
PWM with H-brigde L298
« on: April 30, 2009, 04:00:53 PM »
Hello,

So i have an L298 from solarbotics that I'm screwing around with before doing my homework.  To get the motors to work i have to P0 high and P1 low and of course enable is powered.  I was thinking if i were to set P1 to low and then P0 to pulseout just like a servo, could i have the speed vary just like a continuous rotation servo?  I know i can have a "For and Next" code to toggle the P1, but it seems to choppy.  How do you guys control your DC motor's speed?

bane

found this
Quote
Subject: [DPRG] PWM & L298 Problems
From: Rick J. Bickle rbickle at swbell.net
Date: Tue Aug 10 17:58:29 CDT 2004

Farhan,

The PWM frequency you use should not be critical to the operation of
your robot. Most hobby type PWM controllers use freqencies as low as 100
Hz. More sophisticated controllers use freqencies above 15KHz, so that
humans cannot hear it. I would refrain from using anything much higher
than this, as you will get more transistor heating and switching losses,
without any gain in performance. At 100KHz, the sound you were hearing
was probably a harmonic generated by the motor windings.

The L298 is a bipolar transistor device, but has internal transistor
drivers. The inputs should be compatible with any TTL logic. For an
H-bridge configuration, you can put flyback diodes from each motor lead
to Vcc and to GND in reverse bias. The higher speed the better, but
remember that Schottky diodes cannot handle as much current as silicon
diodes.

-Rick
« Last Edit: April 30, 2009, 04:24:55 PM by BANE »

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,121
  • Helpful? 108
Re: PWM with H-brigde L298
« Reply #1 on: April 30, 2009, 06:36:55 PM »
PWM.

Sorry - short answer !
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline BANETopic starter

  • Supreme Robot
  • *****
  • Posts: 639
  • Helpful? 4
  • E=roboticsC^2
Re: PWM with H-brigde L298
« Reply #2 on: May 01, 2009, 07:06:28 AM »
So can you do PWM with a standard H-bridge?  Or is the quote i found true and it can't be done with the L298?

Bane

Offline ArcMan

  • Supreme Robot
  • *****
  • Posts: 519
  • Helpful? 4
  • Mmmm... Plasma
Re: PWM with H-brigde L298
« Reply #3 on: May 01, 2009, 03:14:42 PM »
The quote you found is true and accurate, but it does not say that you can't use PWM.  It was a discussion of PWM frequency.  The L298 can drive variable motor speed given PWM input - the greater the duty cycle of the PWM, the greater the motor speed.  I typically use a 20 kHz PWM frequency.

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,121
  • Helpful? 108
Re: PWM with H-brigde L298
« Reply #4 on: May 02, 2009, 11:40:23 AM »
Any h-bridge can cope with PWM. They have a digital input to set either 'stop' or 'full speed' (ignoring braking for now...). So PWM is just flicking between these two states very quickly. The duty cycle refers to how long you stay in the 'full speed' state. So varying the duty cycle will vary the speed of the motor.

If your PWM frequency is too low - then you may get some 'hum' from the motor. If your frequency is too high then the switching transistors may not be able to switch that fast
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: PWM with H-brigde L298
« Reply #5 on: May 02, 2009, 04:57:29 PM »
Hi,

So can you do PWM with a standard H-bridge?  Or is the quote i found true and it can't be done with the L298?
Just PWM pins 6 and 11 (Enable pins) on th L298.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline BANETopic starter

  • Supreme Robot
  • *****
  • Posts: 639
  • Helpful? 4
  • E=roboticsC^2
Re: PWM with H-brigde L298
« Reply #6 on: May 03, 2009, 05:47:55 AM »
thanks guys.  I'm currently programming in basic and i just found that it already has a code for PWM.  Before i was just toggling between low and high which seemed to work but not nearly as smooth as the PWM.
Code: [Select]
counter var byte
r_duty var byte
counter = 0
r_duty = 50

LOW 0
LOW 1
LOW 4

PAUSE 1000
high 4

'PROGRAM START
dutycycle_loop
for counter = 0 to 205
r_duty = r_duty + 1
gosub generate
next
high 0



pause 1000
for counter = 0 to 205
r_duty = r_duty - 1
gosub generate
next

goto dutycycle_loop

generate
pwm p0, r_duty, 50000
return

One thing that i did notice is that even when duty is 100% the motors are not pulling maximum speed, and not really even close, more like 80%.  Is the only way to get 100% of motor power to set p0 to high and p1 to low?

Bane

Offline ArcMan

  • Supreme Robot
  • *****
  • Posts: 519
  • Helpful? 4
  • Mmmm... Plasma
Re: PWM with H-brigde L298
« Reply #7 on: May 04, 2009, 01:46:02 PM »
You're seeing the effect of the L298's transistors.  They have a voltage drop of ~ 0.7V each for a total voltage drop of about 1.4V to your motor.  If you want your motor to see full speed, use a MOSFET H-bridge like a LMD18201.

 


Get Your Ad Here