# Temperature compensation of LSM303DLHC accelerometer / magnetometer

ST Microelectronics makes the LSM303XXXX, a popular range of 3-axis accelerometer / magnetometer sensors that are used on Arduino breakout boards, etc.

The older LSM303DLH sensor has been replaced by the LSM303DLHC with has improvements in power and data transfer. However, the new LSM303DLHC sensor has a zero-g acceleration delta of 0.5mg/deg compared to the much tighter 0.1mg/deg for the older LSM303DLH.

Using the newer sensor, variation with temperature is noticeable in our data. Fortunately, the LSM303DHLC has a temperature sensor onboard.

• What method should I use the compensate for sensor drift using the temperature readings? Just a look-up table / simple formula?

• For batches of instruments (10 - 100) is there any alternative to calibrating each instrument?

• Will the effect of temperature change over time? i.e. how long until another temperature calibration needs to be done?

EDIT: mg units

In order to compensate for temperature drift, you need to place your accelerometer in a temperature chamber (e.g. these) and concurrently record both temperature and raw acceleration values while slowly changing the chamber temperature over the range of interest (ideally about ~1°/minute). If your accelerometer is well placed, you know that the true value you should be measuring is [0, 0, -9.81 m/s] and any deviation has to be due to temperature drift. Based on this, you can apply some kind of fit to the measured data to build a calibration that you subsequently use to predict the drift based on the measured temperature.

My experience is the following:

• A polygonal fit of order 3 is enough to implement the calibration. Depending on the temperature performance of your particular sensor (I haven't tested it), a linear fit may be sufficient.
• The sensor gain (the factor that convert from raw value to G) is relatively immune to temperature, but the sensor offset (additive value) is temperature dependant.
• For sensor types that are prone to temperature drift, there is a high degree of sample-to-sample variation. You should thus consider calibrating every single parts.
• More recent parts, such as the LIS3DH, exhibit much lower temperature drift as older parts. This particular one could go without temperature calibration for most applications but the most demanding.
• Thanks. I made a mistake with the units - it is meant to be mg. LIS3DH has same performance. 0.5mg doesn't sound like much but if I can reduce that then the instrument will have a much greater range. – geometrikal Jul 3 '13 at 22:22
• Then it looks like calibration is in order for your application. – abey Jul 4 '13 at 7:44

These are really questions you should be asking the manufacturer. If the datasheet doesn't say anything beyond the maximum possible change due to temperature, then we can't answer this.

However, temperature dependence is usually a low frequency curve. Common ways to do temperature compensation is by polynomial fit or lookup table. Usually the lookup table approach is simpler in the firmware and will take less space and cycles unless you already have floating point routines loaded for some other reason. Something like a 16 point table used with linear interpolation is probably plenty good enough. This table would provide the offset value to add based on the current measured temperature. Actually it doesn't need to be real temperature. The table index can be based on the raw temperature sensor reading, regardless of how linear or calibrated that is. In other words, the table says that when the temperature sensor says X, you add Y to the accelleration reading. You don't need to care what the units of X are.

Yes, you will likely need to calibrate each unit individually in production. That compesates both for the errors in the temperature sensor and the temperature dependence of the accellerometer.

1/2 g per degree, really!!? That means that after only a 2° change, you could be off by 1 g. Unless this is meant to measure 100s of g, that's ridiculous.

• My mistake - units were meant to be mg – geometrikal Jul 3 '13 at 22:16
• I'll ask the manufacturer too. – geometrikal Jul 3 '13 at 22:22