Cordic
Cordic
CORDIC is an acronym of COordinate Rotation Digital Calculation. It is also known as digit by digit or Volders algorithm. It is simple and efficient method to calculate trigonometric functions. It is commonly used when no hardware multiplier is available (eg,simple microcontrollers and FPGAs) as the only operations it requires are addition, subtraction, bitshift and table lookup. CORDIC processor has three registers, namely, x(X coordinate), Y(Y coordinate) and Z(Angle). It has two modes Vector mode and Rotation mode. Rotation mode : The rotation mode is used to find the sine or cosine of an angle iteratively using simple math operations. The angle whose sine or cosine is to be found is first stored in the Z register. X and Y are made 1 and 0 respectively, thus representing a horizontal vector. The angle in Z is changed in successively smaller steps with a view to finally make it 0. X and Y registers are updated with each change in Z such that they represent the corresponding rotation of the vector. After sufficient number of iterations, Z nearly becomes 0 and at this time, X represents cosine and Y represents sine of the original angle. Vector rotation is the heart of this algorithm. So, first let us study the relation between the angle of rotaion and corresponding change in x, y coordinates. Let us suppose, the vector is originally inclined to x-axis at an angle 1. Its coordinates are x1 and y1 respectively. It is now rotated counter-clockwise through an angle , so that it is now inclined t x-axis at an angle 2. The new coordinates are x2, y2. By using the formulae for sin(A+B) and cos(A+B) it can be easily shown that: x2 = x1 * cos() y1 * sin() y2 = x1 * sin() + y1 * cos() The equations can be re-written as x2 = cos() * [x1- y1 *tan()] y2 = cos() * [y1 + x1 * tan()] In rotation mode, the initial angle is , and it is rotated in steps i to make the angle stored in Z register as zero. Now comes the beauty of the algorithm : Multiplication by tan() in above equations can be replaced by right shift if the steps are chosen such that tan(i) at ith step is the fractional power of 2.
This way, multiplication by tan() reduces to a right shift by i. We can ignore multiplication by cos() because it approaches a constant value k irrespective of initial values of x,y,z. Multiplication of k can be achieved by initializing x with 0.607253 instead of 1. This method find sine and cosine of angles in the range of 0 to 90 degrees. This project is limited to this range. For a 4 quadrant calculation, we can add a little hardware using the formulae. Sin(180+) = -sin(); Cos(180+)=-cos(); Initially x=0.607253, y=0, z=, i =0 Repeat When z >= 0 then x(i+1) = x(i) y(i) * y(i+1) = y(i) + x(i) * z(i+1) = z(i) When z < 0 then x(i+1) = x(i) + y(i) * y(i+1) = y(i) - x(i) * z(i+1) = z(i) + sin(90+)=cos() cos(90+)=-sin()