PDA

View Full Version : Encoder question...clock count overflow?



FlyingFishFinger
12-19-2009, 03:16 PM
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[Inpin]~
REPEAT
if INA[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

FlyingFishFinger
12-19-2009, 03:39 PM
Wow I must be tired. The variables need to be longs -_- :(

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
UC Berkeley '12 EECS
CalSol: Berkeley Solar Car team
www.calsol.berkeley.edu
KJ6AWU

MacGeek117
12-23-2009, 08:59 AM
It took me a while to get used to working with longs rather than words, so don't feel bad.
MacGeek117

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
BS2: $49


SX48 Protoboard: $10

Propeller Protoboard: Priceless

www.apple.com (http://www.apple.com)

www.parallax.com (http://www.parallax.com/)

www.goldmine-elec.com (http://www.goldmine-elec.com)

www.expresspcb.com (http://www.expresspcb.com)

www.jameco.com (http://www.jameco.com)