Changeset 3421


Ignore:
Timestamp:
Nov 14, 2012, 12:10:08 AM (3 years ago)
Author:
wmb
Message:

OLPC ARM - accelerometer selftest - manufacturing was seeing a small false-negative
fallout from the accelerometer test. This change attempts to address it by:
a) Changing the scale factor for acceleration components to 1000 units = 1 gravity, per the datasheet definition of "LSB"
b) Changing the averaging from 64 samples to 5 samples, per the vendor's recommendation
c) Changing the test limits to the vendor's recommended limits (in the new units)
d) Fixing a bug in which the first test invocation often failed, due to the sensor initially being in low-resolution mode (so the granularity of the initial average was too coarse).
e) Adding a gain test to check that the magnitude of the acceleration vector is about 1 gravity.
f) Refactoring the test slightly so that "accelerometer-off" is paired more cleanly with "accelerometer-on" (inside close and open) instead of being all over the place.

Location:
cpu/arm/olpc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpu/arm/olpc/accelerometer.fth

    r3373 r3421  
    44" accelerometer" name
    55" lis3lv02d" +compatible
     6
     7true value hi-res?
    68
    79\ reg is set dynamically by probing to find which chip is present
     
    1416: ctl1!  ( b -- )  h# 20 acc-reg!  ;
    1517: ctl4!  ( b -- )  h# 23 acc-reg!  ;
    16 : accelerometer-on  ( -- )  h# 47 ctl1!  ;
     18: ctl4@  ( -- b )  h# 23 acc-reg@  ;
     19: accelerometer-on  ( -- )
     20   h# 47 ctl1!
     21   hi-res?  if  8 ctl4!  then  \ High resolution mode
     22;
    1723: accelerometer-off  ( -- )  h# 07 ctl1!  ;  \ should this be 00?
    1824: wext  ( b -- n )  dup h# 8000 and  if  h# ffff0000 or  then  ;
     25
     26\ The scale factor for an acceleration component is 1 gravity = 1000 units.
    1927: acceleration@  ( -- x y z )
    2028   begin  h# 27 acc-reg@  h# 08 and  until  \ wait for data available
    2129   h# 0a8 1 6 " bytes-out-in" $call-parent ( xl xh yl yh zl zh )
    22    bwjoin wext 5 >>a     ( xl xh yl yh z )
     30   bwjoin wext 4 >>a     ( xl xh yl yh z )
    2331   >r                    ( xl xh yl yh     r: z )
    24    bwjoin wext 5 >>a     ( xl xh y         r: z )
     32   bwjoin wext 4 >>a     ( xl xh y         r: z )
    2533   >r                    ( xl xh           r: z y )
    26    bwjoin wext 5 >>a     ( x               r: z y )
     34   bwjoin wext 4 >>a     ( x               r: z y )
    2735   r> r> ( x y z )
    2836;
     
    4048   rot r> -        ( x3 y3 z3 )
    4149;
     50
    4251\ Averaging a lot of samples reduces the effect of vibration
     52\ The vendor recommends averaging 5 samples for selftest.
    4353: average-acceleration@  ( -- x y z )
    4454   acceleration@        ( x y z )
    45    d# 64 0  do
     55   d# 4 0  do
    4656      acceleration@ t+  ( x' y' z' )
    47    loop
    48    rot 6 >>a
    49    rot 6 >>a
    50    rot 6 >>a
     57   loop                 ( xsum ysum zsum )
     58   rot 5 /              ( ysum zsum x )
     59   rot 5 /              ( zsum x y )
     60   rot 5 /              ( x y z )
    5161;
    5262
     
    6272;
    6373
    64 \ The datasheet says the selftest change range is 3 to 32, but we
    65 \ give a little headroom on the high end to allow for external
    66 \ vibration.  Typical is supposed to be 19.
    67 \ Empirically, measured maximums were:
    68 \ - Mitch's unit, 32
    69 \ - James' A3, 41 (on rubber mat on bare ground)
    70 \ - James' A2, 39
    71 
    72 d#  50 value min-x
    73 d#  50 value min-y
    74 d# 150 value min-z
    75 d# 150 value max-x
    76 d# 150 value max-y
    77 d# 450 value max-z
     74\ The vendor recommends the following min/max values for LIS3DHTR selftest:
     75\ X:80..1700  Y:80..1700  Z:80..1400.
     76\ The numbers are in units of "1LSB = 1mg", 1000 unit = 1 gravity.
     77
     78d#   80 value min-x
     79d#   80 value min-y
     80d#   80 value min-z
     81d# 1700 value max-x
     82d# 1700 value max-y
     83d# 1400 value max-z
    7884: range?  ( delta max-delta -- error? )  between 0=  ;
    7985
     
    8591;
    8692
     93\ Lower and upper test limits for the magnitude squared of the acceleration
     94\ vector when the device is stationary.  The scaling is 1000 units = 1 gravity.
     95
     96d#  900 dup * constant gsq-min   \ 0.9 gravity squared
     97d# 1100 dup * constant gsq-max   \ 1.1 gravity squared
     98
     99: xyz>mag-sq  ( z y z -- magnitude-squared )
     100   dup *  swap dup * +  swap dup * +
     101;
     102: not1g?  ( x y z  -- error? )
     103   xyz>mag-sq   ( magnitude**2 )
     104   gsq-min gsq-max between 0=
     105;
     106
    87107: lis33de-selftest  ( -- error? )
    88108   \ Use the device's selftest function to force a change in one direction
     
    96116   rot negate -rot           ( dx' dy dz )
    97117   negate                    ( dx dy dz' )
    98    error?  if  accelerometer-off  true exit  then
     118   error?  if  true exit  then
    99119
    100120   \ Use the device's selftest function to force a change in the opposite direction
     
    107127   \ because we subtract the new measurement from the old.
    108128   swap negate swap          ( dx dy' dz )
    109    error?  if  accelerometer-off  true exit  then
    110    false
     129   error?
    111130;
    112131: lis3dhtr-selftest  ( -- error? )
     132   delay                     ( )
     133   average-acceleration@     ( x y z )
     134
     135   \ Check that the magnitude of the acceleration vector is about 1 G
     136   3dup not1g?  if           ( x y z )
     137      3drop                  ( )
     138      ." Acceleration is not 1 gravity" cr   ( )
     139      true exit              ( -- error? )
     140   then                      ( x y z )
     141
    113142   \ Use the device's selftest function to force a change in one direction
    114    delay                     ( )
    115    average-acceleration@     ( x y z )
    116143   h# 0a ctl4!               ( x y z )     \ High res, Selftest mode 0
    117144   delay
     
    119146   rot negate  rot negate  rot negate
    120147   h# 08 ctl4!               ( x y z )     \ High res, Normal mode
    121    error?  if  accelerometer-off  true exit  then
     148   error?  if  true exit  then
    122149
    123150   \ Use the device's selftest function to force a change in the opposite direction
     
    128155   average-acceleration@ t-  ( dx dy dz )
    129156   h# 08 ctl4!               ( x y z )     \ High res, Normal mode
    130    error?  if  accelerometer-off  true exit  then
    131 
    132    accelerometer-off
    133    false
     157   error?
    134158;
    135159defer lis-selftest
     
    137161   open 0=  if  true exit  then
    138162
    139    final-test?  if  accelerometer-off false  exit  then
    140 
    141    ." Don't move!" cr
    142    lis-selftest
     163   final-test?  if
     164      false
     165   else
     166      ." Don't move!" cr
     167      lis-selftest
     168   then
     169
     170   close
    143171;
    144172
     
    150178      \ Support for new LIS3DHTR chip
    151179      d# 400,000 to bus-speed
    152       d#  50 to min-x  d#  50 to min-y  d#  50 to min-z
    153       d# 150 to max-x  d# 150 to max-y  d# 450 to max-z
     180      d#   80 to min-x  d#   80 to min-y  d#   80 to min-z
     181      d# 1700 to max-x  d# 1700 to max-y  d# 1400 to max-z
    154182      h# 19 1 reg
    155183      ['] lis3dhtr-selftest to lis-selftest
     184      true to hi-res?
    156185   else
    157186      accelerometer-off
     
    159188      \ Support for old LIS33DE chip
    160189      d#  25,000 to bus-speed
    161       d#  20 to min-x  d#  20 to min-y  d#  20 to min-z
    162       d# 400 to max-x  d# 400 to max-y  d# 400 to max-z
     190      d#  40 to min-x  d#  40 to min-y  d#  40 to min-z
     191      d# 800 to max-x  d# 800 to max-y  d# 800 to max-z
    163192      h# 1d 1 reg
    164193      ['] lis33de-selftest to lis-selftest
     194      false to hi-res?
    165195   then
    166196;
  • cpu/arm/olpc/roller.fth

    r3070 r3421  
    7676d# 19 d# 20 a/b>fraction value damping
    7777
    78 d#  1 d# 80  a/b>fraction value acc-scale
     78d#  1 d# 160  a/b>fraction value acc-scale
    7979
    8080d# 20 constant ball-radius
Note: See TracChangeset for help on using the changeset viewer.