Cordic algorithm again

70 views
Skip to first unread message

Edwa...@alum.mit.edu

unread,
Jul 19, 2021, 2:17:48 PM7/19/21
to PiDP-8

Some time ago there was discussion here regarding the Cordic (coordinate rotation) algorithm for sines and cosines. Experience with the its implementation on a PDP8 leaves a bit to be desired. For example, with a double word argument and using double word arithmetic, the sine and cosine of 45 degrees is off by six in the last octal digit.

Two word calculation
Given angle: 45
Angle used: 0o20000000 45.0
Result
Sine:
Calc: 0o26501177 0.707107424
True: 0o26501171 0.7071067
Cosine:
Calc: 0o26501163 0.707105994
True: 0o26501171 0.7071067

In this calculation angles are scaled by 4000 0000 (octal)/90 (decimal) and the results by 4000 0000 (octal).

The advantage of the Cordic algorithm is significant: both sine and cosine can be obtained with 2 pages of code with no requirement for an EAE. This, as compared to the DEC distributed routines that require 3 pages (one each for sine, cosine and multiplication).

So is it possible to implement the Cordic algorithm in two pages and get results accurate to the last octal digit of a two word result? The answer is yes: there was enough left in the two pages of the two word version to calculate with three words. Here is the result of that implementation:

Three word calculation
Given angle: 45
Angle used: 0o200000000000 45.0
Result
Sine:
Calc: 0o265011714707 0.7071067823271
True: 0o265011714637 0.707106781
Cosine:
Calc: 0o265011714566 0.7071067799697
True: 0o265011714637 0.707106781

In the attachment are the python prototypes for both types of calculation, together with the pal assembly code and listing for both.

Yul
cordic.zip

Ian Schofield

unread,
Jul 24, 2021, 1:46:23 PM7/24/21
to PiDP-8
Dear All,

 Seeing we are now in the area of digital implementations of functions without resorting to floats/doubles etc. This tiny function
draws a (not too bad) circle using the sin/cos recursion technique and only 12 bits. Here is the c version which is actually
used to draw circles for a tic-tac-toe app that runs on our favourite computer.
This is actually a quadrature signal generator.

int circle(ix,iy)  // Draw circle at coord x,y
int ix,iy;
{
        int re,im,tm,i;

        re=0;
        im=1000;
        for (i=0;i<19;i++) {
                dispxy(ix+re/20,iy+im/20);
                tm=re+im/3;
                im=im-tm/3;
                re=tm;
        }
}

More of a curiosity than something useful! 

BW, Ian.

Reply all
Reply to author
Forward
0 new messages