Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: jim on April 22, 2013, 11:42:45 AM

Title: L298N motor driver
Post by: jim on April 22, 2013, 11:42:45 AM
hi.. I want to clarify something. I recently made this circuit in the below link. http://www.instructables.com/file/FT8ERG4GYVDJSP8 (http://www.instructables.com/file/FT8ERG4GYVDJSP8)

unfortunately it is not working and i guess something is wrong.. i have a doubt regarding the two pins 9 and 4.. i think it has been interchanged in the circuit... because the datasheet of L298 says that pin 4 is for supply and pin 9 for logic. Also the Vc +5V is being connected to the ground in this link.. I guess this is the mistake why the circuit is not working. Could anyone please tell me whether I am correct or wrong..?? thank you
Title: Re: L298N motor driver
Post by: jkerns on April 22, 2013, 11:54:15 AM
Something is wrong with your schematic and the VS  connection - you show your Vc+5v connected directly to ground and a capacitor in series with the supply which will block the current to your chip.

Edit - re-reading, I see you asked about this.

It will not work as drawn. The voltage source needs to be on the other side of the capacitor - directly to pin 4.

As far as pins being mixed up - pin 9 should be the same 5V as your chip. Pin 4 should be the motor supply voltage - does the label on the drawing Vc+5v mean that it is at 5V or that it is 5V more than Vcc?
Title: Re: L298N motor driver
Post by: jkerns on April 22, 2013, 11:56:01 AM
Also, you don't need the 22 ohm resistors unless you plan on measuring the current. Those pins can be connected directly to ground. Putting the 22 ohms in series with your motor supply will reduce the performance.

And, are 'Vmotor" and "Vcc+5" the same voltage source? They should be.
Title: Re: L298N motor driver
Post by: Duane Degn on April 22, 2013, 04:06:34 PM
That schematic sure has some problems.

Pin 9 is the logic power supply. This is usually 5V. 4.5V to 7V is the allowed range for the logic supply. (The datasheet calls this Vss which can be confusing since Vss is often ground.)

Pin 4 is the motor power supply. This needs to be at least 2.5V higher than the logic power supply (so at least 7.5V if using 5V for the logic power supply). 12V seems to be a common motor power supply value. It can be as high as 46V.

There are lots of cheap L298 boards on ebay. I have a bunch from this seller.

http://www.ebay.com/itm/L298N-DC-Stepper-Motor-Dual-H-Bridge-Drive-Controller-Board-Module-for-Arduino-/140895190441 (http://www.ebay.com/itm/L298N-DC-Stepper-Motor-Dual-H-Bridge-Drive-Controller-Board-Module-for-Arduino-/140895190441)

I have had to resolder some of the connectors but in general these cheap boards seem to work well.
Title: Re: L298N motor driver
Post by: jim on April 23, 2013, 04:14:07 AM
thanx.. i made a few changes. im not using those sense resistors as your advice..well i am using arduino and i powering it with 9 V battery. my motors are 5V.. im using a voltage regulator (7806) to supply the 6v to the motors. my question is pin 4 being connected to the REGULATED voltage (6V) is correct or wrong?

Also i read in one the SOR tutorials that a capacitor being connected to the two terminals of each of the motors  will increase their lifetime.. So what capacitor should I use? I guess it is an electrolytic capacitor..Please tell me the most suitable  value for it..

thank you..
Title: Re: L298N motor driver
Post by: jkerns on April 23, 2013, 11:52:07 AM
Right Pin 4 is the source of current / voltage to run the motor. In your case that would be the 6V supply.

Pin 9 is the logic supply - that would typically be the 5V or 3.2V regulated logic power from your Arduino.

Note - from the data sheet
Symbol     Parameter                 Test Conditions            Min.        Typ. Max. Unit
VS            Supply Voltage (pin 4) Operative Condition    VIH +2.5        46       V

The supply voltage needs to be 2.5V higher than your logic high values (pins 5, 7, 10, 12) If you are using 6V to supply the motors, then you would want these voltages to be down at the 3.5V range (minimum voltage on these pins is 2.3V) . If your Arduino is kicking out 5V on the digitial outputs you could put a voltage divider in the connection between the Arduino and the L298N. Also, it doesn't hurt to put 10K or so between the L298 and the Arduino so when you let the smoke out of the L298 you don't take the Arduino with it. So, to do the voltage divider from 5 volts it would be:

Arduino pin ----------- 10K --------+------------L298
                                                 |
                                                 |
                                                 22K
                                                 |
                                              Ground

Check my math. And check to make sure you don't overload the Arduino I/O pin.

