cancel
Showing results for 
Search instead for 
Did you mean: 

LSM303AGR temperature compensation

MHuk
Associate II

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? 

1 ACCEPTED SOLUTION

Accepted Solutions
Miroslav BATEK
ST Employee

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

0690X000006CFiLQAW.png

View solution in original post

5 REPLIES 5
Miroslav BATEK
ST Employee

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
Associate II

@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
Associate II

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

Miroslav BATEK
ST Employee

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

0690X000006CFiLQAW.png

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?