SBAA463A january 2021 – april 2023 TMAG5170 , TMAG5170-Q1 , TMAG5170D-Q1 , TMAG5173-Q1 , TMAG5273
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.
If this point is rotated 45° clockwise, denoted α0, the new resulting vector leaves the first quadrant as Figure 2-9 shows.
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°
The algebraic process for rotating a coordinate point in space is described following the matrix multiplication in Equation 1.
If cos(α) is factored from the resulting products, we are left with Equations 4 and 5 as a result:
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:
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.
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.
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 |
After implementing these modifications to the algorithm, we are left with Equation 11–Equation 14 which can be used iteratively to determine both the angle and magnitude of any two-dimensional vector.
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.