Shop OBEX P1 Docs P2 Docs Learn Events
PWM with L293D — Parallax Forums

PWM with L293D

azmax100azmax100 Posts: 173
edited 2008-04-09 19:28 in BASIC Stamp
Hi all,

Just want to ask is it possible to use PWM to control motor speed with L293D. I am using BS2.

If possible can somebody show me sample coding.

how about L298?

Comments

  • tedbeautedbeau Posts: 48
    edited 2008-04-07 11:53
    I just checked and found that the SN754410NE chip is pin for pin compatable with the L293. I am currently using the 754410 for my motor control. The specs for the 754410 are impressive, according to the EE here at work. The chip can handle voltages up to 36 volts and currents as high as 1 amp per motor. According to one web site you can stack the chips and increase the capacity even more.

    I use the 754410 with a 556 dual timer to give me PWM speed control. BY changing the R/C timer setup I change the PWM of the 754410.

    Sample code to drive the chip, which should work for the L293 also, since they are supposed to be the same pinout can be found here.

    http://www.hobbyengineering.com/appHBridge1A.html

    The schematic I am using, with the 556 timer is attached.
    Motor one is controlled using pins 1, 3 and 5. 3 and 5 determine direction, and 1 is Enable. Pin one runs thru the 556 reset line, and then from the 556 output to the 7554410 Enable.

    Motor two is done the same way, with pin 2 used as Enable. Pins 4 and 6 control direction.
  • tedbeautedbeau Posts: 48
    edited 2008-04-07 12:06
    Sorry the attachment for the schematic did not come thru correctly.

    Here it is again.
  • azmax100azmax100 Posts: 173
    edited 2008-04-08 05:46
    Thanks tedbeau.

    i don't understand how the 556 can control motor speed by sending Hi to it reset pin.
  • tedbeautedbeau Posts: 48
    edited 2008-04-08 11:55
    The 556 is acting as a PWM generator. The 556 is actually the same as having two 555 timer chips. If you study how a 555 can be used in what is known as an astable clock. There is a really good tutorial here;
    http://www.kpsec.freeuk.com/555timer.htm

    Each half of the 556 is a seperate circuit.
    Looking at the left half of the schemtic, pins one thru seven of the 556 and pins one thru eight of the 754410 motor controller drive motor #1. The Basic Stamp Pin 1 sends the high signal to the 556 reset line when you want the motor to run. The·556 sends a high signal out its output pin #5 to the·754410 enable pin #1.
    The high from the 556 is switched ON for a period from 50 to 95 percent of the time. It is off the other time so if it is on 75% of the time and off 25% you have a 75 % duty cycle. The cycles can be up to and beyond
    680 Hz. This is so fast that the motor does not stop, it simply runs slower. It has the effect of running the motor at a lower voltage. By changing the two resistors R1 and R2 and the Capacitor that is in series with R2 you can change the duty cycle and the length of the cycle (Hz). I designed·this circuit to be able to run each motor at a different duty cycle so that I could adjust the speeds so the motors ran at the same speed. I have motors from two different cd players that I am using to run my robot. The drive ratio and motor speeds are not the same so I needed to be able to adjust motor two to match motor one.

    As I stated BS pin1 controls the 556 timer, and BS pin3 and BS pin5 control the motor direction, to run the motor backwards change pin3 to low and pin5 to high. As noted in the 754410 documentation if you put both of its input pins·high or both low you can dynamically brake the motor when·the 754410 pin 1 is high.·This would mean making the BS pin3 and BS pin5 both the same. This might come in handy with a heavier robot.

    You do not have to use the 556 chip. As it shows here· http://www.datasheetcatalog.com/datasheets_pdf/L/2/9/3/L293D.shtml· it is possible to drive the pins of the 754410 directly from the Basic Stamp if you do not need to be able to adjust the speed of the motors. I just suggested the 754410 as an alternative to the L293D. I believe it is cheaper and has same voltage and current rating. In either case, it appears that the pin out and functions are the same so the same circuit should work for both, but·I am not making any guarantees. I suggest you look here for specs on the L293D.

    http://www.datasheetcatalog.com/datasheets_pdf/L/2/9/3/L293D.shtml

    Ted


    Post Edited (tedbeau) : 4/8/2008 12:02:58 PM GMT
  • azmax100azmax100 Posts: 173
    edited 2008-04-09 05:24
    tedbeau,

    Thanks for the detail explanation.

    trough my understanding:

    1. R1, R2 and the cap are to fix the speed for the motor. So if i want to do changeable speed of the motor i can use VR for R2 as you did for R4. Is it correct?
    2. Adjust R4 to make both motor run at same speed.
    3. And it also mean that i can't use Pbasic to Ramp up or down once the VR value is fix.

    my question?

    1. Is there any method i can ramp up or down the motor speed using Pbasic?
    ( I am trying to avoid using the digital potentiometer)

    Thanks and regards.
  • tedbeautedbeau Posts: 48
    edited 2008-04-09 19:28
    1. Exactly, the time to charge/discharge the capacity thru R1 and R2 are really totally a time function which the 556 uses to turn on and off the motor enable line which is how PWM works. Changing the R2 for a variable resistor (pot) would let you adjust the speed of motor one just like motor two.

    2. correct

    3. You could set the r2 and r4 resistors and actually still pulse the stamp P1 and P2 off and on using the PWM command below.
    I havn't tried this and I would think that the ON signal would have to be longer than the time to charge/discharge the capacitor, or it would never cycle the 556. The total cycle is determined by the size of the capacitors (the ones after R2 and R4). A smaller capacitor charges/discharges faster and larger one charges slower.The ratio of on to off remains the same, and is determined by the ratio of the resistors. See Electronics club web page.

    In answer to your question last question above, I believe you can actually do this by using the pbasic built in PWM command. If you have two motors that are running the same speed you could eliminate the 556 all together and run the output of p1 to the enable1 pin on the 755410. Same with stamp P2 to Enable 2 which is pin9 on the 754410. If you ask in the forum here about using PWM to control motors you will probably be told that it doesnt work, or its not the best way to do it. This is because almost everyone here is using servo motors to drive robots and they require burst of plus voltage of specific length to drive the servo, due to its internal electronics. This burst needs to be repeated every 50ms. I guess the timing issue and the fact that you end up only running the motor, and can't do any other processing makes it difficult.
    I havn't tried using the PWM command but it should work with circuit I have, with or without the 556 timer. When the PWM command is sending the high command the 556 would still quickly cycle the enable line on and off.

    In closing, I should tell you I only started into this stuff two months ago, so I am a newbie at it also.
    Also, I think I kind of deverted from your original question about using a L293D chip. I think everything we have discussed here would apply to that chip also since its function is identical to the 755410.

    Good luck

    Ted
Sign In or Register to comment.