You can't use an electrolytic capacitor on the DC motor pins if you are going to run it in both directions because each wire will sometimes be + and sometimes - and the electrolitic cap is polarized - it only works one way. Ceramic caps would be better. Off the top of my head I woud guess about .1uF but you probably want to do some more research on that.
 
Title: Re: L298N motor driver
Post by: jwatte on April 23, 2013, 11:55:31 AM
Quote
powering it with 9 V battery

The 9V battery can only give about 100 mA of current before it starts to sag noticeably.

You may find that the 9V battery can't drive your motors effectively. If that happens, you could use a four-AA battery pack instead for the motor, and forego the regulator entirely.

You could also just wire 9V directly to the motor, and instead of burning it off with a regulator, just set the PWM duty cycle to something lower. If you set the PWM to 128-out-of-255, and have 9V motor power, the motors will see an effective 4.5 volts.

The EMI capacitor used on the motor terminals is typically in the range of 10 nF to 100 nF, and should be a high-voltage ceramic capacitor. For your case, a 25V ceramic with 10 nF capacitance would probably be about right.
Title: Re: L298N motor driver
Post by: jkerns on April 23, 2013, 12:11:41 PM
Quote
powering it with 9 V battery

You could also just wire 9V directly to the motor, and instead of burning it off with a regulator, just set the PWM duty cycle to something lower. If you set the PWM to 128-out-of-255, and have 9V motor power, the motors will see an effective 4.5 volts.

That solves the problem of keeping the supply voltage higher than the logic voltage as well. Forget my suggestion.
Title: Re: L298N motor driver
Post by: jim on May 03, 2013, 07:02:28 AM
i have made the necessary changes.. attached is the final working circuit of L298N


i would like to know the purpose of the two 100nF capacitors and the 1n4007 diodes.. i know that the diodes are to protect the motors but how?

why is 1n4007 diode better than 1n4001?

thank you

Title: Re: L298N motor driver
Post by: jkerns on May 03, 2013, 09:15:52 AM
The capicitors filter out noise caused by the digital circuit switching to reduce the impact of the switching on the devices in the circuit

DC motors are, essentially, big coils of wire - inductors. When current is flowing through the coils, it builds up a magnetic field. When you shut off the current, the magnetic field collapses. However, that colapsing magnetic field is like having a wire move through a magnetic field - it generates a current.  But, if you have opened up the circuit to turn off the power to the motor, where is that current going to go? With nowhere to go, it can result in high voltages that can damage componants. The diodes give that current a place to go (back to your power source) without causing damage.
Title: Re: L298N motor driver
Post by: jwatte on May 03, 2013, 11:39:38 AM
why is 1n4007 diode better than 1n4001?

In engineering, you have to choose the right part given the known requirements.
The main difference between 1n4007 and 1n4001 is the rated voltage.
Personally, I think the 1000V rated voltage of the 1n4007 is way overkill, and a 1n4001 would be quite good enough for the job.
In fact, I think in your case (small motor,) a fast-recovery signal diode like 1n4148 might be used, and would save a little cost/board space/leakage current.

To make up your own mind, read the data sheets:

1n4001, 1n4007: http://www.diodes.com/datasheets/ds28002.pdf (http://www.diodes.com/datasheets/ds28002.pdf)
1n4148: http://www.nxp.com/documents/data_sheet/1N4148_1N4448.pdf (http://www.nxp.com/documents/data_sheet/1N4148_1N4448.pdf)
Title: Re: L298N motor driver
Post by: jim on May 03, 2013, 05:16:19 PM
thank you .. i got it..  ;D
Title: Re: L298N motor driver
Post by: Duane Degn on May 04, 2013, 11:28:23 AM
I've read several places that Schottky diodes are preferred as flyback diodes since they have such fast switching times.

SparkFun has this one listed under their L298N chips.

https://www.sparkfun.com/products/10926 (https://www.sparkfun.com/products/10926)

Any reasons not to think it would be a good diode to use with a L298N controller?
Title: Re: L298N motor driver
Post by: waltr on May 04, 2013, 12:15:38 PM
That Schottky should work fine.
I also tend to use Schottky diodes across coils due to their fast switch times.
Title: Re: L298N motor driver
Post by: jwatte on May 05, 2013, 08:54:34 PM
Schottkys are fine. Note that the 1N4148 I recommended actually switches FASTER than most Schottkys, and has lower capacitance (which doesn't matter here); the main benefit of Schottkys is that you can often get them in higher amp ratings than conventional fast-recovery diodes. For a bigger motor, that's a good idea. For a small motor, a small diode is good enough (me and Soren had a discussion about this a while back on this forum, if I recall correctly)