Do anyone have any sample code for a Stamp 2 for controlling the H-bridge?
Thanks.
Page 1 of 1
H bridge with Parallax Stamp
#2
Posted 03 April 2007 - 09:53 AM
Here's some simple code that controls motor direction with 4 i/o lines. You could reduce it down to 2 i/o's if you need to. To control motor speed you need to PWM the low sides. The BASIC STAMP2 doesn't do this well, other stamps might (check with www.parallax.com). The datasheet for the Simple Bridge shows an application where a PIC controller is used to control a motor's speed and direction as well.
See the datasheet for external circuit components that can help reduce voltage spikes.
Lon
' {$STAMP BS2}
' CONTROLLING A DC MOTOR FORWARD, REVERSE, AND STOP USING
' A BASIC STAMP2 AND A SIMPLE BRIDGE
' L1 = P0
' L2 = P1
' H1 = P2
' H2 = P3
'
H2 CON 3 'DIRS 1 RESET 0
H1 CON 2 'DIRS 1 RESET 0
L2 CON 1 'DIRS 1 RESET 0
L1 CON 0 'DIRS 1 RESET 0
'
START:
OUTS = %0000000000000000
DIRS = %0000000000001111
STOP_MOTOR:
LOW L1
LOW L2
LOW H1
LOW H2
PAUSE 1000
FORWARD_MOTOR:
LOW L2
LOW H1
HIGH L1
HIGH H2
PAUSE 4000
REVERSE_MOTOR:
LOW L1
LOW H2
HIGH L2
HIGH H1
PAUSE 4000
GOTO STOP_MOTOR
END:
See the datasheet for external circuit components that can help reduce voltage spikes.
Lon
' {$STAMP BS2}
' CONTROLLING A DC MOTOR FORWARD, REVERSE, AND STOP USING
' A BASIC STAMP2 AND A SIMPLE BRIDGE
' L1 = P0
' L2 = P1
' H1 = P2
' H2 = P3
'
H2 CON 3 'DIRS 1 RESET 0
H1 CON 2 'DIRS 1 RESET 0
L2 CON 1 'DIRS 1 RESET 0
L1 CON 0 'DIRS 1 RESET 0
'
START:
OUTS = %0000000000000000
DIRS = %0000000000001111
STOP_MOTOR:
LOW L1
LOW L2
LOW H1
LOW H2
PAUSE 1000
FORWARD_MOTOR:
LOW L2
LOW H1
HIGH L1
HIGH H2
PAUSE 4000
REVERSE_MOTOR:
LOW L1
LOW H2
HIGH L2
HIGH H1
PAUSE 4000
GOTO STOP_MOTOR
END:
Share this topic:
Page 1 of 1

Help










