Quick help needed with the memsic 2125...
JamesB
Posts: 1
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?
· 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
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