cancel
Showing results for 
Search instead for 
Did you mean: 

Sensitivity of LIS3MDL (LSB/Gauss)

Khaled Aljehani
Associate III
Posted on September 23, 2017 at 05:45

I am using LIS3MDL sensor and I do not understand the sensitivity which its unit is LSB/Gauss.  

In x-cube-mems1 library, the following is calculated:

&sharpdefine LIS3MDL_MAG_SENSITIVITY_FOR_FS_4G    0.14 /**< Sensitivity value for 4 gauss full scale [mgauss/LSB] */

&sharpdefine LIS3MDL_MAG_SENSITIVITY_FOR_FS_8G    0.29 /**< Sensitivity value for 8 gauss full scale [mgauss/LSB] */

&sharpdefine LIS3MDL_MAG_SENSITIVITY_FOR_FS_12G    0.43 /**< Sensitivity value for 12 gauss full scale [mgauss/LSB] */

&sharpdefine LIS3MDL_MAG_SENSITIVITY_FOR_FS_16G    0.58 /**< Sensitivity value for 16 gauss full scale [mgauss/LSB] */

and in the datasheet:

0690X00000603jKQAQ.jpg

My question is how did they calculate the sensitivity in the above code? and also what does LSB/Gauss mean?

Thanks in advance. 

#lsb/gauss #lis3mdl
1 ACCEPTED SOLUTION

Accepted Solutions
Legacy member
Not applicable
Posted on September 23, 2017 at 09:33

Regarding the values in the code mentioned in the cube library:

For +/- 4 gauss, the sensitivity is 6 842 LSB / gauss, meaning 6 842 = 1 gauss, 12 964 = 2 gauss, 19 806 = 3 gauss, etc...

However, one way to interpret the data is to read the raw value and display as miligauss.

If 1 gauss = 6 842, then 1 000 mgauss = 6 842, meaning 1 000 mgauss / 6 842 = 0,146156 mgauss / LSB.

The same applies to the other ranges. It is just a different look at the same data.

I personally prefer to keep the precision and use integer math as much as possible in microcontrollers, which is why I wrote my own 'driver' to read, compute and display the values from the sensor.

View solution in original post

6 REPLIES 6
Legacy member
Not applicable
Posted on September 23, 2017 at 09:25

Hello,

have a look at this earlier discussion, I had the same question before:

https://community.st.com/0D50X00009XkXwiSAF

David

Legacy member
Not applicable
Posted on September 23, 2017 at 09:33

Regarding the values in the code mentioned in the cube library:

For +/- 4 gauss, the sensitivity is 6 842 LSB / gauss, meaning 6 842 = 1 gauss, 12 964 = 2 gauss, 19 806 = 3 gauss, etc...

However, one way to interpret the data is to read the raw value and display as miligauss.

If 1 gauss = 6 842, then 1 000 mgauss = 6 842, meaning 1 000 mgauss / 6 842 = 0,146156 mgauss / LSB.

The same applies to the other ranges. It is just a different look at the same data.

I personally prefer to keep the precision and use integer math as much as possible in microcontrollers, which is why I wrote my own 'driver' to read, compute and display the values from the sensor.
Posted on September 24, 2017 at 06:32

Thanks

Koudela.David

‌ for your reply. It helped me alot.

I still did not get it 100%.

The original equation is:

magnetic_intensity (in gauss) = raw_data / sensitivity

So, for this equation the sensitivity is a value from the table in the datasheet(6842 or 2..etc)

Am I correct here?

Now, regarding LSB/gauss. What I understand is

6842 LSB = 1 gauss,

6842 LSB = 1000 mgauss

So, sensitivity = 6842/1000 = 6.8

My question is why did you calculate it in that way? (1000 mgauss / 6842 LSB = 0.14)

Last thing, in the cube library, they use this equation: mgauss = raw data * sensitivity.

Should not we use this one (magnetic_intensity (in gauss) = raw_data / sensitivity)?

Again, I really appreciate your help.

Legacy member
Not applicable
Posted on September 24, 2017 at 17:56

Hello

khaledaljehani99

‌,

Khaled Aljehani wrote:

The original equation is:

magnetic_intensity (in gauss) = raw_data / sensitivity

So, for this equation the sensitivity is a value from the table in the datasheet(6842 or 2..etc)

Am I correct here?

Yes, you are.

Now, regarding LSB/gauss. What I understand is

6842 LSB = 1 gauss,

6842 LSB = 1000 mgauss

So, sensitivity = 6842/1000 = 6.8

My question is why did you calculate it in that way? (1000 mgauss / 6842 LSB = 0.14)

Last thing, in the cube library, they use this equation: mgauss = raw data * sensitivity.

