Memsic 2125 code?


Closed Thread
Results 1 to 25 of 25

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: Memsic 2125 code?

    Great to hear!

    In the Nuts and Volts article they handle the XTilt like this for printing:

    Code:
    Display:
    DEBUG MoveTo, 0, 3
    DEBUG "Raw Input... ", DEC (xRaw / 1000), ".", DEC3 xRaw, " ms", ClrRt, CR
    DEBUG "G Force..... ", (xGForce.Bit15 * 13 + " ")
    DEBUG DEC (ABS xGForce / 1000), ".", DEC3 (ABS xGForce), " g", ClrRt, CR
    DEBUG "X Tilt...... ", (xGForce.Bit15 * 13 + " ")
    DEBUG DEC (ABS xTilt / 100), ".", DEC2 (ABS xTilt), DegSym, ClrRt
    PAUSE 200
    GOTO Main
    But I am sure your solution works as well.
    http://www.scalerobotics.com

  2. #2
    Join Date
    Mar 2011
    Location
    Los Angeles, California
    Posts
    322


    Did you find this post helpful? Yes | No

    Default Re: Memsic 2125 code?

    Thanks and here is the current temporary code. The plan is to take Read_Tiltx and Read_tilty and make it one subroutine for both the X and Y to conserve on the amount of code. I put a indicator (0 and 1) to show + and - angle for X and port and starboard for the Y. Best, Ed

    '************************************************* ***************
    '* Name : X-Y Tilt.BAS *
    '* Author : Ed Cannady *
    '* Notice : Copyright (c) 2012 Copyright (c) 2012 *
    '* : All Rights Reserved *
    '* Date : 6/17/2012 *
    '* Version : 1.0 *
    '* Notes : 16F628A and Memsic 2125 *
    '* : *
    '************************************************* ***************
    include "Modedefs.bas"

    ' ** Set Xtal Value in mHz **

    define OSC 20 ' Set Xtal Frequency

    #CONFIG
    __config _HS_OSC & _WDT_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
    #endconfig


    ' ** Declare Pins Used **

    CMCON= 7

    input PortA.0 ' X Data is clocked on rising edge of this pin
    input PortA.2 ' Y Data is clocked on rising edge of this pin

    ' ** Variables **

    xRaw var word 'High Pulse width from Memsic 2125
    xGForce var word ' x axis g force (1000ths)
    xTilt var word ' x axis tilt (100ths)
    xidx var byte 'Table index
    xmult var word 'Multiplier - whole part
    xfrac var word 'Multiplier - fractional part
    xPosNeg var byte 'Positive angle or Negative angle flag

    yRaw var word 'High Pulse width from Memsic 2125
    yGforce var word ' x axis g force (1000ths)
    yTilt var word ' x axis tilt (100ths)
    yidx var byte 'Table index
    ymult var word 'Multiplier - whole part
    yfrac var word 'Multiplier - fractional part
    yPosNeg var byte 'Positive angle or Negative angle flag

    Read_Force:
    pulsin PORTA.0, 1, xRaw
    pulsin PORTA.2, 1, yRaw

    xRaw = xRaw * 20
    xGForce = (xRaw / 99 - 500) * 8 'xGForce = ((xRaw / 99) - 502) * 8 ' g = ((t1 / 0.01) - 0.5) / 12.5%

    yRaw = yRaw * 20
    yGforce = (yRaw / 99 - 487) * 8 'yGforce = ((xRaw / 99) - 502) * 8 ' g = ((t1 / 0.01) - 0.5) / 12.5%


    Read_Tiltx: 'tilt = g x k Select tilt conversion factor based on static G force. Table data derived from Memsic specs.

    lookdown2 abs xGForce, <=[174, 344, 508, 661, 2000], xidx ' Table is in thousandths g results for 10,20,30,40 and max value degrees
    lookup xidx, [57, 58, 59, 60, 62], xmult 'integer lookup
    lookup2 xidx, [32768, 10486, 2621, 30802, 22938], xfrac 'gets fractional result
    xTilt = xmult * (abs xGForce / 10) + (xfrac ** (abs xGForce / 10))

    Read_Tilty: 'tilt = g x k Select tilt conversion factor based on static G force. Table data derived from Memsic specs.
    lookdown2 abs yGforce, <=[174, 344, 508, 661, 2000], yidx ' Table is in thousandths g results for 10,20,30,40 and max value degrees
    lookup yidx, [57, 58, 59, 60, 62], ymult 'integer lookup
    lookup2 yidx, [32768, 10486, 2621, 30802, 22938], yfrac 'gets fractional result
    yTilt = ymult * (abs yGforce / 10) + (yfrac ** (abs yGforce / 10))

    Check_SignX: 'Check the sign of X angle
    if (xGForce.bit15 = 0) then XT_Exit ' if positive, skip correct for g force sign
    xPosNeg = 0 ' If xPosNeg = 0 then the angle is negative (-)
    gosub Check_SignY
    XT_Exit:
    xPosNeg = 1 ' If xPosNeg = 1 then the angle is positive (+)

    Check_SignY: 'Check the sign of Y angle
    if (yGforce.bit15 = 0) then YT_Exit ' if positive, skip correct for g force sign
    yPosNeg = 0 ' If yPosNeg = 0 then the angle is negative (-)
    gosub Read_Force
    YT_Exit:
    yPosNeg = 1 ' If yPosNeg = 1 then the angle is positive (+)
    gosub Read_Force

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts