Accelerometer acquisition, filtering and treatment on Pic

accelerometeradcpic

I've been asked to experiment with dynamic testing.
Using accelerometer and strain gage bolted onto a metallic pipe,and hammering it ( the pipe ) I need to show out force of the impact, and displacement of the pipe, in fact sinking in the ground.

There are already systems doing that but it's out of budget and for big pipes.

Strain gage is used to get force of impact and can deal with that.

But for accelerometer, I'm a bit lost.
One full impact recording seems to be close to 50ms.
Example of impact

So I'd need help to point me in the right direction in order to get displacement from accelerometer recordings.

I know how to condition sensors and record data… but next I'm lost 🙂
I should integrate 2 times the accelerometer data in order to get displacement.
That's the hard part for me, as I have never done that using pics, only analog OP AMPs long time ago.

So what kind of integration works best for that type of job ?

Thanks a lot

Best Answer

Assuming you are sampling at a fixed time step, called \$\Delta\$, and \$t_n\$ denote your sample times (i.e. \$t_n = n \Delta\$) then a traditional estimate of the velocity is $$v(t_{n}) \sim \sum_{k=0}^{n-1} a(t_k) \Delta$$ where \$a(t_k)\$ is the acceleration value at time \$t_k\$ as sampled by your accelerometer. It sounds like you are also assuming the initial conditions that \$v(t_0) =0\$ and \$p(t_0) = 0\$.

Applying this idea again to get the position via integrating the computed velocity we obtain $$p(t_{n}) \sim \sum_{k=0}^{n-1} v(t_k) \Delta \sim \sum_{k=0}^{n-1}\sum_{i=0}^{k-1} a(t_i) \Delta^2.$$

This latter summation simplifies a bit to $$\sum_{k=0}^{n-1}\sum_{i=0}^{k-1} a(t_i) \Delta^2 = \sum_{i=0}^{n-2}(n-1-i)a(t_i)\Delta^2 = \left(\sum_{i=0}^{n-3}(n-2-i)a(t_i)\Delta^2\right) + \sum_{i=0}^{n-2}a(t_i)\Delta^2.$$

Now if you notice the bit in parenthesis is our estimate of \$p(t_{n-1})\$ then you see we get the recursive formula \$p(t_{n}) = p(t_{n-1}) + \sum_{i=0}^{n-2} a(t_i)\Delta^2\$. This allows us to easily compute \$p(t_{n})\$ by keeping track of two (and only two) values: \$p(t_{n-1})\$ and an auxiliary variable \$s_n = \sum_{i=0}^{n-2} a(t_i) \Delta^2\$. Note we have the recursive formulas $$s_n = s_{n-1} + a(t_{n-2})\Delta^2$$ and $$p(t_n) = p(t_{n-1}) + s_n.$$

Your computation algorithm will go something like this:

1) Initial: \$p(t_0) = p(t_1) = 0\$. \$s_2 = a(t_0)\Delta^2\$.

2) At stage \$n\$: \$s_n = a(t_{n-2})\Delta^2 + s_{n-1}\$; free the memory containing \$s_{n-1}\$; \$p(t_{n}) = p(t_{n-1}) + s_{n}\$.

3) Repeat.

A few small remarks: You will probably want to delay multiplying everything by \$\Delta^2\$ until the end. You will have to experiment with the size of floating point data type you need so as not to overflow it. You need not use separate variables for \$s_n\$; in XC you would have a statement similar to \$s \hspace{5pt} +\hspace{-5pt}= a(t_{n-2})\Delta^2\$.