Shop OBEX P1 Docs P2 Docs Learn Events
Using Memsic 2125 Acceerometer as a Tilt sensor with a BS2p — Parallax Forums

Using Memsic 2125 Acceerometer as a Tilt sensor with a BS2p

ArchiverArchiver Posts: 46,084
edited 2003-05-30 05:26 in General Discussion
I need a reality check and I have a question. The question first:

QUESTION:
After all is said and done, with the Memsic Demo-kit board laying flat on the
breadboard, and the breadboard laying flat on a level workbench, the sucker
reads
about 250 milli-g's in both the x and y axes. Is that normal? If it is, the fix
is easy
(just subtract whatever it takes to get zero-g on a level surface). If I should
be getting
a zero-g reading on a level surface, does anyone out there in StampLand have a
clue
about what's going on. The circuit, after it is zeroed, be the way, seems to
give +/-
90 degree readings in both axes.

REALITY CHECK:
The timing constants on the BS2, for which the Parallax App Note was written,
are
rather different from the timing constants for the BS2p, so the formulas for
measuring acceleration have to be fudged. Here's what I did; does anyone out
there
know if this is correct?

The formula for the acceleration in either axis is:

Acceleration (g) = ((T1/T2)-0.5)*8, where T2 is supposed to be 1/100th of a
sec.


1) I checked the T2 period. Following the logic of Analog AN 596, for the ADXL
202
(an equivalent part to the Memsic) and a BS2, They write:

Count Pin, 500, FREQ ' where 500 is a 500*1ms interval
T2=25000/(FREQ/20) 'where 25000/(whatever/20) is really 500000*whatever

Because the BS2P has a count 0f 287 microseconds, I used the following:

Count Pin, 1742, Freq 'because there are 1742 287 microsecond intervals
'more or less, in 500 ms.
T2= 25000/Freq*20 'This is really the same as above

I DEBUGed the results for Freq and T2, getting Freq = 50 and T2 = 10000
(microsecs)
or .01 sec, I think So far, So, good, I hope.

2) I did my counting (y axis is the same as x):

The formula for the calculation (in milli-g-units), with T2 = 0.01x1000 = 10


Accel(mg) = ((T1/10)-500)*20

The BS2 code is:

PULSIN Pin, Direction, xRaw
Xmg = ((Xraw/5)-500)*8 'There is a 5 (not a 10) in the denominator of the
fraction
'because the units of xRaw are 2 microsecs
on the BS2,
' but only 0.8 microsecs on the BS2p

Since there are 2.5 0.8 microsecond intercals in 2 microseconds (Do you have a
headache yet?), I multiplied the 5 in the denominator by 2.5 (to get 12.5,
actually, I
multiplied the numerator by 2 and the denominator of the fraction by 5 to avoid
death-by-integer-division) I wound up with


PulsIn Pin Direction, xRaw
Xmg = ((2*xRaw/25)-500)*8

As I noted above, I got level-table results ranging from about 250 milli-g to
1250
milli-g, and I subtracted 250 milli-g. (Doctor, It hurts when I go like this!)
Ultimately,
it does seem to work.

Does any of this make sense?
Sign In or Register to comment.