Shop OBEX P1 Docs P2 Docs Learn Events
H-bridge — Parallax Forums

H-bridge

TURKEYUSATURKEYUSA Posts: 4
edited 2006-04-28 14:38 in BASIC Stamp
I wrote the following code to run·a dc·motor forward·3 sec,·stop 3 sec and then run reverse 3 sec. However it runs 3sec forward·and then imidiately runs 3 sec reverse then it·pauses for 3 sec.· Does anybody know why?·When both output 8 and 10 set to 1 or 0(1,1)(0,0) it doesnt run. I attached the picture for wiring reference. I also used http://robotroom.com/HBridge.html·for the H bridge.

Regards,

OUTPUT 8
OUTPUT 10
main:
OUT8=1
OUT10=0
PAUSE 3000
OUT8=1
OUT10=1
PAUSE 3000
OUT8=0
OUT10=1
PAUSE 3000
GOTO main
1024 x 768 - 178K
640 x 480 - 69K
640 x 480 - 67K

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-04-27 22:14
    You have OUTPUT 8 and OUTPUT 10.· The IC has pin2 (PWM in OR just +V) and pin4 (DIRection.)· You don't tell which OUTPUT you are using in this regard.

    You should start/stop with the IC pin2 and go FWD/REV with pin4.

    You should use HIGH 8, LOW 8 and HIGH 10, LOW 10 to change the states of the STAMP outputs.· [noparse][[/noparse]Yes, declare them as OUTPUTs first, then use HIGH/LOW to change states.]
  • Beau SchwabeBeau Schwabe Posts: 6,557
    edited 2006-04-27 22:30
    TURKEYUSA,
    On the TC4424 pins 2 and 4 are the control lines and essentially they can be reversed.· When·both pins are HIGH or LOW, this effectively acts as a "brake" to the motor.
    That said, if you are driving one pin HIGH, then the other pin must be driven LOW.· and vise versa.· Refer to the link that you provided... notice the asterisk indicating
    the PWM situation for forward.· The opposite would be true for reverse.

    As PJ said, use HIGH 8, LOW 8 and HIGH 10, LOW 10 to change the states of the STAMP outputs.

    ·



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

    IC Layout Engineer
    Parallax, Inc.
  • TURKEYUSATURKEYUSA Posts: 4
    edited 2006-04-27 23:04
    Thanks guys.
    I understand the concept but my programming knowledge is only 6 hours old. I was able to write the code from the given samples from the tutorials. At this point I still don’t know how I can output first then use high and low.
    I used pin8 on BS2 for pin4 on IC(P10 for pin2). I wrote the following code; unfortunately the result is still the same. Is my code totally wrong? How should I change it?
    Best regards,

    ' {$STAMP BS2}
    OUTPUT 8
    OUTPUT 10
    main:
    HIGH 8
    LOW 10
    PAUSE 2000
    HIGH 8
    HIGH 10
    PAUSE 3000
    HIGH 10
    LOW 8
    PAUSE 3000
    GOTO main


    When·I enter the following code it rottates in only one direction
    ' {$STAMP BS2}
    OUTPUT 8
    OUTPUT 10
    main:
    LOW 8
    HIGH 10
    PAUSE 3000
    HIGH 8
    HIGH 10
    PAUSE 3000
    LOW 8
    LOW 10
    PAUSE 3000
    GOTO main

    Post Edited (TURKEYUSA) : 4/27/2006 11:19:22 PM GMT
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-04-27 23:59
    Those ICpins have deceptive names attached.
    OUTPUT 8
    OUTPUT 10
    main:
      'go one way
      LOW 8
      HIGH 10
      PAUSE 3000
     
      'does this stop1?
      LOW 8
      LOW 10
      PAUSE 3000
     
      'go other way
      HIGH 8
      LOW 10
      PAUSE 3000
     
      'does this stop2?
      HIGH 8
      HIGH 10
      PAUSE 3000
    
      GOTO main
    
    
  • TURKEYUSATURKEYUSA Posts: 4
    edited 2006-04-28 00:56
    It worked! Thanks alot!
    i was doing the same thinng but missing the 4th step ('does this stop2?
    ).
  • SSteveSSteve Posts: 808
    edited 2006-04-28 01:19
    turkeyusa said...
    At this point I still don’t know how I can output first then use high and low.
    The OUTPUT command just tells the Stamp that the specified pin will be used for output rather than input. The HIGH and LOW commands are the ones that set the pin into a high or low state.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-04-28 01:25
    · Well -- there are two ways to STOP the Motor: with a '1'·to both pin2 & 4 OR a '0' to both pin2 & 4.· Either should work.· Your 2nd program didn't have a STOP before the GOTO main.

    · N.B. -- It's not really a STOP (like a brake), it just puts both Motor terminals at the same potential (GND or +); it cuts the juice.
  • Beau SchwabeBeau Schwabe Posts: 6,557
    edited 2006-04-28 01:58
    ...An electrical "brake" ... you effectively short the motor leads together. If the motor tries to turn and act as a generator, the
    rotation will be restricted due to the short compared to the same motor without a short.

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

    IC Layout Engineer
    Parallax, Inc.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-04-28 04:32
    TURKEYUSA -

    You're not done having fun yet! :-)

    Please take a look at this version with some additional documentation, and another feature - variable speed. Please note the use of Pin Port NAMES, as opposed to Pin Port NUMBERS. Much easier to understand, and self-documenting too!

    /code
    '{PBASIC 2.5}
    '{STAMP BS2}

    'Declare Pin Port Usage
    Speed· PIN 10· 'Pin·2 on TC4424 Driver IC
    Dir······ PIN··8···'Pin·4 on TC4424 Driver IC

    'Declare Constants
    Full······ CON 255·· 'Full speed constant
    Half····· CON 127·· 'Half speed constant
    Quarter CON· 63··· 'Quarter speed constant
    Time···· CON 255·· 'Max. time permissible in microseconds

    Initialize:
    OUTPUT Speed· 'Set Speed Pin Port to Output mode
    OUTPUT Dir· 'Set Direction Pin Port to Output mode

    'Ensure we are stopped initially
    · LOW·Speed
    · LOW·Dir

    main:
    · 'go one way
    ··HIGH·Speed
    ··LOW·Dir···· 'Proceed Forward
    · PAUSE 3000

    · 'does this stop1?
    · LOW·Speed
    · LOW·Dir
    · PAUSE 3000

    · 'go other way
    ··LOW·Speed
    ··HIGH·Dir···· 'Proceed in Reverse
    · PAUSE 3000

    ··'does this stop2?
    ··HIGH·Speed
    ··HIGH·Dir
    · PAUSE 3000

    'Let's try variable speed!

    'Prototype PWM Command (See PBASIC Stamp Manual for details):
    'PWM Pin, Duty, Duration

    'Run at Full Speed, same as before
    ·LOW Dir
    ·PWM Speed, Full, Time
    ·PAUSE 3000

    'Stop for a second
    ·LOW·Speed
    ·LOW·Dir

    'Run at 1/2 speed
    ·PWM Speed, Half, Time
    ·PAUSE 3000

    'Stop for a second
    ·LOW·Speed
    ·LOW·Dir

    'Run at 1/4 speed
    ·PWM Speed, Quarter, Time
    ·PAUSE 3000

    'Stop for a second
    ·LOW·Speed
    ·LOW·Dir

    ·GOTO main
    code/

    My apologies if I inadvertantly introduced any syntax errors above, as I wasn't able to run this test code through the Stamp Editor. There are·probably more "LOW Dir" commands above than what is really needed, but I left them in for symmetry during the learning process. In other words, that's how you're used to seeing it.

    Once you understand what's going on, I'm sure you'll see which ones can be removed. No harm is done by having them there, it just makes the program longer than it needs to be.

    Have fun!

    Regards,

    Bruce Bates


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • Robert@HCCRobert@HCC Posts: 80
    edited 2006-04-28 07:03
    Bruce Bates said...



    My apologies if I inadvertantly introduced any syntax errors above, as I wasn't able to run this test code through the Stamp Editor.

    Was bored, so I ran the code through the Editor and no probs - except I had to erase the stamp directives and redo them, wouldnt work without doing that for some odd reason.....other than that, all seems good smile.gif

    Robert
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-04-28 10:04
    Robert -

    Thanks, I forgot the necessary currency indicator smile.gif

    '{$PBASIC 2.5}
    '{$STAMP BS2}

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2006-04-28 14:38
    Bruce Bates said...
    Robert -

    Thanks, I forgot the necessary currency indicator smile.gif

    '{$PBASIC 2.5}
    '{$STAMP BS2}

    Regards,

    Bruce Bates

    Currency indicator- hehe. No strings attached-

    I can't tell you how many people have problems when first starting with PBASIC because they think that the directives are comments, and leave them out. The directives are necessary!

    Ryan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ryan Clarke
    Parallax Tech Support

    RClarke@Parallax.com
Sign In or Register to comment.