SLYA069A october 2022 – may 2023 TMAG5170 , TMAG5170-Q1 , TMAG5170D-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 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.
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.
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.
α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 |
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.
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.
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:
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.
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.
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.
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.
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. |
TMAG5170D-Q1 | Dual-die Automotive high-precision 3D linear Hall-effect sensor with SPI available in 16-pin TSSOP package | Identical to the TMAG5170, but with stacked sensor dies for integrated redundancy. Developed for functional safety applications, with resources supporting design up to ASIL D. |
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 |
TMAG5170EVM | GUI and attachments incorporate angle measurement using a precise three dimensional linear Hall-effect sensor |
GUI and attachments incorporate angle measurement using both precise three dimensional linear Hall-effect sensors integrated in this one device | |
TMAG5273EVM | 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. |