PDA

View Full Version : H-bridge



TURKEYUSA
04-28-2006, 05:50 AM
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

PJ Allen
04-28-2006, 06:14 AM
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.· [Yes, declare them as OUTPUTs first, then use HIGH/LOW to change states.]

Beau Schwabe
04-28-2006, 06:30 AM
TURKEYUSA (http://forums.parallax.com/member.php?u=46062),
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 (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

TURKEYUSA
04-28-2006, 07:04 AM
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

PJ Allen
04-28-2006, 07:59 AM
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

TURKEYUSA
04-28-2006, 08:56 AM
It worked! Thanks alot!
i was doing the same thinng but missing the 4th step ('does this stop2?
).

SSteve
04-28-2006, 09:19 AM
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

PJ Allen
04-28-2006, 09:25 AM
· 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 Schwabe
04-28-2006, 09:58 AM
...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 (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

Bruce Bates
04-28-2006, 12:32 PM
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@HCC
04-28-2006, 03:03 PM
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 http://forums.parallax.com/images/smilies/smile.gif

Robert

Bruce Bates
04-28-2006, 06:04 PM
Robert -

Thanks, I forgot the necessary currency indicator http://forums.parallax.com/images/smilies/smile.gif

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

Regards,

Bruce Bates

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->

Ryan Clarke
04-28-2006, 10:38 PM
Bruce Bates said...
Robert -

Thanks, I forgot the necessary currency indicator http://forums.parallax.com/images/smilies/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 (mailto:RClarke@Parallax.com)