Memsic 2125 code?


Results 1 to 25 of 25

Threaded View

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


    Did you find this post helpful? Yes | No

    Default Re: Memsic 2125 code?

    Hi Ed,

    If I were you, I'd use the Parallax Memsic 2125 example, as it is probably the easiest of what I have seen. It uses a lookup table and simple math to approximate the angle, with pretty good accuracy within the 0 to 45 degree range (but error will increase as roll increases, since a lookup table can only take one axis into account at a time).

    Parallax shows a table for angle/g from Memsic:
    Name:  memsic-table.png
Views: 5042
Size:  52.3 KB

    Straight from the nv92.pdf example:

    Now, we could take the easy route and use 62.35 as our conversion factor, but this would give us
    an error at low tilt angles that we really don't need to tolerate. What we'll do, then, is work
    backward from this data and determine the output from the 2125 at the angles specified in the
    chart. Then we can use LOOKDOWN to compare the 2125 output to the chart and a LOOKUP
    table to determine the proper tilt conversion factor.
    Calculating the maximum g-force output for a given range is done by dividing the arc for a range
    by its conversion factor. This will give us the maximum g-force output for that range.

    10 ÷ 57.50 = 0.17391
    20 ÷ 58.16 = 0.34387
    30 ÷ 59.05 = 0.50804
    40 ÷ 60.47 = 0.66148
    50 ÷ 62.35 = 0.80192

    Remember that the g-force output from the BASIC Stamp code is in 0.001g units, so we'll
    multiply the results above by 1000 for use in a LOOKDOWN table. Let's look at the code that
    converts g-force to tilt.

    Here is some of the code, modified only slightly for Picbasic:

    Code:
    xRaw    VAR Word ' pulse width from Memsic 2125
    xGForce VAR Word ' x axis g force (1000ths)
    xTilt   VAR Word ' x axis tilt (100ths)
    idx     VAR byte ' table index
    mult    VAR Word ' multiplier - whole part
    frac    VAR Word ' multiplier - fractional part
    HiPulse con 1    ' tells pulsin to look for highpulse, not lowpulse
    
    
    
    
    Read_X_Force:
        PULSIN PORTB.1, HiPulse, xRaw
        xRaw = xRaw * 2
        ' g = ((t1 / 0.01) - 0.5) / 12.5% ' formula from data sheet
        xGForce = ((xRaw / 10) - 500) * 8 ' Modified for our PIC - Converts to 1/1000 g's
    RETURN
    
    Read_X_Tilt:
    GOSUB Read_X_Force
        ' 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], idx
        ' above table are thousandths g results for 10,20,30,40 and max value degrees  
        LOOKUP idx, [57, 58, 59, 60, 62], mult          'integer lookup
        LOOKUP2 idx, [32768, 10486, 2621, 30802, 22938], frac 'gets fractional result
        ' G Force is divided by 10 to prevent roll-over errors at end
        ' of range. Tilt is returned in 100ths degrees.
        ' Parallax explains fractional lookup like this:
        ' 65,536 * .16 (this is from the fractional part of 20 degree, 58.16 number) = 10486
        xTilt = mult * (ABS xGForce / 10) + (frac ** (ABS xGForce / 10))
        Check_SignX:
        IF (xGForce.Bit15 = 0) THEN XT_Exit ' if positive, skip
        xTilt = -xTilt ' correct for g force sign
        XT_Exit:
    RETURN
    Attached Images Attached Images
    http://www.scalerobotics.com

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