PHY Cordic (int theta, struct cint32 *val)
Note: struct cint32 {int q; int i;};
This routine does most of its calculations in a pseudo-floating point. The binary point is in the middle of a 32-bit word, which explains the shifts below. Both arguments are in this form.
- Create an arctangent table with the following elements:
- 2949120, 1740967, 919879, 466945, 234379, 117304, 58666, 29335, 14668, 7334, 3667, 1833, 917, 458, 229, 115, 57, 29
- Set signx to 1
- Set the imaginary part of val[0] to 39797
- Set the real part of val[0] to 0
- Set the angle to 0
While theta > (180 << 16)
Subtract 360 << 16 from theta
While -theta > (180 << 16)
Add 360 << 16 to theta
If theta > (90 << 16)
Subtract (180 << 16) from theta
- Set signx to -1
If -theta > (90 << 16)
Add 180 << 16 to theta
- Set signx to -1
- Loop from 0 to 17 (inclusive)
- If theta greater than the angle
- Save the imaginary part of val[0] minus the real part right shifted by the loop index
- Add the imaginary part of val[0] right shifted by the loop index to the real part of val[0]
- Replace the imaginary part of val[0] with the temporary from above
- Add the value from the arctangent table indexed by the loop variable to the angle
- Otherwise
- Save the imaginary part of val[0] plus the real part right shifted by the loop index
- Subtract the imaginary part of val[0] right shifted by the loop index from the real part of val[0]
- Replace the imaginary part of val[0] with the temporary from above
- Subtract the value from the arctangent table indexed by the loop variable from the angle
- If theta greater than the angle
- Multiply the real and imaginary parts of val[0] by signx