Mouse Sensor Kit Overflow error
swearne
Posts: 7
I purchased a mouse sensor kit and have attempted using it with a BS2 on a board of education. I've followed all steps in the manual to connect everything. When I run the program provided, it does not detect any motion and the OVERFLOW error pops up in the Debug window even when it is not being moved. Any ideas on why this might be happening?
Thanks!!!
Thanks!!!
Comments
I tried both setups suggested in the manual but the picture I posted is the first one (both setups acted the same when the program was run). I did double check the jumpers and I think I had them in the correct placement for each setup. The picture isn't very high resolution I'm working on getting a camera right now that will be better. I post a better one later.
I also tried to hook the mouse sensor up to an arduino and it does the exact same thing. It kinda made me think there might be something wrong with the sensor... Like I soldered it poorly or something
Better pictures still coming
Thanks again!
' =========================================================================
'
' File...... mouse_monitor.bs2
' Purpose... Monitors data coming from Mouse Sensor (#28560).
' Author.... Parallax, Inc.
' E-mail.... support@parallax.com
' Started... 24 Feb 2010
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================
'
[ Program Description ]
' This program monitors the queries the Parallax Mouse Sensor Module
' and outputs the data to the serial port.
'
[ Configuration Constants ]
#DEFINE USE_400DPI 'Comment this out to use 800 dpi, instead of 400 dpi.
#DEFINE USE_DEBUG 'Comment this out to use 38400 baud, instead of DEBUG.
#DEFINE NEG_CLK 'Comment this out to use a the multiplexed clock and Vdd line.
#DEFINE DO_XYQ_ONLY 'Comment this out to dump all the registers, not just X,Y,Q.
'
[ I/O Definitions ]
sclk PIN 14 'Serial clock pin to mouse sensor.
sdio PIN 15 'Serial data I/O pin to mosue sensor.
'
[ Constants ]
'Set the baud rate to 9600 if using DEBUG; else set it to 38400.
#IF (USING_DEBUG) #THEN
#SELECT $STAMP
#CASE BS2, BS2E, BS2PE : baud CON 84
#CASE BS2SX, BS2P : baud CON 240
#CASE BS2PX : baud CON 396
#ENDSELECT
#ELSE
#SELECT $stamp
#CASE BS2, BS2E, BS2PE : baud CON 6
#CASE BS2SX, BS2P : baud CON 45
#CASE BS2PX : baud CON 121
#ENDSELECT
#ENDIF
'Mouse sensor register addresses.
DY CON $02 'Data register for current change in Y location.
DX CON $03 'Data register for current change in X location.
QLTY CON $04 'Data register for current image quality value.
STAT CON $16 'Status register.
CONF CON $1B 'Configuration register.
LORES CON $80 'Value to write to CONF for 400 dpi resolution.
CHNG CON $80 'Bitmask for STAT to see if position changed.
OFLOW CON $18 'Bitmask for STAT to detect X/Y overflow.
NEG CON $80 'Sign bit for DX and DY.
'
[ Variables ]
addr VAR Byte 'Address value for mouse sensor register.
i VAR Byte 'General counter.
dat VAR Byte 'Data value to/from mouse sensor register.
sd VAR Byte 'Scratch register.
q VAR Byte 'Quality value from mouse sensor.
ovfl VAR Byte 'Overflow counter.
x VAR Word 'Current cummulative X position.
y VAR Word 'Current cummulative Y position.
'
[ Program ]
'Initialize clock, depending on polarity.
#IF (NEG_CLK) #THEN
HIGH sclk
#ELSE
LOW sclk
#ENDIF
PAUSE 100 'Wait for mouse sensor to come out of reset.
#IF (USE_400DPI) #THEN
addr = CONF 'Change resolution to 400 dpi.
dat = LORES
GOSUB WriteAddr
#ENDIF
#IF (USE_DEBUG) #THEN
DEBUG CLS 'Clear the screen if using DEBUG window.
#ENDIF
'Main program loop.
DO
#IF (DO_XYQ_ONLY) #THEN
GOSUB DumpXYQ 'Use this to monitor X, Y, and Quality only.
#ELSE
GOSUB DumpALL 'Use this to dump all registers.
#ENDIF
LOOP
'
[ Subroutines ]
' DumpXYQ outputs X, Y, and Quality data to the programming port, for use with
' either DEBUG or an external program.
DumpXYQ:
addr = STAT
GOSUB ReadAddr
#IF (USE_DEBUG) #THEN
IF (dat & CHNG = 0) THEN
DEBUG HOME, "x: ", SDEC5 x, " y: ", SDEC5 y, " quality: ", DEC3 q
RETURN
ELSEIF (dat & OFLOW) THEN
ovfl = 10
ENDIF
#ELSE
IF (dat & CHNG = 0) THEN
SEROUT 16, baud, ["x", SDEC x, " y", SDEC y, " q", DEC q, CR]
RETURN
ELSEIF (dat & OFLOW) THEN
SEROUT 16, baud, ["x", SDEC x, " y", SDEC y, " q999", CR]
ENDIF
#ENDIF
addr = DX
GOSUB ReadAddr
x = x + dat
IF (dat & NEG) THEN x = x + $ff00
addr = DY
GOSUB ReadAddr
y = y + dat
IF (dat & NEG) THEN y = y + $ff00
addr = QLTY
GOSUB ReadAddr
q = dat
#IF (USE_DEBUG) #THEN
DEBUG HOME, "x: ", SDEC5 x, " y: ", SDEC5 y, " quality: ", DEC3 q
IF (ovfl) THEN
ovfl = ovfl - 1
DEBUG " OVERFLOW"
ENDIF
DEBUG CLREOL
#ELSE
SEROUT 16, baud, ["x", SDEC x, " y", SDEC y, " q", DEC q, CR]
#ENDIF
RETURN
' DumpAll outputs the contents of all the sensor chip's registers.
DumpAll:
SEROUT 16, baud, [HOME]
FOR addr = 0 TO $7f
GOSUB ReadAddr
IF (addr & 15 = 0) THEN SEROUT 16, baud, [HEX2 addr, ": "]
SEROUT 16, baud, [HEX2 dat]
IF (addr & 15 = 15) THEN
SEROUT 16, baud, [CR]
ELSEIF (addr & 7 = 7) THEN
SEROUT 16, baud, [" "]
ELSE
SEROUT 16, baud, [" "]
ENDIF
NEXT
SEROUT 16, baud, [CR]
RETURN
' ReadAddr reads a sensor chip register.
' Inputs: addr = address ($00 - $7F) to read.
' Outputs: dat = contents of the addressed register.
ReadAddr:
#IF (NEG_CLK) #THEN
sd = addr
GOSUB WriteNeg
GOSUB ReadNeg
#ELSE
SHIFTOUT sdio, sclk, MSBFIRST, [addr\8]
INPUT sdio
SHIFTIN sdio, sclk, MSBPOST, [dat\8]
#ENDIF
RETURN
WriteAddr:
' WriteAddr writes data to a sensor chip register.
' Inputs: addr = address ($00 - $7F) to write.
' dat = data to write to the addressed register.
#IF (NEG_CLK) #THEN
sd = addr | $80
GOSUB WriteNeg
sd = dat
GOSUB WriteNeg
#ELSE
SHIFTOUT sdio, sclk, MSBFIRST, [addr|$80\8, dat\8]
#ENDIF
RETURN
WriteNeg:
' WriteNeg simulates the SHIFTOUT instruction, but with a
' negative-going (inverted) clock.
' Inputs: sd = data to write, MSB first.
OUTPUT sdio
FOR i = 0 TO 7
sdio = sd.BIT7
PULSOUT sclk, 25
sd = sd << 1
NEXT
INPUT sdio
RETURN
ReadNeg:
' ReadNeg simulates the SHIFTIN instruction, but with a
' negative-going (inverted) clock.
' Outputs: dat = data read from serial bus, MSB first.
FOR i = 0 TO 7
dat = dat << 1
PULSOUT sclk, 25
dat.BIT0 = sdio
NEXT
RETURN
Also, did you clean the board with alcohol as the instructions recommend? I seem to recall them emphasizing that.