Shop OBEX P1 Docs P2 Docs Learn Events
Could use some help with PWM — Parallax Forums

Could use some help with PWM

crgwbrcrgwbr Posts: 614
edited 2006-07-03 18:49 in Robotics
Hi,
I'm looking to control a couple motors using H-bridges, and hopfully use the BS2 for on/off & speed control.· I can handle the on/off part, but PWM continually confuses me.· I understand the princepals of it and stuff like that; I just can't figure out how to generate it using the BS2.· So I looked into the PWMPAL;·since I've never used serial communacation before, that confused me more sad.gif.· So finnally, I'm asking for help, will sombody please explane how to make PWM.

Thanks,
crgwbr

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NerdMaster
For
Life

Comments

  • XNORXNOR Posts: 74
    edited 2006-06-21 19:45
    crgwbr said...
    Hi,
    I'm looking to control a couple motors using H-bridges, and hopfully use the BS2 for on/off & speed control. I can handle the on/off part, but PWM continually confuses me. I understand the princepals of it and stuff like that; I just can't figure out how to generate it using the BS2. So I looked into the PWMPAL; since I've never used serial communacation before, that confused me more sad.gif . So finnally, I'm asking for help, will sombody please explane how to make PWM.

    Thanks,

    crgwbr


    I haven't tried it yet, but there is a discussion here:

    http://forums.parallax.com/showthread.php?p=536244

    HTH


    
    '{$STAMP BS2}
    
    '{$PBASIC 2.5}
    
    #SELECT $STAMP
      #CASE BS2, BS2E, BS2PE
        T1200    CON     813
        T2400    CON     396
        T4800    CON     188
        T9600    CON     84
        T19K2    CON     32
        T38K4    CON     6
      #CASE BS2SX, BS2P
        T1200    CON     2063
        T2400    CON     1021
        T4800    CON     500
        T9600    CON     240
        T19K2    CON     110
        T38K4    CON     45
    #ENDSELECT
    SevenBit     CON     $2000
    Inverted     CON     $4000
    Open         CON     $8000
    
    Baud         CON     T2400 + Inverted
    Sout         PIN 0
    
    A VAR Word
    P1 VAR Byte
    P2 VAR Byte
    
      PAUSE 100
    Start:
      FOR A=0 TO 10
        P1=A*25
        P2=255-P1
        SEROUT Sout,baud,[noparse][[/noparse]"!PWM",P1,P2,P1,P2,P1,P2,P1,P2,0,0,0,0,0,0,0,0,0]
        PAUSE 10
      NEXT
      GOTO Start
    
    
    
  • crgwbrcrgwbr Posts: 614
    edited 2006-06-21 20:00
    Thanks, I was just hoping for more of an explanation, so that I could adapt the could myself; rather than useing someone elses exact code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    NerdMaster
    For
    Life
  • XNORXNOR Posts: 74
    edited 2006-06-21 20:47
    crgwbr said...
    Thanks, I was just hoping for more of an explanation, so that I could adapt the could myself; rather than useing someone elses exact code.


    Greetings crgwbr,

    Sorry that I didn't take more time to look at this carefully.

    Now that I look at it again, I'm not so sure how it's done using the
    Basic Stamp and an H-bridge alone (in other words, no additional
    motor control accessories). confused.gif

    A Google search turned up this:

    maelabs.ucsd.edu/mae_ds/stamp/how/hardware/motor_pwm_ours/motordriver.html

    It looks promising, but I'll have to take another look at it when I get home.

    Maybe someone at Parallax can show us how it's done... wink.gif

    Thanks smile.gif
  • bennettdanbennettdan Posts: 614
    edited 2006-06-21 20:48
    crgwbr,
    What do you plan to use as an input to the stamp to control the PWM (example...POT,debug terminal, RC controller)? Remember that when using PWM it ties up the micro and you can not output two PWM on different pins.
  • crgwbrcrgwbr Posts: 614
    edited 2006-06-21 22:04
    Ok, for control, I will be using either, an Rc controller, or just programing. "Remember that when using PWM it ties up the micro and you can not output two PWM on different pins," what about with the PWMPAL, or some other seperate PWM generater.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    NerdMaster
    For
    Life
  • bennettdanbennettdan Posts: 614
    edited 2006-06-22 02:02
    The PWMPAL works great and is not to hard to get working also other PWM chips work ok too. I have a curcuit of a small h-bridge at the house I will get it tonight and post a parts list.

    Post Edited (bennettdan) : 6/22/2006 7:53:10 AM GMT
  • bennettdanbennettdan Posts: 614
    edited 2006-06-22 07:49
    Hey this digital pot controlled mosfet H-bridge should get you going. You can make two of them and use a 2channel digital pot if you want. Or you can look through the nuts and volts articals they have an H-bridge curcuit controlling a motor with an external chip.
  • crgwbrcrgwbr Posts: 614
    edited 2006-06-22 17:53
    Thanks, that should work nicley.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    NerdMaster
    For
    Life
  • crgwbrcrgwbr Posts: 614
    edited 2006-06-22 18:35
    On your scematic, the parts labeled Q, they are mosfets, right? If so, are they P or N channel?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    NerdMaster
    For
    Life
  • bennettdanbennettdan Posts: 614
    edited 2006-06-22 22:11
    Yes they are the way they are draw indicates what they are, all five of the mosfets are N-channel enhanced mode mosfets. The 4 U nand gates are on one chip, two of them make a PWM signal with the digital pot and the other lets you use one stamp pin to select forward or reverse by turning on the topleft and bottomright mosfets for one direction and botomleft and topright for the other direction. You can eliminate the direction nand gates and run the mosfets off two stamp pins but the nands make sure only one set is on at one time and you dont have to worry about the code turning on both pins and damaging the mosfets. The 74HC132 and five mosfets wont cost much more than the shipping to get them to you.
  • crgwbrcrgwbr Posts: 614
    edited 2006-06-23 16:43
    Cool, I'm just about finished designing the PCB for the components. Thanks!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    NerdMaster
    For
    Life
  • crgwbrcrgwbr Posts: 614
    edited 2006-06-23 17:54
    Hey, sorry about the double post, but I thought you guys might like the finished pcb.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    NerdMaster
    For
    Life
  • bennettdanbennettdan Posts: 614
    edited 2006-06-23 17:57
    That looks good but to same you some space on your board you can buy a dual digital pot to control both of your motors.
  • crgwbrcrgwbr Posts: 614
    edited 2006-06-23 18:00
    I already have 3 or 4 single channel, and because of the size boards I have, I can only put one controller on each board anyway.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    NerdMaster
    For
    Life
  • bennettdanbennettdan Posts: 614
    edited 2006-06-23 19:33
    OK keep us posted when you get it running.
  • crgwbrcrgwbr Posts: 614
    edited 2006-06-23 20:29
    One more question, one your schmatic, near the top of the H-bridge section, there's 12v coming in, and a cap going to ground.· One my PC board design I left it the cap out because I'm pretty sure you don't need it, am I right.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    NerdMaster
    For
    Life
  • bennettdanbennettdan Posts: 614
    edited 2006-06-24 03:09
    The cap is what I call a stiffening cap which is liek putting a cap on a car amp it helps the battery to recover. It will run without.
  • crgwbrcrgwbr Posts: 614
    edited 2006-06-30 15:53
    ok, I have the circuit prototyped, what kind of program will control it? I can handel the digi pot, but I can't figure out P13 & P15.

    Thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    NerdMaster
    For
    Life
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2006-06-30 17:46
    In any of the schematics, I don't see any back EMF diodes. If they are built into the MOSFET's fine, but it should be noted on the schematic(s).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • crgwbrcrgwbr Posts: 614
    edited 2006-06-30 18:11
    Sorry, but, what are you talking about?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    NerdMaster
    For
    Life
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2006-06-30 19:44
    crgwbr,

    When you apply power to an inductive load such as a motor, you create a magnetic field around the coil.
    When the power is removed, the magnetic field collapses causing current to flow in the reverse direction
    through your circuit. MOSFET's and other electronics don't survive very long under these conditions and
    will prematurely fail. A simple fix is to place a diode in the reverse direction across the MOSFET or BIPOLAR
    transistor. Some, not all, MOSFETS have such a diode already built-in.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • bennettdanbennettdan Posts: 614
    edited 2006-07-01 21:22
    Pin 15 is used to turn the PWM chip on and pin 13 is the direction pin. Send a HIGH 15 to turn on the PWM·and send a LOW 13 for one direction or a HIGH 13 for the other.
  • crgwbrcrgwbr Posts: 614
    edited 2006-07-01 22:42
    Thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    NerdMaster
    For
    Life
  • bennettdanbennettdan Posts: 614
    edited 2006-07-02 02:22
    Make sure the diodes are on the mosfets..like Beau suggests.
  • crgwbrcrgwbr Posts: 614
    edited 2006-07-03 18:49
    ok, to make sure, cathode to source, and anode to drain, right?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    NerdMaster
    For
    Life
Sign In or Register to comment.