Implement trigonometric functions in software with CORDIC
This tutorial describes software implementation of the following fixed point trigonometric routines using the CORDIC Algorithm on Infineon's XC164CS Microcontroller with MAC unit. The implementation of the algorithm is examined concerning accuracy and efficiency:
* Complex Magnitude
* Sine
* Cosine
Routines are provided for signed two's complement arithmetic. First a brief description of the theory behind the algorithm is presented. Then the theory is extended to the implementation of algorithm in XC164CS Processor after which the numerical errors that occur in the fixed point implementation is discussed.
CORDIC arithmetic technique
The CORDIC algorithm is an iterative technique proposed by Volder in 1956. This algorithm can be a very powerful tool in areas where arithmetic or trigonometric function evaluation is heavily utilized, such as digital signal processing, motor control.
The general vector rotational transform rotates a plane vector [X, Y] by an angle Θ to produce a new vector point [X_{i+1}, Y_{i+1}] as in Equations (1) and(2). The CORDIC Rotation is achieved by the same principle. It rotates the point [X, Y] in series of steps, which are smaller than Θ.
This rotation may be in anti clockwise direction (increase in Θ) or clock wise direction (decrease in ). Suppose if we wish to achieve a total rotation of 35^{o}, we may rotate our point 30^{o} anticlockwise, followed by 10^{o} anticlockwise, followed by 5^{o} clockwise.
The reason for this simplification is to break down the rotation (Θ) into many steps, each of decreasing size and has each step such that tan is the power of 2, where Θ is the rotational angle. The first seven steps of the set of rotations are shown in Table 1.
Table 1: The first seven steps of the set of rotations. |
This would allow us to implement the multiplication by tan Θ as a simple bit shift operation (2^{-i}). Hence Equations (3) and (4) reduce to
From Table 1, it is clear that the total rotation step is 99.88^{o}. Since the rotation can be of clockwise or anticlockwise direction these steps are used to approximate angles between +99.88^{o} to -99.88^{o}. For mathematical simplicity the rotation angles are limited to "90^{o} and +90^{o}. For rotation angles greater than ±90^{o} additional rotation is required. The cos Θ term (K) is a constant which approaches to 0.6073 after 'n' iterations. The angle Θ is accumulated in Z_{i+1}
Related Articles | Editor's Choice |
Visit Asia Webinars to learn about the latest in technology and get practical design tips.