SLYA069 October 2022 TMAG5170 , TMAG5170-Q1 , TMAG5173-Q1 , TMAG5273

Multi-axis, linear Hall-effect sensors, such as TMAG5170, TMAG5173, or TMAG5273 offer the ability to track the directionality of the magnetic field of a rotating magnet. Given that the field vector components are naturally 90 degrees out of phase from each other, the absolute position of the magnet can quickly be determined.

While the previously-mentioned devices are capable of generating angle results using the CORDIC algorithm, it is sometimes desirable to apply a running averaging, get extended floating point accuracy, or to perform calculations for the complete vector in 3D space. Vector calculations can be performed using CORDIC to find planar, spherical, or cylindrical angles and magnitudes. These measurements require implementing the calculations within the microcontroller. When the magnet is rotating quickly, any unnecessary delays in this calculation can be minimized to achieve the least amount of system latency.

The Coordinate Rotation Digital Calculator (CORDIC) algorithm is a process by which an angle within a two-dimensional plane can be calculated by a series of binary search approximations. The process begins by performing coordinate space rotations with the target of ending with a vector in one dimension. In theory, this is most efficiently accomplished using a binary search, where the vector rotation begins at 45 degrees. At each step, the quadrant in which the vector lies is determined, and either a clockwise or counterclockwise rotation half of the previous rotation is applied. This process can run a fixed number of iterations and the output of the algorithm produces both the angle and magnitude of the original vector.

In application, establishing a rotation pattern is best and can easily be applied using digital logic. To produce a coordinate space rotation, multiply by the tangent of the rotation angle. When applied using a true binary search, the first 5 iterations require storing a floating point number for each step in a lookup table. This example is shown in Table 1-1.

α_{n} - Rotation Angle in degrees |
tan(α_{n}) |
---|---|

45 | 1 |

22.5 | 0.414 |

11.25 | 0.199 |

5.625 | 0.98 |

2.8125 | 0.049 |

As long as the rotation angle
used is greater than or equal to each of these steps, converging to a final result
is always possible. Therefore, an alternate method to multiplying by
tan(α_{n}) is to simply divide by two by performing a simple rightward
bit shift. The effective rotation angles in Table 1-2 are the result
of calculating the arctangent of 2^{–n}.

2^{–n} |
Effective Rotation Angle in Degrees |
---|---|

1 | 45 |

0.5 | 26.565 |

0.25 | 14.036 |

0.125 | 7.125 |

0.0625 | 3.576 |

For each step, the result of a rightward bit shift is somewhat larger than the true binary step size. The result is that the search can require one or two more iterations, but this is made up for by not requiring time to parse though a lookup table and load results. The bit shift operation is accomplished in much less time.

More step-by-step details regarding
the derivation of equations used to apply this algorithm are found in the *Angle
Measurement With Multi-Axis Hall-effect Sensors* application
report. Code examples implementing CORDIC using TMAG5170 and
for translating into other coordinate spaces are available at TMAG5170-CODE-EXAMPLE.

With the CORDIC implemented on the TI-SCB which runs with an internal clock of 120 MHz, calculation times as low as 3.4 μs can be achieved for a single 10-iteration loop.

With a fast method for angle calculations, it is now possible to extend calculations from two-dimensional angle and magnitude to a complete three dimensional space. Using planar angles, both the angle and magnitude of a vector in 3D space can be described. This method requires calculating the magnitude of the vector within two separate planes, such as ZY and XZ, and calculating the angle relative to the magnitude of the component that is normal to this.

Equation 1 and Equation 2 demonstrate how these angles are calculated:

Equation 1.
${\theta}_{ZY}=\mathrm{a}\mathrm{tan}\left(\frac{\sqrt{{Z}^{2}+{Y}^{2}}}{X}\right)$

Equation 2.
${\theta}_{ZX}=\mathrm{a}\mathrm{tan}\left(\frac{\sqrt{{Z}^{2}+{X}^{2}}}{Y}\right)$