Should not we use this one (magnetic_intensity (in gauss) = raw_data / sensitivity)?

There are at least two ways of calculating the output value, if you know that the sensitivity is 6 842 LSB per 1 gauss (=1 000 mgauss) and the sensor gives you output of

–32,768 to 32,7

1)

magnetic_intensity = raw_data / sensitivity

with the following units:

[gauss] = [LSB] / [LSB/gauss]

so sensitivity is represented here as[LSB/gauss]

This relates to the values printed in the datasheet and discussed in the linked discussion.

2)

magnetic_intensity = raw_data * sensitivity

with the following units:

[gauss] = [LSB] * [gauss/LSB]

so sensitivity is represented here as

[gauss/LSB] (which is an inverted value)

The fact whether you count with gauss or miligauss doesn't affect the equation, just the sensitivity coefficients (and/or the result).

This relates to the values in the Cube library.

0.14 < Sensitivity value for 4 gauss full scale [mgauss/LSB] (= 0,000 14 gauss/ LSB)

0.29 < Sensitivity value for 8 gauss full scale [mgauss/LSB] (= 0,000 29 gauss / LSB)

0.43 < Sensitivity value for 12 gauss full scale [mgauss/LSB] (= 0,000 43 gauss / LSB)

0.58 < Sensitivity value for 16 gauss full scale [mgauss/LSB]

(= 0,000 58 gauss / LSB)

-----

ST chose version 2, however, I like version 1 more. Version 1 can be faster and use less resources, moreover, with a higher precision!

If the sensitivity was a round number in both cases, it would perform the same, but it is not in this case.

Example 1:

If the sensor gives you an output of 6 842, method 1 will tell you that the output is 1 gauss. Method 2 will tell you that the output is 957 mgauss (about 4 % difference). (This also comes from the fact that

0,146156 mgauss / LSB was rounded to 0,14, not 0,15 as I would expect).

You might say that method 1 output only an integer value in gauss and that you want output in miligauss. There is no problem with that, just multiply the raw_data with a 1000 and you get a 1000 x bigger result (which is what you need, because 1 gauss = 1000 mgauss).

Example 2, raw data = 10 000:

Method 1:

magnetic_intensity [mgauss] = ( raw_data * 1 000) / sensitivity

magnetic intensity [mgauss] = 10 000 000 / 6 842 = 1 461 mgauss (=1,461 gauss)

Method 2:

magnetic_intensity [mgauss] = raw_data * sensitivity

magnetic_intensity [mgauss] = 10 000 * 0,14 = 1 400 mgauss ( = 1,400 gauss) =again, about 4 % error

However, method 1 has a downside - if you multiply an output value (by a 1 000 in this example), make sure your data type will handle this.

In this case sensor raw_data is –32,768 to 32,767 , multiplied by 1 000 gives us -32 768 000 to 32 767 000 and this easily fits into a signed int32 with –2,147,483,648 to 2,147,483,647 range.

You can the code of method 1 on your own, just call the method below with raw_data as signed int16 as a parameter.

#define DECIMAL_3DIGIT_FACTOR 1000u // 3decimal points multiplication

#define COUNT_TO_GAUSS_4G_SCALE 6842; // measured data count per 1 Gauss, full scale +/- 4 g

#define COUNT_TO_GAUSS_8G_SCALE 3421; // measured data count per 1 Gauss, full scale +/- 8 g

#define COUNT_TO_GAUSS_12G_SCALE 2281; // measured data count per 1 Gauss, full scale +/- 12 g

#define COUNT_TO_GAUSS_16G_SCALE 1711; // measured data count per 1 Gauss, full scale +/- 16 g

// converts magnetometer data (hex) to Gauss unit

int32_t MM_Convert_To_Gauss (int16_t magnetometerData) {

int32_t mgaussData;

mgaussData = (magnetometerData * DECIMAL_3DIGIT_FACTOR);

mgaussData /= COUNT_TO_GAUSS_4G_SCALE;

return gaussData;

}

Posted on September 25, 2017 at 09:46

Well explained

Koudela.David

You really helped me a lot with the equations.

I really do not understand why such an information is not added in either datasheet nor application note.

I want to ask, is there a reference for calculating the output values? Because I searched a lot and did not find any thing.

Again, thanks for your effort with me.

Legacy member
Not applicable
Posted on September 25, 2017 at 10:16

I am glad you find the information useful.

The same suprise happened to me, as you could see in the earlier discussion. I also think these simple explanations should be added to datasheet and/or the related application note.

The same way of computing output values is used for a lot of other sensors (if not all) - accelerometers, gyroscopes, pressure sensors...