SLYA069A october   2022  – may 2023 TMAG5170 , TMAG5170-Q1 , TMAG5170D-Q1 , TMAG5173-Q1 , TMAG5273

 

  1.   1
  2. 1Application Brief

Application Brief

Introduction

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 average, 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.

CORDIC

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 of 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.

GUID-20220912-SS0I-XQVR-FS5F-NFRPT7XRNSC8-low.gifFigure 1 Five Step Vector Rotation

In application, establishing a rotation pattern is best and can 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 five iterations require storing a floating point number for each step in a lookup table. This example is shown in Table 1.

Table 1 Arctangent Results of Rotation Angles
αn - Rotation Angle in degreestan(αn)
451
22.50.414
11.250.199
5.6250.98
2.81250.049

Converging to a final result is possible as long as the rotation angle used is greater than or equal to each of these steps. 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 2 are the result of calculating the arctangent of 2–n.

Table 2 Rotation Angles of Rightward Bit Shifts
2–n

Effective Rotation Angle in Degrees

145
0.526.565
0.2514.036
0.1257.125
0.06253.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.

Planar Angle Calculation

A fast method for angle calculations can 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. θZY=atanZ2+Y2X
Equation 2. θZX=atanZ2+X2Y

For example, consider a B-field vector whose components are BX = 3 mT, BY = 6 mT, and BZ = 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.

GUID-20220909-SS0I-NFK9-TSH0-PKGWGNKDJTGD-low.svgFigure 2 YZ Plane Angle

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

GUID-20220909-SS0I-8PGT-FRHT-70BK9WTJVGHK-low.svgFigure 3 ZX Plane Angle

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.)

GUID-20220909-SS0I-M2NJ-GPWL-LPFQ4CG9XB9F-low.svgFigure 4 Combined Planar Angle Results

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.

Spherical Coordinate Angles

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.

GUID-20210617-CA0I-KX1F-XR4N-FPH9TMJQFR7T-low.svgFigure 5 Spherical Coordinates

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 Angle

For Cylindrical Coordinate Translations, 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.

GUID-20220909-SS0I-2DNF-KZLV-ZJSKL8MKH01J-low.svgFigure 6 Cylindrical Coordinates

Conclusion

3D magnetic sensors offer a 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 a 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 3 and Table 4.

Table 3 Alternative Device Recommendation
DeviceCharacteristicsDesign Considerations
TMAG5170(TMAG5170-Q1)Commercial (Automotive) grade linear 3D Hall-effect position sensor with SPI available in 8 pin DGK packageComplete 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.
TMAG5170D-Q1Dual-die Automotive high-precision 3D linear Hall-effect sensor with SPI available in 16-pin TSSOP packageIdentical to the TMAG5170, but with stacked sensor dies for integrated redundancy. Developed for functional safety applications, with resources supporting design up to ASIL D.
TMAG5273Commercial grade Linear 3D Hall-effect position sensor with I2C interface available in 6 pin SOT-23 packageSimilar to the TMAG5170, but operates over I2C with wider sensitivity tolerance specifications.
TMAG5173-Q1Automotive grade Linear 3D Hall-effect position sensor with I2C interface available in 6 pin SOT-23 packageOperates over I2C with comparable performance to TMAG5170.
Table 4 Related Technical Resources
NameDescription
Achieving Highest System Angle Sensing AccuracyA guide to designing sensor arrays for tracking motion across long paths
Measuring 3D Motion With Absolute Position SensorsA discussion on the differences between a linear output and switched output Hall effect sensors.
Absolute Angle Measurements for Rotational Motion Using Hall-effect SensorsA discussion about the Hall effect and how the Hall effect is used to create magnetic sensors
Angle Measurement With Multi-Axis Hall-effect SensorsA guide to monitoring absolute angle position using a 3D Hall effect sensor
TMAG5170EVMGUI and attachments incorporate angle measurement using a precise three dimensional linear Hall-effect sensor

TMAG5170DEVM

GUI and attachments incorporate angle measurement using both precise three dimensional linear Hall-effect sensors integrated in this one device
TMAG5273EVMGUI and attachments incorporate angle measurement using a three dimensional linear Hall-effect sensor
TMAG5173EVMGUI and attachments incorporate joystick measurement using a three dimensional linear Hall-effect sensor
TI Precision Labs - Magnetic SensorsA helpful video series describing the Hall effect and how to use the Hall effect in various applications. A video on CORDIC calculations is included.