Hello
I am using code warrior with processor expert, I am using the MMA8451Q Accelerometer library in PE. I printed 100 values of the accelerometer's reading in same position without even touching it, and programatically after 100 readings the mode changed from 2 to 4 and later 8G, but in all 3 sets of values the readings are differing for more than 250 values. but ideally all the 100 values should remain the same. So I want to know how to overcome this problem? I tried changing modes from 2g, 4g, 8g but in all three case the values are differing a lot so I wanted to know how to use these diff. modes ? some required piece of code I am posting below
#define MMA8451_I2C_ADDR (0x1D) /* I2C slave device address as set in the properties */
#define XYZ_DATA_CFG 0X0E
#define EIGHT_G 0X02
#define FOUR_G 0X01
#define TWO_G 0X00
after init function i used
GI2C1_WriteByteAddress8(MMA8451_I2C_ADDR, XYZ_DATA_CFG, EIGHT_G);
for data acquiring , in for loop I used
f_printf(&fp, "%d %d %d \n",MMA1_GetX(),MMA1_GetY(), MMA1_GetZ());
after 100 readings I again changed the mode and did the same.
I am attaching extracted data in different modes.ACC2, ACC4, ACC8 shows accelerometer readings in 2G, 4G, 8G mode.
Kindly look into the matter
Regards,
Amit Kumar
Original Attachment has been moved to: acc_readings.zip
Solved! Go to Solution.
Hello Amit,
First, looking at the extracted data, it seems that you are not changing the dynamic range properly. To change the dynamic range by setting the FS0 and FS1 bits in the XYZ_DATA_CFG register (0x0E), the MMA8451Q must first be put into Standby mode by clearing the ACTIVE bit in the CTRL_REG1 register (0x2A). Then you can write the selected dynamic range in the XYZ_DATA_CFG register and put the part back into the Active mode by setting the ACTIVE bit in the CTRL_REG1 register.
Further, you need to convert the 16-bit raw data to the correct 14-bit signed (2's complement) numbers. quevedo has already explained it clearly in your another thread.
Now, having the correct data, you will see that the values still fluctuate a little. This fluctuation depends mainly on the selected ODR (DR[2:0] bits) and mode ((S)MODS[1:0] bits). You can minimize it by setting the LNOISE bit and selecting the lowest ODR (1.56Hz) and the High Resolution mode. For more information, please refer to our AN4075.
I hope this helps.
Regards,
Tomas
Thanks Tomas
Following the above mention steps I was able to change the different modes of the accelerometer. but still facing the noise problem. I will go through the document and try to resolve the issue and update it
Regards
Amit Kumar
Amit,
I have just created a simple bare metal example code that illustrates how to achieve the best noise performance on the MMA8451Q.
If you look at Xout_14_bit, Yout_14_bit or Zout_14_bit variables in the "Variables" window on the top right of the Debug perspective, you will see that they fluctuate by 1 count (1 LSB = ~0.25mg).
The code is written in the CW 10.5 for the FRDM-KL25Z board.
Let me know if you found it useful or if you need any further help.
Regards,
Tomas
Thanks a lot Tomas
Now the values are very much stable. But Now I am facing another problem, I am printing these values through UART so for Xout_g the floating values are not being printed. i.e I used %f in printf and instead of printing the values it is printing "%f" only. Please help me to resolve this issue.
Thanks
Amit Kumar
Amit,
I would recommend using the Term component and the SendFloatNum() method. BlackNight described this component in this tutorial.
I hope it helps.
Regards,
Tomas
Hello Amit,
First, looking at the extracted data, it seems that you are not changing the dynamic range properly. To change the dynamic range by setting the FS0 and FS1 bits in the XYZ_DATA_CFG register (0x0E), the MMA8451Q must first be put into Standby mode by clearing the ACTIVE bit in the CTRL_REG1 register (0x2A). Then you can write the selected dynamic range in the XYZ_DATA_CFG register and put the part back into the Active mode by setting the ACTIVE bit in the CTRL_REG1 register.
Further, you need to convert the 16-bit raw data to the correct 14-bit signed (2's complement) numbers. quevedo has already explained it clearly in your another thread.
Now, having the correct data, you will see that the values still fluctuate a little. This fluctuation depends mainly on the selected ODR (DR[2:0] bits) and mode ((S)MODS[1:0] bits). You can minimize it by setting the LNOISE bit and selecting the lowest ODR (1.56Hz) and the High Resolution mode. For more information, please refer to our AN4075.
I hope this helps.
Regards,
Tomas