How to get 14 bit data from MMA8451Q Accelerometer ?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to get 14 bit data from MMA8451Q Accelerometer ?

1,219 Views
Amit_Kumar1
Senior Contributor II

Hi

I want to extract 14 bit data out of MMA8451Q Accelerometer and display it over UART. So for storing I am taking int16_t  x, y, z; the maximum value which I am getting out is 23736 instead of permissible value 2^14 = 16384. and the minimum value which I am getting out is -17736 instead of the permissible value -16384. I am using FRDM-K20D50M board and the accelerometer is mounted on it. I am using codewarrior with processor expert. I am using MMA8451Q library in processor expert and extracting data using x=MMA1_GetX(); or x=MMA1_MeasureGetRawX();  Kindly look into the matter.


Regards,

Amit Kumar

4 Replies

708 Views
terry_lv
NXP Employee
NXP Employee

Hi,

     In mma8451q registers, both OUT_X_MSB[7:0] and OUT_X_LSB[7:2] indicates value of X.

     You have to read OUT_X_MSB and OUT_X_LSB, and get X value by (OUT_X_MSB << 6) | (OUT_X_LSB >> 2).

    Thanks.

Best regards

Terry

708 Views
alissonporto
Contributor III

So, it has been a while... Did you get the answer?

708 Views
Amit_Kumar1
Senior Contributor II

Hi Alisson

It has been a year now. The data being stored in 16 bit data type so to get 14 bit u need to bit shift the received data 2 times. i.e acc_x >> 2; for all x,y,z values. An alternative solution can be dividing the raw 16 bit value by 4. i.e 2^2(on dividing 2^16 by 2^2 u will get 2^14 bit value i.e 14 bit value which we need but in this case the fluctuation in value is observed more.Hope It helps

Best Regards

Amit

708 Views
Amit_Kumar1
Senior Contributor II

Hello

I also tried printf("%d %d %d \n",MMA1_GetX(),MMA1_GetY(), MMA1_GetZ()); and the maximum  values I got was 17408, 15256, 17808 and the minimum values I got was -16384, -16584, -16408 for x,y,z respectively, But the value for 14 bit data should range b/w 16384 to -16384 So i was wondering is it due to the drift in accelerometer?

Regards

Amit Kumar

0 Kudos
Reply