cancel
Showing results for 
Search instead for 
Did you mean: 

Can offset registers on LIS2MDL compensate strong magnetic field?

MHo
Associate II

Hi,

I'm working on a prototype device. It is very compact, battery powered and has a motor inside. I want to know if the offset can be set (during production) to compensate a very strong magnetic field and still be able to detect earth magnetic field for heading. Is there any other way/sensor can achieve this?

Thank you,

Min-Ching Ho

10 REPLIES 10
Eleon BORLINI
ST Employee

Hi @Community member​ , it depends on how strong is the sensed magnetic field. From the absolute maximum ratings of the datasheet p.14, the Maximum exposed field is 10000 gauss (and I believe you won't exceed this field intensity...). The magnetic sensor full scale is however well below this value, at +-50 gauss. Supposing the case of a full hard iron compensation, the procedure is described in the AN5069 p.19 and allows a maximum compensation per axis is of the order of magnitude of FS/2, acting of registers from OFFSET_X_REG_L (45h) to OFFSET_Z_REG_H (4Ah). Unfortunately, the magnetometer with maximum FS in ST portfolio is the LIS2MDL, and it is not possible to compensate background static magnetic field greater than 50 gauss. Regards

MHo
Associate II

Hi @Eleon BORLINI​ ,

Sorry for late reply. I found some hard-iron calibration method on line. But, I don't know which method works. Does ST have any document describe how to perform a proper hard-iron calibration (on production line)?

Thank you,

Min-Ching Ho

Hi Min-Ching Ho, sure, you can refer to the UM2192: MotionMC magnetometer calibration library in X-CUBE-MEMS1 expansion for STM32Cube.

/* Magnetometer calibration algorithm update */
MotionMC_Update(&data_in);
/* Get the magnetometer calibration coefficients */
MotionMC_GetCalParams(&data_out);
/* Apply calibration coefficients */
mag_cal_x = (int)((data_in.Mag[0] - data_out.HI_Bias[0]) * SF_Matrix[0][0]
 + (data_in.Mag[1] - data_out.HI_Bias[1]) * SF_Matrix[0][1]
 + (data_in.Mag[2] - data_out.HI_Bias[2]) * SF_Matrix[0][2]);
mag_cal_y = (int)((data_in.Mag[0] - data_out.HI_Bias[0]) * SF_Matrix[1][0]
 + (data_in.Mag[1] - data_out.HI_Bias[1]) * SF_Matrix[1][1]
 + (data_in.Mag[2] - data_out.HI_Bias[2]) * SF_Matrix[1][2]);
mag_cal_z = (int)((data_in.Mag[0] - data_out.HI_Bias[0]) * SF_Matrix[2][0]
 + (data_in.Mag[1] - data_out.HI_Bias[1]) * SF_Matrix[2][1]
 + (data_in.Mag[2] - data_out.HI_Bias[2]) * SF_Matrix[2][2]);
}

The algorithm between data in and data out is ST proprietary, but you can find some more details in the design tip document DT0059: Ellipsoid or sphere fitting for sensor calibration. Regards

MHo
Associate II

Thank you, @Eleon BORLINI​ . I'll check those documents.

Min-Ching Ho

MHo
Associate II

Hi @Eleon BORLINI​ ,

I tried to integrate MotionMC library into my test code. I was able to build it on a different platform, nRF52840. When the code calls MotionMC_Initialize(), it always crashed. Can you help on this?

The test call looks like this:

char MotionMC_LoadCalFromNVM(unsigned short int datasize, unsigned int *data)
{
  return (char)1; /* FAILURE: Read from NVM not implemented. */
}
 
char MotionMC_SaveCalInNVM(unsigned short int datasize, unsigned int *data)
{
  return (char)1; /* FAILURE: Write to NVM not implemented. */
}
 
static void _CalibrationHandler( nrf_cli_t const * inCLI, size_t argc, char **argv )
{
    char lib_version[36] = {0};
 
    MotionMC_Initialize( 20, 1 );  // system crashes when this is called.
    MotionMC_GetLibVersion(lib_version);
 
    nrf_cli_fprintf( inCLI, NRF_CLI_NORMAL, "MotionMC lib ver %s\r\n", lib_version );
}

Another question, do you have MotionMC library built with "-mfloat-abi=hard"?

Thank you,

Min-Ching Ho

MHo
Associate II

I have found the answer. It seems your library can only run on STM32 chips.

Hi Min-Ching Ho, of course the libraries "as-they-are" shall run on STM32 MCU. However, regarding your question "Another question, do you have MotionMC library built with "-mfloat-abi=hard"?" , the X-CUBE-MEMS1 package can be compiled to run on all ARM-based MCUs and with the soft, but since the the release of STM proprietary libraries is subject to signature of a License User Agreement (LUA), you should contact an STMicroelectronics sales office and representatives for further information.

Please also check this discussion if it can be of your help --> https://community.st.com/s/question/0D50X0000Bvk9coSQA/source-code-for-stcoms-xcubemems1-available

"Go to project properties and try to find the settings there,

I don't have Attolic TrueStudio but in STM32CubeIDE it looks like in the attached screenshot.

0693W000001sV20QAE.png

"

Regards

@Eleon BORLINI​ ,

Thank you for the info. I checked your MotionMC library. I found it is using some HW modules, e.g. RAM ECC. We are using a SoC from another vendor. If we contact with your representatives, will we be able to get a library that could run on a different SoC? If we can get one, will the performance be significantly lower?

Thank you,

Min-Ching Ho

Slong.1
Associate II

Hello, can you use these libraries on nrf52840?