# Thread: Determining Acceleration from Memsic 2125

1. ## Determining Acceleration from Memsic 2125

In the Smart Sensors And Applications PDF pages 230-240 ( http://www.parallax.com/Portals/0/Do...nsors-v1.0.pdf ) the memsic 2125 provides pulse width data in the range of 1875 to 3150 whereby these values are scaled and offset to a range of -100 TO +100. This data is then considered to be the Acceleration data for a moving RC car whereby these -100 TO +100 figures are copied to the provided spreadsheet and used as the basis for further calculations, ie., velocity.

I don’t understand how simply offsetting and scaling the memsic range data (provided by the BS2 PULSIN command) automatically makes these figures Acceleration figures when other documentation such as “Memsic 2125 Accelerometer Demo Kit (#28017) ( http://www.parallax.com/Portals/0/Do.../memsickit.pdf ) indicates that the raw memsic data must be converted to acceleration by use of the equation A(g) = ((T1 / T2) – 0.5 ) /12.5% ( where T1 is the sense pulse width, T2 is the total pulse duration).

I have spent many hours pondering this one without success. Any help is greatly appreciated!

2. ## Re: Determining Acceleration from Memsic 2125

the range of 1875 to 3150 whereby these values are scaled and offset to a range of -100 TO +100.
How is this scaled and offset? What formula is used?

3. ## Re: Determining Acceleration from Memsic 2125

Hi Franklin,

On page 225 of the Smart Sensors and Applications PDF is the offset and scaling BS2 code of:

y = (y MIN 1875 MAX 3125) - 1875 ** 10538

The complete program code may be found on p227-229

I hope this helps.

4. ## Re: Determining Acceleration from Memsic 2125

Regarding the above quoted BS2 programming statement

y = (y MIN 1875 MAX 3125) - 1875 ** 10538
, the scale factor is determined using the scale factor equation on page 82 of the same PDF, which is:
ScaleConstant=Int(65536( (output scale elements)/(input scale elements -1) ) )

Output scale elements: -100 TO 0 TO 100 yields 201
Input scale elements: 3125-1875-1 yields 1249
ScaleConstant=Int( 65536 * (201/1249) ) yielding 10546

As noted above, my calculation yields 10546, whereas, the PDF indicates 10538. I am not certain why the difference of 8 is occurring (any insight appreciated), however, as mentioned in the original post, I don't understand how scaling and offsetting the memsic raw output results in Acceleration values whereas other documentation indicates that the raw data must be put through the previous listed conversion equation in order to derive Acceleration.

5. ## Re: Determining Acceleration from Memsic 2125

robotics,

I'll have to look at the code a little closer to explain it in further detail, but it seems that your only off by one tick...

If you change the 1249 to 1250 and rework the equation...

ScaleConstant=Int( 65536 * (201/1250) )

... you get 10538

6. ## Re: Determining Acceleration from Memsic 2125

robotics,

SOLVED

When you use the formula on page 82 to determine the ScaleConstant your first subtracting 1875 from 3125 and getting 1250 for your input scale elements when in fact the number of elements in your input scale are 1251 ... <- keep in mind this is before you subtract 1 as the equation indicates.

In the example on page 82, the input scale of 0 to 10 is used. By your same notation that would be ...

10 - 0 which gives an answer of 10, but there are actually 11 elements total.

The same scenario is a common mistake when counting items from lined numbers...

Suppose your data starts on line 9 and ends on line 26 and you wanted to figure out how many lines there were...

26 - 9 = 17 ... but there would actually be 18 lines of data.

...The same is true for your input range of 3125 and 1875 ... subtracting yields 1250, but there are actually 1251 individual 'elements' there, so the equation for your scale constant should look like this...

ScaleConstant = Int [ 65536 ( 201 / 1251 - 1) ]

ScaleConstant = Int [ 65536 ( 201 / 1250) ]

ScaleConstant = Int [ 10538.1888]

ScaleConstant = 10538

BTW) the output Scale is correct ... -100 to 100 is 201 individual elements counting Zero.

7. ## Re: Determining Acceleration from Memsic 2125

Beau,

If you could address the first part of my question(below) I would greatly appreciate it.

I don’t understand how simply offsetting and scaling the memsic range data (provided by the BS2 PULSIN command) automatically makes these figures Acceleration figures when other documentation such as “Memsic 2125 Accelerometer Demo Kit (#28017) ( http://www.parallax.com/Portals/0/Do.../memsickit.pdf ) indicates that the raw memsic data must be converted to acceleration by use of the equation A(g) = ((T1 / T2) – 0.5 ) /12.5% ( where T1 is the sense pulse width, T2 is the total pulse duration).

8. ## Re: Determining Acceleration from Memsic 2125

robotics,

The formula is derived from the manufacturer and can be found on their documentation here...

http://www.parallax.com/Portals/0/Do...MXD2125G&M.pdf

... "The acceleration is proportional to the ratio T1/T2. The zero g output is set to 50% duty cycle and the sensitivity scale factor is set to 12.5% duty cycle change per g."

A = (T1/T2 - 0.5) / 12.5%

...It a very similar formula to what you have been using.

i.e.
y = (y MIN 1875 MAX 3125) - 1875 ** 10538
... compared to ...
a = (T1/T2) - 0.5 * 12.5%

Where you have a 'raw value' (T1/T2) and you offset it by some amount to 'zero it out' (-0.5), and then you apply a scaling factor to make the data a little more human readable (* 12.5%)

The reason for multiplying by 12.5% can be a little misleading the way it's written.

12.5% = 1/8th of the Whole

So essentially by multiplying by 12.5% you are really dividing by 8