Report
4 years, 3 months ago.

Dividing by 15 bug

A very helpful library, thank you for creating it.

One thing that confused me was the division by 15. It's not immediately obvious, but the data by default is in the highest 12 bits of a 16bit number spread across two registers. The sensitivity is expressed as X mg per digit, but this is per digit of the 12bit representation. Consequently, you need to right shift the 16bit representation by 4 (aka divide by 16, not 15).

I think this is a more obvious way of showing this in the code (from read_mg_data):

    dt_usr[0] = float(short((data[1] << 8) | data[0]) >> 4) * fs_factor;
    dt_usr[1] = float(short((data[3] << 8) | data[2]) >> 4) * fs_factor;
    dt_usr[2] = float(short((data[5] << 8) | data[4]) >> 4) * fs_factor;

.

Please correct me if I have made a mistake.

Question relating to:

LIS3DH / STMicroelectronics / MEMS motion sensor, 3-axis accelerometer library I2C, LIS3DH

Hello Chris, Could you please upload your final code? Thank you, Allex

posted by Allex Lmbed 16 Oct 2015

Hi Allex, there is actually a second bug here in that the sensitivity is expressed in g per digit, not mg per digit (e.g. #define LIS3DH_SENSITIVITY_2G (0.001F) where the sensitivity is 1mg per digit). So the function gives the results in g not mg. Example usage: float f[3] = {0}; acc.read_mg_data(f); printf("acceleration in g is: a_x = %+.3f, a_y = %+.3f, a_z = %+.3f\r\n", f[0], f[1], f[2]);

posted by Chris P 16 Oct 2015
Comment on this question

1 Answer

3 years, 9 months ago.

Hi Chris,

Thanks your comments and I agreed your explanation. I fixed those bugs and updated it. I'm sorry not to answer until today. I haven't come to mbed web page due to my busy business condition. I made a check program as follows. /users/kenjiArai/code/Check_new_LIS3DH_lib/

Thanks your suggestion!


You need to log in to post a question