Shop OBEX P1 Docs P2 Docs Learn Events
Mouse Sensor Kit Overflow error — Parallax Forums

Mouse Sensor Kit Overflow error

swearneswearne Posts: 7
edited 2012-05-15 13:04 in BASIC Stamp
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!!!

Comments

  • Martin_HMartin_H Posts: 4,051
    edited 2012-05-10 13:29
    There are jumpers which select the operating mode of the mouse sensor. Double check those are installed correctly as well as the cables that connect the sensor. Post a high resolution picture of you set up and I can take a look.
  • swearneswearne Posts: 7
    edited 2012-05-10 14:17
    Ok, thanks.

    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.

    IMG_0313.JPG
    960 x 720 - 265K
  • FranklinFranklin Posts: 4,747
    edited 2012-05-10 15:51
    Could you attach the program file to your next post so we could look it over?
  • swearneswearne Posts: 7
    edited 2012-05-10 16:08
    Its just the same code on the parallax website. I pasted it below.

    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
  • Martin_HMartin_H Posts: 4,051
    edited 2012-05-10 17:10
    The picture is blurry, but as best I can see the jumpers look correct as do the wires. I think it is better to use servo cables rather than wires because they'll make a better connection. As you move the mouse I could see that causing glitches.

    Also, did you clean the board with alcohol as the instructions recommend? I seem to recall them emphasizing that.
  • swearneswearne Posts: 7
    edited 2012-05-11 11:12
    I did clean the board with alcohol like it recommended. Here are the better pictures so you can see the connections I made. The second two pictures are the connection with the servo cable. However, the same thing happens regardless of the connection. I'm thinking there is probably something wrong with the sensor. I already bought another one and will see how it works out. Thanks.

    IMG_4064.jpg
    IMG_4066.jpg
    IMG_4067.jpg
    1024 x 683 - 72K
    1024 x 683 - 51K
    1024 x 683 - 62K
  • Martin_HMartin_H Posts: 4,051
    edited 2012-05-11 11:27
    In the last two photos it looks like you have it configured (via jumpers) in the harvests power from the clock line mode. But you have the servo cable plugged into a servo header. That won't work as one pin will be data, but the power line will always be 5 volts and not clocked off/on. If you look in the instructions in that mode you have the transistor controlled via a pin to generate the combined power/clock pulse, and another pin send data. These are used for the data and power lines with ground being the third.
  • swearneswearne Posts: 7
    edited 2012-05-11 12:47
    Is this better? I'n no expert at circuits. The mouse sensor still has the same problem though. I guess I could give you some more details about what happens. Like I said the OVERFLOW error pops up but also the sensor detects no movement at all and both the x and y positions start at zero and incrementally accumulate error in the negative direction. At about 30 seconds both x and y are less than -300 and still steadily decreasing. The quality always says it is at 255.
    IMG_4070.jpg
    1024 x 683 - 70K
  • Martin_HMartin_H Posts: 4,051
    edited 2012-05-11 13:02
    That does look better and I'm out of ideas.
  • swearneswearne Posts: 7
    edited 2012-05-11 13:49
    Well thanks for the help. I'll let you know if the second one I bought works at all
  • swearneswearne Posts: 7
    edited 2012-05-15 13:04
    Well it looks like the mouse chip must have gotten damaged or something. The new one that I ordered and put together works just fine. Thanks for all your help.
Sign In or Register to comment.