Shop OBEX P1 Docs P2 Docs Learn Events
Quick help needed with the memsic 2125... — Parallax Forums

Quick help needed with the memsic 2125...

JamesBJamesB Posts: 1
edited 2004-10-15 23:16 in BASIC Stamp
In my program I am using the following (based on the demo code) to read in values:

· PULSIN Xin, HiPulse, xRaw···················· ' read pulse output
· xRaw = xRaw */ Scale························· ' convert to uSecs
· xmG = ((xRaw / 10) - 500) * 8················ ' calc 1/1000 g
· PULSIN Yin, HiPulse, yRaw
· yRaw = yRaw */ Scale
· ymG = ((yRaw / 10) - 500) * 8


I then send this to an LCD:

SEROUT 7,n9600,[noparse][[/noparse]poscmd,104,"y axis· ", SDEC (ABS ymG / 1000), ".", DEC2 (ABS ymG), " g"]
SEROUT 7,n9600,[noparse][[/noparse]poscmd,124,"x axis ·", SDEC (ABS xmG / 1000), ".", DEC2 (ABS xmG), " g"]

but I am finding that "negative" values display as a high number - i.e. 65521 -this changes as I tilt the device. In the other direction it's fine.
Any thoughts? I presume something in the code can't deal with a negative number and it looks like its going to 65535 - actual value? Not 100% sure on that though. Any pointers?

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-10-15 23:16
    If you look in that same demo you'll see how negative values are handled with DEBUG -- you need to do the same thing. Basically, you have to look at Bit15 of the value; if it is 1 the value is negative. I think you're going to end up with something like this:

    sign = ymG .BIT15 * 13 + " "
    ymG = ABS ymG
    SEROUT Sio, Baud, [noparse][[/noparse]PosCmd, 104, "Y Axis ", sign, DEC (ymG / 1000), ".", DEC3 ymG]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
Sign In or Register to comment.