Joystick Control
BIG BIG AL
Posts: 7
I'm a rookie trying to program a BASIC stamp so I can control an Underwater ROV with an old PC joystick. I have a Basic Stamp 2 Version C, a PWM Pal, a 1uF capacitor, a 220 Ohm resistor, and a PC Raider joystick (from waaaaay back in the day). This is all I have so far:
' ROV - TestRcToPulse
' {$STAMP BS2}
' {$PBASIC 2.5}
timeCounter VAR Word
counter VAR Byte
pulse VAR Byte
DEBUG CLS
HIGH 7
DEBUG "Charging...", CR
PAUSE 1000
DEBUG CR, CR, "Measuring decay time.", CR, CR
INPUT 7
DO
PAUSE 100 'Originally PAUSE 1
timeCounter = timeCounter + 1
LOOP UNTIL IN7 = 0
DEBUG "Decay time: ", DEC timeCounter, CR
IF timeCounter < 63 THEN jargon
timeCounter = 63
jargon:
pulse = timeCounter * 4
DEBUG "Pulse: ", DEC pulse
DO
FOR counter = 0 TO pulse
HIGH 1 'Originally 14
NEXT
FOR counter = pulse TO 252
LOW 1 'Originally 14
NEXT
LOOP
Before I can add motors and a motor driver, I need to get this program to work. Sometimes, the timeCounter value is outrageously high in all joystick positions, so the pulse value is always 252. If I change the rate at which the Stamp counts to get a lower timeCounter value, pulse gets outrageously low. And in any case, the numbers steadily rise the longer I keep the stamp plugged in. I'm pretty lost right now. Any words of guidance?
' ROV - TestRcToPulse
' {$STAMP BS2}
' {$PBASIC 2.5}
timeCounter VAR Word
counter VAR Byte
pulse VAR Byte
DEBUG CLS
HIGH 7
DEBUG "Charging...", CR
PAUSE 1000
DEBUG CR, CR, "Measuring decay time.", CR, CR
INPUT 7
DO
PAUSE 100 'Originally PAUSE 1
timeCounter = timeCounter + 1
LOOP UNTIL IN7 = 0
DEBUG "Decay time: ", DEC timeCounter, CR
IF timeCounter < 63 THEN jargon
timeCounter = 63
jargon:
pulse = timeCounter * 4
DEBUG "Pulse: ", DEC pulse
DO
FOR counter = 0 TO pulse
HIGH 1 'Originally 14
NEXT
FOR counter = pulse TO 252
LOW 1 'Originally 14
NEXT
LOOP
Before I can add motors and a motor driver, I need to get this program to work. Sometimes, the timeCounter value is outrageously high in all joystick positions, so the pulse value is always 252. If I change the rate at which the Stamp counts to get a lower timeCounter value, pulse gets outrageously low. And in any case, the numbers steadily rise the longer I keep the stamp plugged in. I'm pretty lost right now. Any words of guidance?
Comments
'
http://www.parallax.com/Portals/0/Downloads/docs/books/sw/Web-SW-v2.1.pdf
http://www.yourwarrantyisvoid.com/2010/02/03/basic-stamp-a-quick-guide-on-using-a-legacy-joystick/
Pictures and BS2 code for down-load
I used this to make my joystick mod and made a mini board for holding the capacitors and resistors (see photos).
I am using the joystick output to control 2 stepper motors (using 2 Little Step-U stepper motor controllers), a bit excessive, but these are spare parts I had around.
just getting the joystick to work using the RCTime process is easy and cheap ($2 max)
If I was going to do it again I would go straight to a multi channel ADC like the one on the Parallax store site (Item code 604-00062).
Also, if you can, rewire the joystick so that the pots are differential (3 wires for each axis) as the resistance for each pot in the joystick is bound to be different, if you use single ended (1 common wire and 1 wire for the wiper of each axis you will need to spend a lot of time on calibration.
I have modified the code and components recommended by the tutorial in the link to speed up the response and reduce the range to use a Byte rather than Word, happy to send details if you want, but really, go with the ADC - Sooooo much easier in the long run.