Reading a quadrature encoder with a basic stamp
Erik Arendall
Posts: 21
I have a technical question. Would I be able to read a quadrature encoder running at 7200 PPM on a BS2? If the BS2 is not fast enough which stamp would be?
Im wanting to monitor a motors direction by using a quadrature encoder. The motor runs at 120 RPM.
Any help would be great.
Im wanting to monitor a motors direction by using a quadrature encoder. The motor runs at 120 RPM.
Any help would be great.
Comments
·· You could use the COUNT command on the BS2 if you have a clean TTL pulse.· Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
-Martin
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Martin Hebel
Personal Links with plenty of BASIC Stamp info
StampPlot - Graphical Data Acquisition and Control
AppBee - XBee ZigBee / IEEE 802.15.4 Adapters & Devices
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
You say you're using it to monitor motor direction. If that's the only criteria, you'll probably be OK because you can periodically check direction then go on to do the other parts of the program. But, if you're doing speed, direction or positioning, you may need more processing power, as has been noted.
Following lines of code will give you the direction.
' {$stamp bs2}
' Program to act as high speed quadrature counter
' Program Name: quadhicount.bs2
' Last Update: Mar 10/01 tjs
DIRH=%11111111
counter VAR Word
counter2 VAR Word
counter3 VAR Word
old VAR Nib
new VAR Nib
direct VAR Byte
' Channel a and b of encoder go on inputs 6 and 7 in this case.
quad:
counter=127 'load a dummy value so can count up or down
new = INB & %0011 ' get initial condition
start:
old = new & %0011 ' remember initial setting
again:
new = INB & %0011 ' get new reading
IF new=old THEN again
direct=new.BIT1 ^ old.BIT0 ' XOR left bit of new with right bit of old to get direction
IF direct=1 THEN cw ' jump here to increment
LOW 0 ' pin 0 turns led off id turning counter-clockwise
counter=counter-1 ' jump here to decrement
OUTH=counter.LOWBYTE
GOTO start
cw:
HIGH 0 ' pin 0 turns on led if turning clockwise
counter=counter+1
OUTH=counter.LOWBYTE 'turn on leds on pins 8 through 15 to watch count
GOTO start
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
·· If you look in the help file for SX/B, there is an example of reading the encoders using the SX Chip.· You could do it by itself.· Take care.
EDIT: that should have read, "You can do it with the SX alone"
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Post Edited (Chris Savage (Parallax)) : 9/22/2006 3:25:38 PM GMT
·· Whether you use the SX or the BASIC Stamp the interface is the same.· In the case of PBASIC VS SX/B the code will be very similar as well.· What will differ greatly is performance.· You will find the SX able to read higher resolution encoders at a much faster rate than a BASIC Stamp with a lower resolution one.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
If so, that is 120 pulses per second.
The SX could do that without even breaking a sweat.
Just yell in the SX forum if you need assistance.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
There are only two guaranteed ways to become weathy.
Spend less than you make.
Make more than you spend.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support