I'm currently using a ADXL335 chip two measure acceleration then converting it into a displacement. I'm wanting to measure the vetical (-z direction) displacement range of maximum 10cm, so quite small. I have read the data from the ADXL335 and converted it into "g's". I then numerical integrate (trapezoidal) it twice in order to convert the g's into displacement. I only want to measure the vertical displacement in the -Z direction.
Sample rate == 100Hz; using a 12 bit ADC; Vref == 3.3volts;
here is my CVI/c code:
//every sample (0.01 seconds) acceleration = (((((adc - 2420)*3.3)/4096)/0.3)*-9.8);//subtracting 2420 to account for the acceleration due to gravity. acceleration_1 = acceleration; velocity = velocity_1 + (((acceleration+acceleration_1)/2)*0.01); velocity_1 = velocity; displacement = displacement_1 + (((velocity+velocity_1)/2)*0.01); displacement_1 = displacement;
....//then I output the displacement data and have a condition to reset the values of the velocity and displacement to zero (when the acceleration goes positive as only need the vertically down direction).
My problem is that I'm getting incorrect values of displacement and my observation so far is that the faster the accelerometer moves the higher the displacement will be.
Would appreciate all the help i can get, been stuck on this problem for a while and not able to make sense of it.
I also tried using a High pass filter to remove the dc offset of the acceleration with no luck (The subtract works?). I also tried implementing another button to control when I integrate. For example integrate when the button is push and set the data values to zero when not pressed.
Hope my problem is clear, In essence my displacement output depends on the rate of acceleration and not the total distance.