SLAU846A June 2023 – October 2023 MSPM0G1105 , MSPM0G1106 , MSPM0G1107 , MSPM0G1505 , MSPM0G1506 , MSPM0G1507 , MSPM0G3105 , MSPM0G3105-Q1 , MSPM0G3106 , MSPM0G3106-Q1 , MSPM0G3107 , MSPM0G3107-Q1 , MSPM0G3505 , MSPM0G3505-Q1 , MSPM0G3506 , MSPM0G3506-Q1 , MSPM0G3507 , MSPM0G3507-Q1
The arctangent function (ATAN2) computes the arctangent of (y/x), where y and x are the normalized coordinates. The ATAN2 algorithm relies on expressing the resulting angle as a sum of constituent angles computed by incrementally accumulating the constituent angles until the y-coordinate value is 0. The number of iterations to calculate the arctangent is specified using the CTL.NUMITER field, and the final result for the angle in per unit is stored in RES1 as a signed number.
Before performing the ATAN2 function, the x- and y- coordinates should be normalized to a unit vector, which can be done with various types of normalization algorithms. One normalization algorithm is shown in Figure 4-3.
Table 5-5 shows the configuration registers for the ATAN2 function.
Register (Bit Field) | Value | Description |
---|---|---|
OP1 | User value | X coordinate (SQ0.31 format) |
OP2 | User value | Y coordinate (SQ0.31 format) |
CTL.FUNC | 2h | ATAN2 |
CTL.NUMITER | User value | Number of iterations |
RES1 | 32-bit value | Angle in degrees per unit (SQ0.31 format) . The angle in per unit is calculated by n = angle/180, where n is the angle in per unit between [-1,1) and angle is between [-180,180) degrees. |
A higher number of iterations (NUMITER) calculates more accurate results but will take longer to compute.
Status, Errors, and Overflow
There are no status, error, or overflow bits for ATAN2.
Configuration
To perform ATAN2: