I have a problem with my threshold value and offset value on the z-axis off the magnetometer.
With no magnets in place, I take a couple of readings and get an average. I then left shift this value one place and write it to the M_OFF_Z register to account for the natural magnetic field of the earth. This works perfectly, i take some readings after i have wrote to the registers and the readings are roughly 0.
My problem is when with the threshold value i feel. With my offset done, i put a magnet in place, take a couple of readings to get an average, I then directly write this number(absolute, not shifted etc) to the z-axis Threshold register. I then go to test this to make sure its all ok (when the magnetic field strength on the z-axis exceeds that of the threshold value it will generate an interrupt). But my interrupt is generated before it can reach the value of the threshold value. My interrupt is generated exactly my threshold value minus my offset value (before been left shifted).
From my understanding from the datasheet:" The thresholds for each axis are applied after the magnetic data has been adjusted by the offset values stored in the M_OFF_X/Y/Z registers when M_CTRL_REG3[m_raw] = 0". my m_raw is 0.
From what i can see my offset is ignoring by threshold. Can anyone help me with this?