Haunt Forum banner

1 - 8 of 8 Posts

·
Registered
Joined
·
871 Posts
Discussion Starter #1 (Edited)
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
 

·
Registered
Joined
·
871 Posts
Discussion Starter #3 (Edited)
Thanks...no, i dont have the means to do video right now...i wish.

Im not sure on the gaps for more accuracy. I suppose so, at low rpm. At higher rpm the tics become a blur. I have to do some more experimenting to see what the limitations are but Im excited as to the possibilies. My reason for pursuing this was to raise/lower a heavy porp arm and let out/take in a specific length of line on a reel.

edit: The sensor counts at the begining and end of a tic so there is actually more resolution than just one tic/one count. Said another way, you can stop the motor at the start of a tic or the end of a tic...i hope im making sense...
 

·
Registered
Joined
·
6,024 Posts
Thanks...no, i dont have the means to do video right now...i wish.

Im not sure on the gaps for more accuracy. I suppose so, at low rpm. At higher rpm the tics become a blur. I have to do some more experimenting to see what the limitations are but Im excited as to the possibilies. My reason for pursuing this was to raise/lower a heavy porp arm and let out/take in a specific length of line on a reel.

edit: The sensor counts at the begining and end of a tic so there is actually more resolution than just one tic/one count. Said another way, you can stop the motor at the start of a tic or the end of a tic...i hope im making sense...
Oh, yea, that makes sense. That's alot better it senses the beginning and end of the ticks..that doubles the "resolution". Have you thought about hacking a mouse sensor? Not an optical one, a ball one. Just wondering your thoughts on it.
 

·
Registered
Joined
·
80 Posts
Randy,

You might consider the use of LOOKDOWN and ON GOSUB to streamline your code; the way it's written right now you can have one routine fall into another and I don't think that's what you want, even if the HB-25 tends to ignore pulses that fall into the "ignore" time frame.
 

·
Registered
Joined
·
80 Posts
... just a follow up: SELECT-CASE would work very nicely, too. One of the advantages of PBASIC 2.5 is all the niceties added that come from the PC programming world.
 
1 - 8 of 8 Posts
Top