Hi,
after a long time I now updated my 3 copters with different boards to a recent version (r1567). On 2 of them I have the problem, that it often get's to a sensor overflow at Mag_init() and the values are not scaled any more.
i2c_writeReg(MAG_ADDRESS, HMC58X3_R_CONFB, 2 << 5); //Set the Gain
This means, the sensor range is +-1,9 gauss. In test operation a field of 1.1 gauss is added. Since the magnetic field is about 0.6 gauss (maximum), the sum is 1.7 in worst case and that leaves not much room for the magnetic noise from the board itself or other sources of magnetic fields. I have now set the gain in self test operation to 2.5 gauss (as it was a long time ago), and everything works fine again.
Code change:
Mag_Init() {
...
i2c_writeReg(MAG_ADDRESS, HMC58X3_R_CONFB, 0x60); //Set the Gain to 2.5 gauss
...
magGain[0]=fabs(660.0*HMC58X3_X_SELF_TEST_GAUSS*2.0*10.0/xyz_total[0]);
magGain[1]=fabs(660.0*HMC58X3_Y_SELF_TEST_GAUSS*2.0*10.0/xyz_total[1]);
magGain[2]=fabs(660.0*HMC58X3_Z_SELF_TEST_GAUSS*2.0*10.0/xyz_total[2]);
Best regards
Peter
Critical values for self test mag hmc5883
Re: Critical values for self test mag hmc5883
Thanks for catching that. I also noticed I failed copypasting and forgot to make explicit floats for this stuff in baseflight.