How To: Use a L298N Dual H-Bridge with a Microcontroller (QuickStart Board)

13»

Comments

  • Duane DegnDuane Degn Posts: 10,348
    edited 2014-08-08 - 06:13:19
    tommy7575 wrote: »
    Will the regulator decrease voltage and will the motors get less voltage? Because I want to enable as much voltage as possible on the motors. I have baterry box 4 x AA(total 6V)

    Okay, I think I understand your concern now. Thanks for clarifying.

    No, using the regulator will not decrease the voltage to the motor. The L298N has two supply pins one supply is used to power the motors. This supply is taken directly from the Vin connection so it will supply the L298N with all 6V from your pack. The other power source the L298N needs is to control logic portion of the L298N. This logic source should be around 5V. To make it easier on the user, many L298N boards include a 5V regulator which takes the Vin and drops down to 5V but using the regulator does not change the voltage from going to the L298N motor power source.

    Do you have a separate power source for your Raspberry Pi? If so, I could see you may think by using 5V from the Pi, you could decrease the current used by the L298N board a little by disabling the 5V regulator and powering the logic portion from the Raspberry Pi board's 5V rail. I'm not sure if this would increase the power available to the motors a noticeable amount but it might slightly prolong the battery life of the 6V pack.

    As long as your motor supply voltage isn't much more than 14V, there really isn't a down side to using the on board 5V regulator to power the L298N's logic.

    What size of a robot are you using. Your four AA pack may work okay with a small robot, but if you're also using it to power the Raspberry Pi, the pack may have trouble providing enough current to both the motors and the Pi. You may find the Pi reseting as you apply power to the motors. I think there's also a danger of corrupting the contents of the SD card if the power drops while the SD card is being written to.
  • WhitWhit Posts: 4,143
    edited 2014-08-08 - 07:16:51
    The Raspberry Pi Guy's new video is here - https://www.youtube.com/watch?v=JJXzlCK4vnY&list=UUfY8sl5Q6VKndz0nLaGygPw

    He using a different motor controller now...

    In the comment section is this interesting exchange...

    photo.jpgBroProStudios
    3 hours ago
    Will this work with the L298N

    Reply

    View all 3 replies

    photo.jpgBroProStudios
    3 hours ago

    +TheRaspberryPiGuy I have the L289N Like this image http://batteriashopping.com/EBAY/ubeststore/EN00GG5004-1.jpgand know that i can control motors with it.

    Reply

    uFp_tsTJboUY7kue5XAsGA=s32Jim Darby
    2 hours ago (edited)

    +BroProStudios The problems with these boards is that they are very easy to wire up wrongly. For example, looking at your board from the link above I have a horrible suspicion that the link on its own connects the motor power to the chip and this can cause serious problems if it can get back to the Pi.

    So, if the link is in, as it is in the photo, you'll either power the motors from the Pi (bad) or the Pi from the motors (terrible).


  • tommy7575tommy7575 Posts: 3
    edited 2014-08-08 - 13:03:14
    What size of a robot are you using.
    https://www.ebay.com/itm/2WD-Motor-Smart-Robot-Car-Chassis-Kit-Speed-Encoder-Battery-Box-For-Arduino-1-48-/121312722516?pt=LH_DefaultDomain_0&hash=item1c3ecd3e54
    Do you have a separate power source for your Raspberry Pi?

    Yes I will use this voltage regulator and new battery pack 6V(4xAA battery).Is that a good idea, or do you have a better one?
    https://www.ebay.com/itm/DC-DC-Buck-Converter-Step-Down-Module-LM2596-Power-Output-1-23V-30V-2014-/301218533352?pt=LH_DefaultDomain_2&hash=item4622060fe8
  • Duane DegnDuane Degn Posts: 10,348
    edited 2014-08-08 - 13:23:15
    tommy7575 wrote: »
    Yes I will use this voltage regulator and new battery pack 6V(4xAA battery).Is that a good idea, or do you have a better one?

    A second battery pack with a regulator sounds like a good idea. Just make sure you adjust the regulator to 5V before you use it with the R Pi.

    The regulator you have for the Pi is more efficient than the L298N's on board regulator so in theory you'd get a bit more battery life by using 5V from pin #2 of the R Pi board to power the logic of the L298N but IMO, it's not worth the bother. The logic section of the L298N uses very little power so I don't think any difference in battery life would be noticeable.

    You do need to make sure both battery packs share a common ground connection.
  • GenetixGenetix Posts: 1,478
    edited 2014-08-08 - 13:51:59
    An old trick for powering logic chips from 6V (4 AA batteries) is to put a 1N400X diode in series with the batteries. The diode will drop the voltage about 0.7V.
  • Duane DegnDuane Degn Posts: 10,348
    edited 2014-09-04 - 17:14:46
    I've updated the code attached to post #2 to the latest version of this program.

    There was a bug in the program "TwoPwmCounters140709c", which prevented it from working correctly if any of the pins were set to -1.
    If any of you are using this previous version, make sure and switch to the latest code.

    The bug is fixed in the program I just uploaded (TwoPwmCounters140904a).

    I added several new features to the latest version of the code.

    New Feature #1:

    The program can now be used with a single motor by setting the constant "ENABLE_PIN_B" to -1.

    If used with a single motor, the maximum PWM possible is increased from 27,472Hz to 38,700Hz.

    Many h-bridges do not work well at very high PWM frequencies. Make sure and test your h-bridge/motor combination at the PWM frequency you plan to use before using the h-bridge/motor extensively. You may also want to experiment with various frequencies to fine frequencies which don't sound annoying.

    New Feature #2:

    The program no longer requires a direction pin to be assigned.

    To use the program without direction control (for example when controlling a motor with a transistor) set the first direction pin to -1. The first direction pin for motor A is "IN1_PIN". The first direction pin for motor B is "IN3_PIN".

    New Feature #3:

    The maximum PWM frequency is now listed when the resolution is changed. As with the previous version of the program, the frequency and resolution may be adjusted while the program and motors are running. The maximum possible frequency is dependent on the clock frequency of the Propeller and the resolution of the PWM signal. Very high PWM frequencies are not possible at very high resolution settings.

    The program will allow PWM frequencies above the highest possible at the current resolution but the program will warn the user the resolution is no longer valid.

    For example, with the Propeller running at 80MHz and the PWM frequency set to 20kHz, the maximum resolution possible is 4,000 (80,000,000Hz / 20,000Hz = 4,000). If the resolution were set to 10,000 the program would allow the change but it would also issue a warning indication the new resolution is not really possible but speed setting will still be issued by setting the speed to a value between -10,000 and 10,000.

    New Feature #4:

    The maximum resolution possible is listed when the PWM frequency is changed.

    New Feature #5:

    I added three schematics to the CON section of the program. One schematic shows how to use use a transistor to control a motor. Another schematic shows how to wire the L298D chip on the Propeller Professional Development Board for use with a single direction motor. The final schematic shows how to use the L298D on the Propeller Professional Development Board for bidirectional control of two motors.

    There are notes in post #2 about how to set the various I/O pins.
  • MohsenMawadMohsenMawad Posts: 4
    edited 2015-01-08 - 10:39:41
    i have a problem with my L298 .. only one motor is working and when i turn on the other ..i hear a weird beep sound from the L298 .. anyone ?
  • Duane DegnDuane Degn Posts: 10,348
    edited 2015-01-08 - 11:24:00
    i have a problem with my L298 .. only one motor is working and when i turn on the other ..i hear a weird beep sound from the L298 .. anyone ?

    A common problem when using h-bridges is using an inadequate battery.

    Please provide information about the motors you are using and the battery pack you are using. A picture of your setup would be very helpful.

    Have you tried controlling the motor with just the h-bridge? At the beginning of the video, I showed how to control the h-bridge by just setting the various pins high or low manually. Have you tried this? Have you tried it with two motors?
Sign In or Register to comment.