BS2 DC Motor\Encoder Control
Hello!
I have a circuit setup as pictured. This is mostly from Nuts N Volts of Basic Stamps #52. HIP4081A H-Bridge & HRF3205 Mosfets

The motor is from an inkjet. It has a 64 count per rev. encoder wheel on it with a 3 wire emitter\optical(transistor i think) receiver pair
I got it working like in the article, then added an LM339 comparator and tuned it with the o-scope. Ive got the encoder feeding into PO5
I cannot imagine how to create a closed loop control system using the stamp.. the pwm takes priority? Anyone have any help or examples? Ideally i want to be able to tell it 'go xxx encoder ticks, at xxx rpm'.
The code to make it move in one direction is as follows, you can see my attempt to start at counting pulses:
Thanks in advance!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
3D & 2D Design - Technical Documentation
www.robertguyser.com
I have a circuit setup as pictured. This is mostly from Nuts N Volts of Basic Stamps #52. HIP4081A H-Bridge & HRF3205 Mosfets

The motor is from an inkjet. It has a 64 count per rev. encoder wheel on it with a 3 wire emitter\optical(transistor i think) receiver pair
I got it working like in the article, then added an LM339 comparator and tuned it with the o-scope. Ive got the encoder feeding into PO5
I cannot imagine how to create a closed loop control system using the stamp.. the pwm takes priority? Anyone have any help or examples? Ideally i want to be able to tell it 'go xxx encoder ticks, at xxx rpm'.
The code to make it move in one direction is as follows, you can see my attempt to start at counting pulses:
Thanks in advance!
' {$STAMP BS2}
' {$PBASIC 2.5}
'HIP4801A H-Bridge Motor Driver and Encoder Test
DISpin CON 0 'Disable input, logic high disables all outputs
BHIpin CON 1 'B high side control pin, a logic high turns on B high side driver
BLIpin CON 2 'B low side control pin, a logic high turns on B low side driver
ALIpin CON 3 'A low side control pin, a logic high turns on A low side driver
AHIpin CON 4 'A high side control pin, a logic high turns on A high side driver
PWMreg VAR Word 'Pulse width modulation duty cycle register
DURreg VAR Word 'Pulse width modulation duration register
x VAR Byte
encoder CON 5 'Encoder input pin
encodercount VAR Byte 'Variable to hold encoder tics
main:
DEBUG CLS
DEBUG "HIP4801A H-Bridge Motor Driver and Encoder Test",CR
GOTO runforward
runforward:
HIGH DISpin 'Disable all driver outputs(stops motor)
'PAUSE 100 'Wait 1s then set input values
HIGH BHIpin 'Enable B high side driver
LOW BLIpin 'Disable B low side driver
LOW AHIpin 'Disable A high side driver
LOW ALIpin 'Disable A low side driver(will PWM it below)
LOW DISpin 'Enable all driver outputs(only B high side in this CASE)
'PWM ALIpin,PWMreg,DURreg 'PWM A low side driver
PWM ALIpin,00025,0002
'PULSOUT ALIpin, 1
COUNT encoder,3,encodercount
LOW ALIpin
DEBUG DEC4 encodercount
PAUSE 1000
GOTO main
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
3D & 2D Design - Technical Documentation
www.robertguyser.com
