Skip to main content
MHuk
Associate II
Oct 19, 2018 12:31 PM UTC
Solved

LSM303AGR temperature compensation

Temperature compensation for this magnetometer is not working as I expect. When heating device from room temperature to 50-60 degrees Celsius in 3 minutes magnetometer values are changing a lot. 

I have 100Hz ODR, high-precision mode, temperature sensor and temperature compensation enabled, offset cancelation disabled. 

Anyone having an idea what else should I set up? What is the normal (delta C / minute) which sensor can work with while compensating properly? 

This topic has been closed for replies.
Miroslav BATEKBest answer
ST Employee
Oct 25, 2018 8:41 AM UTC

You have to also enable offset cancellation, to achieve specified offset vs temperature.

0690X000006CFiLQAW.png

5 replies

ST Employee
Oct 22, 2018 12:28 PM UTC

What it means the values are changing a lot?

Can you please share your results and exact sensor configuration so I can check it?

MHuk
MHukAuthor
Associate II
Oct 22, 2018 12:41 PM UTC

@Miroslav BATEK​ 

Here is the log from the device, raw value is plotted in red. So change is around 100, 50 and 15 mGauss for Z, Y and X axes respectively.

I would be happy if all 3 axes will behave as X but in current setup it gives me false positives.

My initialization code is:

mgn_status_t LSM303AGR_M_Init(void)
{
 if (LSM303AGR_M_Check_WhoAmI() == MAGNETO_ERROR)
 {
 return MAGNETO_ERROR;
 }
 
 /* Operating mode selection - power down */
 if (LSM303AGR_MAG_W_MD(0, LSM303AGR_MAG_MD_IDLE1_MODE) == MEMS_ERROR)
 {
 return MAGNETO_ERROR;
 }
 
 /* Enable BDU */
 if (LSM303AGR_MAG_W_BDU(0, LSM303AGR_MAG_BDU_DISABLED) == MEMS_ERROR)
 {
 return MAGNETO_ERROR;
 }
 
 if (LSM303AGR_M_Set_ODR(ODR_LOW) == MAGNETO_ERROR)
 {
 return MAGNETO_ERROR;
 }
 
 if (LSM303AGR_M_Set_FS(FS_LOW) == MAGNETO_ERROR)
 {
 return MAGNETO_ERROR;
 }
 
 /* Disable Self-test */
 if (LSM303AGR_MAG_W_ST(0, LSM303AGR_MAG_ST_DISABLED) == MEMS_ERROR)
 {
 return MAGNETO_ERROR;
 }
 
 /* High-resolution mode */
 if (LSM303AGR_MAG_W_LP(0, LSM303AGR_MAG_HR_MODE) == MEMS_ERROR)
 {
 return MAGNETO_ERROR;
 }
 
 /* Low-pass filter */
 if (LSM303AGR_MAG_W_LPF(0, LSM303AGR_MAG_LPF_ENABLED) == MEMS_ERROR)
 {
 return MAGNETO_ERROR;
 }
 
 /* Enable TEMP sensor */
 if (LSM303AGR_MAG_W_TemperatureSensor(0, LSM303AGR_MAG_TEMP_EN_ENABLE) == MEMS_ERROR)
 {
 return MAGNETO_ERROR;
 }
 
 /* Enable TEMP compensation */
 if (LSM303AGR_MAG_W_COMP_TEMP_EN(0, LSM303AGR_MAG_COMP_TEMP_EN_ENABLED) == MEMS_ERROR)
 {
 return MAGNETO_ERROR;
 }
 
 /* Offset cancellation */
 /*if (LSM303AGR_MAG_W_OFF_CANC(0, LSM303AGR_MAG_OFF_CANC_ENABLED) == MEMS_ERROR)
 {
 return MAGNETO_ERROR;
 }*/
 
 return MAGNETO_OK;
}

I am sure that I have COMP_TEMP_EN = 1 and TEMP_EN[1:0] = 1

0690X000006CEAjQAO.png

MHuk
MHukAuthor
Associate II
Oct 25, 2018 8:32 AM UTC

@Miroslav BATEK​ did you have any chance to look at it? Is it normal behavior of the sensor or not?

Miroslav BATEKBest answer
ST Employee
Oct 25, 2018 8:41 AM UTC

You have to also enable offset cancellation, to achieve specified offset vs temperature.

0690X000006CFiLQAW.png

Atahe.2113
Visitor II
Dec 7, 2019 12:18 PM UTC

I want to use LSM303AGR instead of LIS3MDL to detect a vehicle parking status.

If i get the x-y-z component every second and calculate X=X_new - X_Previous, then new vehicle that comes near sensor is neglected after 1 second and i can't detect a vehicle that parked for 1 hour!

Does "offset cancellation" option do sth like this?

In other word, if i enable offset cancellation, Does it effect on total X(ory or z) components or just their thermal drift?