With a peak-calibrated system, bipolar sensor data can be normalized to ±1 for use with the arctan2 (two sensors) or arcsin (one sensor) function in order to determine the angle. Arctan2 must be used instead of arctan, because arctan2 accounts for which of the two values are negative. The process for calibration is:
- Find the min and max values from each sensor by continuously reading voltages while rotating the magnet 360°. One full rotation is required, but more rotations help make sure that more accurate min and max values are found.
- Then, during normal operation, each new measured voltage can be normalized to ±1 using Equation 1.
Equation 1.
- The normalized data is then put directly into the arctan2 (two sensors, 0° to 360° output) or arcsin (one sensor, 0° to ±90° output) function in order to get the angle of the magnet.