Encoder question...clock count overflow?
FlyingFishFinger
Posts: 461
Hi-
I'm trying to set up a small program that counts the number of clock ticks that elapse between passes of a tab between an encoder. This is my first own attempt at Spin, so still learning the language. Here's what I've got:
VAR
Word ClockDiff
Word ClockInit
CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000
Inpin = 1
OBJ
Serial: "FullDuplexSerial"
PUB Main
Serial.start(31,30,0,9600)
DIRA[noparse][[/noparse]Inpin]~
REPEAT
if INA[noparse][[/noparse]Inpin]
ClockInit := CNT
WAITPEQ(0,|<Inpin,0)
ClockDiff := CNT - ClockInit
Serial.tx(%00000000)
Serial.dec(ClockDiff)
The problem is that I never get digits printed that are longer than 5 digits...
I'm probably missing something important here, but I'm not quite sure what.
Raf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
UC Berkeley '12 EECS
CalSol: Berkeley Solar Car team
www.calsol.berkeley.edu
KJ6AWU
I'm trying to set up a small program that counts the number of clock ticks that elapse between passes of a tab between an encoder. This is my first own attempt at Spin, so still learning the language. Here's what I've got:
VAR
Word ClockDiff
Word ClockInit
CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000
Inpin = 1
OBJ
Serial: "FullDuplexSerial"
PUB Main
Serial.start(31,30,0,9600)
DIRA[noparse][[/noparse]Inpin]~
REPEAT
if INA[noparse][[/noparse]Inpin]
ClockInit := CNT
WAITPEQ(0,|<Inpin,0)
ClockDiff := CNT - ClockInit
Serial.tx(%00000000)
Serial.dec(ClockDiff)
The problem is that I never get digits printed that are longer than 5 digits...
I'm probably missing something important here, but I'm not quite sure what.
Raf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
UC Berkeley '12 EECS
CalSol: Berkeley Solar Car team
www.calsol.berkeley.edu
KJ6AWU
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
UC Berkeley '12 EECS
CalSol: Berkeley Solar Car team
www.calsol.berkeley.edu
KJ6AWU
MacGeek117
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
BS2: $49
SX48 Protoboard: $10
Propeller Protoboard: Priceless
www.apple.com
www.parallax.com
www.goldmine-elec.com
www.expresspcb.com
www.jameco.com