Digital Encoder Problems
blittled
Posts: 681
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
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