Memsic 2125
In using the parallax sample code for basic memsic 2125 interpretation I'm getting g readings over 6g. I'm curious as to why this would be the case? Again, sample code straight from parallax used with a BSIIsx. Any ideas? Thanks

Comments
#SELECT $STAMP
· #CASE BS2, BS2E, BS2PE
··· Scale······ CON···· $200··················· ' 2.0 us per unit
· #CASE BS2SX, BS2P, BS2PX
··· Scale······ CON···· $0CC·················· ·' 0.8 us per unit
#ENDSELECT
And then we have to modify the subroutine that reads the Memsic pulses like this:
Read_G_Force:
· PULSIN Xin, HiPulse, pulse··················· ' read pulse output
· pulse = pulse */ Scale······················· ' convert to uSecs
· xmG = ((pulse / 10) - 500) * 8··············· ' calc 1/1000 g
· PULSIN Yin, HiPulse, pulse
· pulse = pulse */ Scale
· ymG = ((pulse / 10) - 500) * 8
· RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
' ' Refer to Memsic documentation (AN-00MX-007.PDF) for details on g-to-tilt ' conversion and considerations. ' ' www.memsic.com ' -----[noparse][[/noparse] Revision History ]------------------------------------------------ ' -----[noparse][[/noparse] I/O Definitions ]------------------------------------------------- Xin PIN 0 ' X input from Memsic 2125 Yin PIN 1 ' Y input from Memsic 2125 ' -----[noparse][[/noparse] Constants ]------------------------------------------------------- ' Set scale factor for PULSIN #SELECT $STAMP #CASE BS2, BS2E Scale CON $200 ' 2.0 us per unit #CASE BS2SX Scale CON $0CC ' 0.8 us per unit #CASE BS2P Scale CON $0C0 ' 0.75 us per unit #CASE BS2PE Scale CON $1E1 ' 1.88 us per unit #ENDSELECT HiPulse CON 1 ' measure high-going pulse LoPulse CON 0 DegSym CON 176 ' degrees symbol ' -----[noparse][[/noparse] Variables ]------------------------------------------------------- xRaw VAR Word ' pulse from Memsic 2125 xmG VAR Word ' g force (1000ths) xTilt VAR Word ' tilt angle yRaw VAR Word ymG VAR Word yTilt VAR Word disp VAR Byte ' displacement (0.0 - 0.99) angle VAR Byte ' tilt angle ' -----[noparse][[/noparse] EEPROM Data ]----------------------------------------------------- ' -----[noparse][[/noparse] Initialization ]-------------------------------------------------- Setup: PAUSE 250 ' let DEBUG window open DEBUG "Memsic 2125 Accelerometer", CR, "-------------------------" ' -----[noparse][[/noparse] Program Code ]---------------------------------------------------- Main: DO GOSUB Read_Tilt ' reads G-force and Tilt ' display results DEBUG CRSRXY, 0, 3 DEBUG "X Input... ", DEC (xRaw / 1000), ".", DEC3 xRaw, " ms", CLREOL, CR, "G Force... ", (xmG.BIT15 * 13 + " "), DEC (ABS xmG / 1000), ".", DEC3 (ABS xmG), " g", CLREOL, CR, "X Tilt.... ", (xTilt.BIT15 * 13 + " "), DEC ABS xTilt, DegSym, CLREOL DEBUG CRSRXY, 0, 7 DEBUG "Y Input... ", DEC (yRaw / 1000), ".", DEC3 yRaw, " ms", CLREOL, CR, "G Force... ", (ymG.BIT15 * 13 + " "), DEC (ABS ymG / 1000), ".", DEC5 (ABS ymG), " g", CLREOL, CR, "G Force2... ", DEC5 (ymG / 10), " g", CLREOL, CR, "Y Tilt.... ", (yTilt.BIT15 * 13 + " "), DEC ABS yTilt, DegSym, CLREOL IF ((ymG/10)) > 00090 AND ((ymG/10)) < 00110 THEN LOW 11 LOW 12 HIGH 0 ELSEIF ((ymG/10)) > 00110 THEN HIGH 11 LOW 12 LOW 0 ELSE LOW 11 LOW 0 HIGH 12 ENDIF PAUSE 50 ' update about 5x/second LOOP END ' -----[noparse][[/noparse] Subroutines ]----------------------------------------------------- Read_G_Force: 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 RETURN Read_Tilt: GOSUB Read_G_Force disp = ABS xmG / 10 MAX 99 ' x displacement GOSUB Arcsine xTilt = angle * (-2 * xmG.BIT15 + 1) ' fix sign disp = ABS ymG / 10 MAX 99 ' y displacement GOSUB Arcsine yTilt = angle * (-2 * ymG.BIT15 + 1) ' fix sign RETURN ' Trig routines courtesy Tracy Allen, PhD. (www.emesystems.com) Arccosine: disp = disp */ 983 / 3 ' normalize input to 127 angle = 63 - (disp / 2) ' approximate angle DO ' find angle IF (COS angle <= disp) THEN EXIT angle = angle + 1 LOOP angle = angle */ 360 ' convert brads to degrees RETURN Arcsine: GOSUB Arccosine angle = 90 - angle RETURN