|
I freely admit this page borrows very heavily from an article by
Pitts Jarvis
written in the early '90's in
Dr. Dobb's Journal.
I had been interested in CORDIC for a long time, collecting various papers and articles without gaining much true understanding. Either they were solely mathematical with no direction on how to implement algorithms in hardware, or they did cover hardware but always had key logic somehow missing. Finally I ran across Jarvis's paper online early this Millennium. Suddenly in one place was as much information as I needed in order to implement CORDIC in the FSA instruction set. (Ironically, I soon found a hard copy of same in my files. Had the info all along. Did I even look at it when I copied it? Maybe it's simply that the timing wasn't right, then.) Anyway, this is my attempt to pick the highest points from CORDIC theory and lay them out shortly and simply crappy graphics and all. Finally, here is the source link to Mr. Jarvis's original paper. It exists other places around the Net as well. Bob Loy |
^
y | _ (x,y)
| /|
| /
| /
| /
| /
|/)a
--------->
x
--- --- --- ---
| | | |
| x | | x cos a - y sin a |
| | | |
Ra | | = | |
| | | |
| y | | x sin a + y cos a |
| | | |
--- --- --- ---
^
|
|
|
|
|
======>--->
(1,0)
[x, y, z] --> [some value, some value, some value]
[1, 0, a] --> [some value, some value, 0]
[K, 0, a] --> [cos a, sin a, 0]
[K, K, a] --> [e^a, e^a, 0]
Jarvis even provided a long
C language
program detailing over a dozen CORDIC functions. Here's his code for
generating
cosine and sine:
/* C code from Pitts Jarvis */
/* n=29 lets us represent numbers in the interval [-4, 4) in 32 bit long. */
#define fractionBits 29
#define Delta(n, Z) (Z >= 0) ? (n) : -(n)
unsigned X, Y, Z;
Circular(x, y, z) long x, y, z;
{
int i;
X = x; Y = y; Z = z;
for (i = 0; i <= fractionBits; ++i)
{
x = X >> i;
y = Y >> i;
z = atan[i];
X -= Delta(y, Z);
Y += Delta(x, Z);
Z -= Delta(z, Z);
}
}
Just below is the screen shot of the FSA Simulator from the home page. Since I was working within a sixteen bit word, my "fractionBits" is 13 rather than 29. The top word on the rightmost memory display is the 45 degree (pi/4 radians) input value, followed by the cosine constant from the formula, followed by the arctan splits. Notice that the first arctan value is also pi/4 radians. See also that the 'z' variable (the green register above P1) has indeed been reduced to zero. |
|
|
Screen shot of the FSA Simulator thirteen cycles into a CORDIC computation of sine & cosine. Input: 45 degrees. Output: cosine is at top of P1 at level C3, sine is just below it. Both values are .70703125 in a fixed point format with thirteen bits to the right of the binary point. |
|
Quick Test Input
I later extended the CORDIC simulation shown as the screen shot above to allow whole number degrees as input by using the following radian conversions for angles of 1, 2, 4, 8, 16, 32 & 64 degrees: 0000000010001111 0000000100011101 0000001000111011 0000010001110111 0000100011101111 0001000111011111 0010001110111111Of course, whole number degrees don't provide much resolution, but I mainly was looking for an easy way to test the results. Finer accuracy can come later. The data is in a 3.13 fixed point format, eg, the bottom value would be read as: 001.0001110111111. I used Von Neumann rounding on each value, a fast, (no carries necessary) central tendency rounding method achieved simply by forcing a computation's LSB to one. Once I convert the degree input into binary, I shift it to the right one bit at a time while stepping thru the radian array. If the degree's LSB tests as a zero, the current radian value is skipped, otherwise it is added to a cumulative total. Crude, but fast and doesn't take up much space. Bob Loy |