Some microcontrollers may not support floating point operation and are timing critical. In
order to build a standalone tilt compensated electronic compass, the following
recommendations may be helpful:
● Use look-up tables for sin, cos, arcsin, and arctan functions to reduce clock cycles
● Use assembly code to implement signed integer multiplication and division subroutines
to reduce clock cycles
● If some sensor calibration parameters are very small, the user can multiply the whole
accelerometer and magnetic sensor calibration parameter matrix with a big constant
integer, then divide it before the pitch/roll/heading calculation
● Use internal EEPROM to save sensor calibration parameters
● Implement some kind of digital filtering or simple moving average function onto the
sensor raw measurements to reduce the noise level and improve the pitch/roll/heading
accuracy
Pololu Github repo on tilt compensation for this sensor controlled with a ATMega chip is here.
Magnetometer (compass) skews when tilted out of the XY plane. Investigate if it is practical to try to implement a tilt-compensation feature.
From ST Micro paper on tilt:
Pololu Github repo on tilt compensation for this sensor controlled with a ATMega chip is here.