cancel
Showing results for 
Search instead for 
Did you mean: 

LIS2MDL Offset Cancellation Issues

Konami
Senior

I'm having trouble getting a heading from the LIS2MDL on our custom PCB. A summary of the issue:

  • If in the presence of a strong magnetic field (ie. magnet), the LIS is able to report the field as expected and I can see headings calculated in the [-180,180] range.
  • If the magnet is removed and we attempt to measure just the earth's magnetic field it seems there is enough offset (even with offset cancellation enabled) to skew the results.
  • After experimentally measuring the remaining offset, I am able to compensate by that vector and then we are able to measure heading correctly. However, this same compensation does not work on other copies of the same board.

My Questions:

  1. Am I configuring the device and offset cancellation correctly?
  2. Is there anything else I can do to correct this reading without manually calibrating each device?
  3. What might the source of this issue be, and what further steps can I take to debug it?

Initialization Procedure:

/* LIS2MDL Initialization: Offset Cancellation Disabled */
  mag_reset();  // Reset device, set SPI mode, read WHOAMI
 
  lis2mdl_block_data_update_set(&mag_ctx, PROPERTY_ENABLE);
  lis2mdl_power_mode_set(&mag_ctx, LIS2MDL_LOW_POWER);
  lis2mdl_offset_temp_comp_set(&mag_ctx, PROPERTY_ENABLE);
  lis2mdl_operating_mode_set(&mag_ctx, LIS2MDL_SINGLE_TRIGGER);
 
 
  /* LIS2MDL Initialization: Offset Cancellation Enabled */
  mag_reset();  // Reset device, set SPI mode, read WHOAMI
 
  lis2mdl_block_data_update_set(&mag_ctx, PROPERTY_ENABLE);
  lis2mdl_data_rate_set(&mag_ctx, LIS2MDL_ODR_100Hz);
  lis2mdl_set_rst_mode_set(&mag_ctx, LIS2MDL_SENS_OFF_CANC_EVERY_ODR);
  lis2mdl_offset_temp_comp_set(&mag_ctx, PROPERTY_ENABLE);
  lis2mdl_operating_mode_set(&mag_ctx, LIS2MDL_CONTINUOUS_MODE);

Logs:

Data dump for both enabled and disabled offset cancellation are attached

Plots:

0690X00000Bwgg9QAB.png

0690X00000Bwgg4QAB.png

1 REPLY 1
Eleon BORLINI
ST Employee

Hi @DB.7ujak​ , sorry for the very late feedback to your question, mainly due to lot of accumulated work. I (try to) answer your questions here below:

0. I suggest you a time0 calibration of each device magnetic offset, to start all the tests in the same condition.

  1. Am I configuring the device and offset cancellation correctly? --> based on the fact that your procedure is working on at least 1 pcb / device, and considering the magnetic disturbance field constant, I believe it is dependent from the geometry of the system, and the reciprocal distance/orientation between the pcb and the magnet.
  2. Is there anything else I can do to correct this reading without manually calibrating each device? --> you should try to uniform the setup (i.e. try to keep the distance between the magnet and the device always the same), and average the results on the N tests.
  3. What might the source of this issue be, and what further steps can I take to debug it? --> see the points 1. and 2.

I suggest you to check the user manual (link) of the MotionMC magnetometer calibration library in X-CUBE-MEMS1 expansion for STM32Cube if it can be of some help.

Regards