I finally figured out how to use a Parallax QTI Line Sensor, HB25 Motor Controller, and a BS2 to sense and control the shaft position of a wiper motor.
I made a 3" disk with "tic" marks in PaintshopPro, glued it to a cardboard disk, drilled out the center, mounted it over the shaft, then hot glued the QTI to a standoff, and hot glued that to the motor over the "tic disk".
http://www.spooksterville.com/gallery3/albums/batch/normal_P4010032.JPG
The QTI outputs a pulse each time it sees a transition from black to white. The BS2 reads the pulses and sends positioning commands to the HB25. The shaft can be positioned anywhere you want it... near a tic mark
http://www.parallax.com/detail.asp?product_id=555-27401
http://www.parallax.com/detail.asp?product_id=29144
Whats it good for? turning heads, lifting arms/legs/torsos, pulling a prop a precise distance...and back
Here's sample code that will position the shaft a 1/2 rotation CW, back to start position, then CW 1 full rotation and back to starting position...with a few pauses.
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================
' -----[ Program Description ]---------------------------------------------
' This code utilizes a QTI as an encoder
' -----[ I/O Definitions ]-------------------------------------------------
' qti w goes to Vdd
' qti r Output Connects To P0
HB25 PIN 15
trigger PIN 14
' -----[ Constants ]-------------------------------------------------------
T2400 CON 396
T9600 CON 84
T38K4 CON 6
Inverted CON $4000
Open CON $8000
Baud CON Open | T38K4 ' fast baud for accessories
IsOn CON 1 ' for active-high I/O
IsOff CON 0
' -----[ Variables ]-------------------------------------------------------
oldBits VAR Nib ' Previous State Of I/O Pin 0
newBits VAR Nib ' Current State Of I/O Pin 0
counter VAR Byte ' Counter (0-255)
index VAR Word
' -----[ Initialization ]--------------------------------------------------
OUTS = %1000000000000000 ' Set All Output Pins Low but 15
DIRS = %1111111111111110 ' I/O Pin 0 is Input
newBits = INA
' -----[ Program Code ]----------------------------------------------------
main:
'DO WHILE trigger= IsOff: LOOP 'take out the ' to use a trigger
counter =0
DO : LOOP UNTIL HB25 = 1 ' Wait For HB-25 Power Up
LOW HB25 ' Make I/O Pin Output/Low
PAUSE 5 ' Wait For HB-25 To Initialize
PULSOUT HB25, 750
PAUSE 5000
CW:
PULSOUT HB25, 780 'start motor
CCW:
PULSOUT HB25, 710
Halt:
PULSOUT HB25, 750
encoder:
DO WHILE counter < 62
newBits = INA ' Get State Of I/O Pin 0
IF newBits <> oldBits THEN ' Have Bits Changed?
counter = (counter + 1) 'Start counter
IF counter = 10 THEN CCW
IF counter = 20 THEN CW
IF counter = 40 THEN ccw
IF counter = 61 THEN Halt
DEBUG HOME, ? counter ' Show New Counter On Screen
oldBits = newBits ' Update oldBits
ENDIF
LOOP
RETURN