SBAA463A january   2021  – april 2023 TMAG5170 , TMAG5170-Q1 , TMAG5170D-Q1 , TMAG5173-Q1 , TMAG5273

 

  1.   Abstract
  2.   Trademarks
  3. 1Introduction
    1. 1.1 Angle Measurement With One-Dimensional Sensors
    2. 1.2 Challenges of Angular Measurements
  4. 2Benefit of Multi-Axis Sensors
    1. 2.1 Simplified Mechanical Placement
    2. 2.2 Sensitivity Matching
    3. 2.3 CORDIC Angle Estimations
    4. 2.4 Tamper and Stray Field Detection
  5. 3Angular Measurement Considerations
    1. 3.1 Sensor Alignment
    2. 3.2 Sensor Calibration
    3. 3.3 Input Referred Noise
    4. 3.4 Impact of Sample Rate
  6. 4Practical Application
    1. 4.1 Push-Button Knob
      1. 4.1.1 Evaluating Design Constraints
      2. 4.1.2 Magnet Selection
      3. 4.1.3 Prototyping and Verification
    2. 4.2 Off-Axis Design
      1. 4.2.1 Sensitivity Gain Correction
      2. 4.2.2 Accuracy Verification
  7. 5Summary
  8. 6References
  9. 7Revision History

CORDIC Angle Estimations

CORDIC, or Coordinate Rotation Digital Calculator, provides a fast and effective way for digital systems to calculate angle using coordinate data. This algorithm quickly approximates angles by performing a binary search to rotate a point about the origin until the resulting vector lies along a single axis. As the coordinate input is rotated in iterative steps, the starting angle can be estimated by the summation of all steps. The resulting end position after completing these rotations will also produce the magnitude of the input vector. When used along with the outputs from a multi-axis Hall effect sensor, this algorithm proves to be an excellent option for fast and accurate angle calculations. Consider the point in Figure 2-8.

GUID-20201111-CA0I-4R31-0GBF-29Q6GFCDSX2V-low.gif Figure 2-8 CORDIC Input

If this point is rotated 45° clockwise, denoted α0, the new resulting vector leaves the first quadrant as Figure 2-9 shows.

GUID-20201111-CA0I-THQV-FR1G-Q7VHBFWFSWN4-low.gif Figure 2-9 CORDIC First Step

Since the goal is to align the vector with the X axis, the direction of rotation must be adjusted counterclockwise in the next step. In the next iteration, the coordinate will be rotated counterclockwise by 22.5°, (α1). The result here does not produce a quadrant change, and therefore the direction of rotation continues this direction. This process continues, adding and subtracting angular steps and changing rotation direction until the result is aligned to the X-axis. As shown in Figure 2-10, the approximate angle after 5 iterations is about 19.69°

GUID-20201111-CA0I-STD4-XRJF-GWHSSXDSCXRQ-low.gif Figure 2-10 CORDIC - 5 Iterations

The algebraic process for rotating a coordinate point in space is described following the matrix multiplication in Equation 1.

Equation 1. GUID-20201111-CA0I-08CW-KZ1Q-BNCF0JVKSMDH-low.gif
Equation 2. GUID-20201111-CA0I-GGM7-1J2Q-MZD0WVFHSCNL-low.gif
Equation 3. GUID-20201111-CA0I-KCK6-XTDW-6N1NDRGDLR2N-low.gif

If cos(α) is factored from the resulting products, we are left with Equations 4 and 5 as a result:

Equation 4. GUID-20201111-CA0I-4DQJ-XT0S-XGXJ5TRF5QVD-low.gif
Equation 5. GUID-20201111-CA0I-D7KB-9Z7R-K6FP1RJGHQ5J-low.gif

As the algorithm progresses, we must determine the direction of rotation. If we were to choose to rotate counterclockwise instead, the result would produce Equations 6 and 7:

Equation 6. GUID-20201111-CA0I-QVBR-LS3L-J1LTBZLN6DTK-low.gif
Equation 7. GUID-20201111-CA0I-PWBJ-J0WZ-ZJGQWCQVPVPR-low.gif

Notice that the only difference here is that the operation in each equation is inverted. Hence we can easily determine the direction of rotation by examining the sign of the operation. This rotation can be represented by a selectable value, which we will represent as d.

Equation 8. GUID-20201111-CA0I-JTWM-MHWQ-9R6N3NX6TLNB-low.gif

At this point a few approximations will simplify the angular calculation. If cos(α) were removed entirely, examination of the result would show that a new vector has been created which is rotated by the correct angle but has a magnitude greater than the original. This factor is effectively a scalar that normalizes the resulting vector to the correct magnitude for each step of the loop. The scalar value is determined by the angle of rotation, and can be easily calculated for each step by using a predetermined step size.

If a fixed number of iterations is used for every angle conversion, then the cumulative product of every vector transformation will always result with a constant final scalar, m. As a result, the value of cos(α) can be ignored during the routine. Instead, the final magnitude result can be scaled one time by m. Supposing ten iterations (0 to 9) of the algorithm were used, the resulting value for m is shown in Equation 9.

Equation 9. GUID-20201111-CA0I-DKZJ-PZWG-R7HXX7KZT33F-low.gif
Equation 10. GUID-20201111-CA0I-LXSZ-74T8-RHL3MDXG38F5-low.gif

Additionally, we can note that tan(α) is close to the value of 2-n. If the tangent calculation is replaced with a multiplication by a power of two, the algorithm becomes much simpler to implement. Consider the following table of values:

αn [°]

tan(α)

2-n

tan-1(2-n) [°]

45

1

1

45

22.5

0.414

0.5

26.565

11.25

0.199

0.25

14.036

5.625

0.098

0.125

7.125

2.8125

0.049

0.0625

3.576

Since the resulting angle from this substitution is greater than or equal to the expected step value used in a true binary search, the new angular step size will still be able to converge. While one or two more iterations to achieve the same accuracy may be necessary, we gain the benefit of replacing a lookup table of tangent values with a fixed rightward bit-shift operation.

After implementing these modifications to the algorithm, we are left with Equation 11Equation 14 which can be used iteratively to determine both the angle and magnitude of any two-dimensional vector.

Equation 11. GUID-20201111-CA0I-NLGH-NCGC-K2XLLTGPFNVD-low.gif
Equation 12. GUID-20201111-CA0I-9PTX-CKTM-59B50WFDVJK7-low.gif
Equation 13. GUID-20201111-CA0I-K0ZG-GMBF-LV5GKTX4XHRT-low.gif
Equation 14. GUID-20201111-CA0I-SZCS-JWSX-D4H8PGW18DSN-low.gif

Notice that with only a handful of cycles, this provides an elegant solution for a fast calculation. Devices with the CORDIC engine integrated, such as TMAG5170, are able to quickly resolve angular calculations and provide this as an output without any significant impact to overall conversion timing.