|
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. |