Digital Encoder Problems
blittled
Posts: 695
I'm using the Boe-Bot Digital Encoder with 10k pull up resistors to 3.3V on the input line and the following code to read them:
Propeller
On the receiving end instead of incremental numbers I get random large numbers like 50768, 1238, 17301 when using
Basic Stamp
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
What electronics need - MORE POWER!!!!!!!
Propeller
con
_clkmode = xtal1 + pll16x 'Adjusted for ProtoBoard
_xinfreq = 5_000_000
BaudRate = 9200
TxPin = |< 1
RxPin = |< 0
var
long CntStack[noparse][[/noparse]40]
Word counterL
obj
Comms : "JDCogSerial"
pub start | val, valHi, valLo
CommPtr := Comms.start(RxPin, TxPin, BaudRate) ' Start Encoder counting
cognew (Count(@counterL, 2),@CntStack)
val := Word[noparse][[/noparse]@counterL]
valHi := val/256
valLo := val - valHi*256
byte[noparse][[/noparse]@Buffer][noparse][[/noparse] 0 ] := valHi
byte[noparse][[/noparse]@Buffer][noparse][[/noparse] 1 ] := valLo
SendBuffer
PUB SendBuffer | index
index~
Comms.Str(string("!STBD"))
repeat until index == 2
Comms.tx(byte[noparse][[/noparse]@Buffer][noparse][[/noparse]index])
index++
Pub Count(cntrAddr, pin) | status
dira[noparse][[/noparse]pin] := 0
word [noparse][[/noparse]cntrAddr] := 0
status := ina[noparse][[/noparse]pin]
Repeat
waitpne(status, pin, 0)
status := ina[noparse][[/noparse]pin]
word [noparse][[/noparse]cntrAddr]++
On the receiving end instead of incremental numbers I get random large numbers like 50768, 1238, 17301 when using
Basic Stamp
mbuff VAR Byte(2)
DO
SERIN 8,84, [noparse][[/noparse]WAIT("STBD"),STR mbuff\2]
DEBUG DEC mbuff(0)*256 + mbuff(1)
LOOP
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
What electronics need - MORE POWER!!!!!!!

Comments
con _clkmode = xtal1 + pll16x 'Adjusted for ProtoBoard _xinfreq = 5_000_000 BaudRate = 9200 [color=red] TxPin = |< 1 RxPin = |< 0[/color] var long CntStack[noparse][[/noparse]40] Word counterL obj Comms : "JDCogSerial" pub start | val[color=orange][s], valHi, valLo[/s][/color] CommPtr := Comms.start(RxPin, TxPin, BaudRate) ' Start Encoder counting cognew (Count(@counterL, 2),@CntStack) val := Word[noparse][[/noparse]@counterL] [s][color=orange] valHi := val/256 valLo := val - valHi*256[/color][/s] byte[noparse][[/noparse]@Buffer][noparse][[/noparse] 0 ] := [color=orange][s]valHi[/s] byte[noparse][[/noparse]@val][noparse][[/noparse]1][/color] byte[noparse][[/noparse]@Buffer][noparse][[/noparse] 1 ] := [color=orange][s]valLo[/s] byte[noparse][[/noparse]@val][noparse][[/noparse]0][/color] SendBuffer PUB SendBuffer | index index~ Comms.Str(string("!STBD")) repeat until index == 2 Comms.tx(byte[noparse][[/noparse]@Buffer][noparse][[/noparse]index]) index++ Pub Count(cntrAddr, pin) | status, mask [color=orange][s]dira[noparse][[/noparse]pin] := 0[/s][/color] ' simply not needed, as cognew always starts a cog with dira set to 0 completely word [noparse][[/noparse]cntrAddr] := 0 [color=green]mask := |< pin[/color] status := ina[s][color=purple][noparse][[/noparse]pin][/color][/s] [color=purple]& mask[/color] Repeat waitpne(status, [color=red][s]pin[/s][/color][color=green]mask[/color], 0) status := ina[color=purple][s][noparse][[/noparse]pin][/s] & mask[/color] word [noparse][[/noparse]cntrAddr]++In red you see the problem! Waitpne expects a bitmask, but what you gave it is the bit-number, so actually it is watching the TxPin which is heavyly used by the serial interface.
PS: forgot something ... see the purple correction. Know the difference? ina[noparse][[/noparse]pin] is shifting bit number pin of ina to bit 0 of status.
Post Edited (MagIO2) : 7/2/2009 5:22:55 AM GMT