For
example, consider a B-field vector whose components are B_{X} = 3 mT,
B_{Y} = 6 mT, and B_{Z} = 8 mT. Combined with the magnitude from
the ZY plane, the first angle result produced by Equation 1 describes any
point along the circumference of a circle that is parallel to ZY, and separated by
this angle.

Similarly, Equation 2 describes a perpendicular circle which is parallel to the ZX plane.

The original vector in Cartesian coordinates lies at the intersection of these two circles. This results in two intersections, so these results are constrained to cases where the Z component is always positive or always negative, such as can be observed in a joystick control.

Since this format relies heavily on both angle and magnitude, a quick calculation of this result can be made using CORDIC. When executed, the planar angle calculation can be fully completed in 16.2 μs when using 10 iteration CORDIC calculations under the same conditions cited in CORDIC.

Translations from Cartesian XYZ
coordinates to spherical are helpful, particularly when the magnet remains at a
fixed range from the sensor and orbits radially. Translations are demonstrated in
the *Measuring 3D Motion with Absolute Position Sensors*
application brief.

This process is achieved by finding the angle φ using the X and Y component. The angle θ is calculated using the Z component and the magnitude of XY. Using CORDIC for this angle calculation also produces the radius as the final magnitude in two passes.

Spherical calculations require two CORDIC calculations to complete, so the total calculation time to translate from the Cartesian coordinate space is about 7 μs.

Cylindrical Coordinate Translations are also simple. A single 3.4-μs pass using CORDIC on the X and Y results produces both a radius and angle. Z is not transformed when changing to this coordinate space.

3D magnetic sensors offer an dramatic increase in measurements of an existing B-field. Depending on the type of motion being observed, there are several methods of applying data from each of the axes to map the result to a useful coordinate system. Joystick and lever applications, such as those found in a steering column control or turn indicator in a video game controller particularly benefit from this ability.

For more details and guides related to using linear Hall-effect sensors for absolute position measurements with either one dimensional or 3D position sensors, see Table 1-3 and Table 1-4.

Device | Characteristics | Design Considerations |
---|---|---|

TMAG5170 (TMAG5170-Q1) |
Commercial (Automotive) grade linear 3D Hall-effect position sensor with SPI available in 8 pin DGK package | Complete magnetic vector sensitivity. This device is able to track a wide range of magnet positions, though careful planning is still required to make sure all input conditions map to a unique position. |

TMAG5273 | Commercial grade Linear 3D Hall-effect position sensor with I2C interface available in 6 pin SOT-23 package | Similar to the TMAG5170, but operates over I2C with wider sensitivity tolerance specifications. |

TMAG5173-Q1 | Automotive grade Linear 3D Hall-effect position sensor with I2C interface available in 6 pin SOT-23 package | Operates over I2C with comparable performance to TMAG5170. |

Name | Description |
---|---|

Achieving Highest System Angle Sensing Accuracy | A guide to designing sensor arrays for tracking motion across long paths |

Measuring 3D Motion With Absolute Position Sensors | A discussion on the differences between a linear output and switched output Hall effect sensors. |

Absolute Angle Measurements for Rotational Motion Using Hall-effect Sensors | A discussion about the Hall effect and how the Hall effect is used to create magnetic sensors |

Angle Measurement With Multi-Axis Hall-effect Sensors | A guide to monitoring absolute angle position using a 3D Hall effect sensor |

TMAG5170 EVM | GUI and attachments incorporate angle measurement using a precise three dimensional linear Hall-effect sensor |

TAMG5273 EVM | GUI and attachments incorporate angle measurement using a three dimensional linear Hall-effect sensor |

TMAG5173EVM | GUI and attachments incorporate joystick measurement using a three dimensional linear Hall-effect sensor |

TI Precision Labs - Magnetic Sensors | A helpful video series describing the Hall effect and how to use the Hall effect in various applications. A video on CORDIC calculations is included. |