ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts  1.0
ESP8266ILI9341DisplayProject
Macros | Typedefs | Functions | Variables
cordic2c.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <libgen.h>

Go to the source code of this file.

Macros

#define Cordic_T_Bits   (int)(sizeof(Cordic_T) << 3)
 
#define FCordic_T_Bits   (int)(sizeof(FCordic_T) << 3)
 
#define Cordic_T_FractionBits   (int)(Cordic_T_Bits - 3 - 1)
 
#define Cordic_T_STR   "typedef int Cordic_T;"
 
#define UCordic_T_STR   "typedef unsigned int UCordic_T;"
 
#define FCordic_T_STR   "typedef double FCordic_T;"
 
#define Cordic_One   (1UL << Cordic_T_FractionBits)
 
#define Cordic_K   (Cordic_One * 0.6072529350088812561694)
 
#define Cordic_INVK   (Cordic_One / 0.6072529350088812561694)
 
#define Cordic_KP   (Cordic_One * 1.20749706776307212887772)
 
#define Cordic_INVKP   (Cordic_One * 1/1.20749706776307212887772)
 
#define Cordic_HalfPI   ((UCordic_T) (Cordic_One * M_PI_2) )
 
#define Cordic2FP(a)   ( (double) (a) / (double) (Cordic_One))
 
#define FP2Cordic(a)   ((Cordic_T) (Cordic_One * (a)))
 

Typedefs

typedef int Cordic_T
 cordicC.c – J. Pitts Jarvis, III cordicC.c computes CORDIC constants and exercises the basic algorithms. Represents all numbers in fixed point notation. 1 bit sign, Cordic_T_Bits-1-n bit integral part, and n bit fractional part. n=29 lets us represent numbers in the interval [-4, 4) in 32 bit Cordic_T. Two's complement arithmetic is operative here. More...
 
typedef unsigned int UCordic_T
 
typedef double FCordic_T
 

Functions

char * get_date ()
 Get the current date in a string. More...
 
void dump_tables (FILE *FO)
 Create Cordic tables Normalize base number system to 1.0 == Cordic_One == PI/2 (90 degrees) Example .5 is 50 gradians or PI/4 This value as great advantages: More...
 
void PrintXYZ (char *str)
 Display X,Y,Z as floating point. More...
 
void Circular (Cordic_T x, Cordic_T y, Cordic_T z)
 Main Cordic routine - used for basic trig and vector rotations. More...
 
void cordit1 (Cordic_T x, Cordic_T y, Cordic_T z, Cordic_T vecmode)
 This is the circular method. One slight change from the other methods is the y < vecmode test. this is to implement arcsin, otherwise it can be y < 0 and you can compute arcsin from arctan using trig identities, so it is not essential. More...
 
Cordic_T asinCordic (Cordic_T a)
 Compute ArcSine (a) Only works for |a| < 0.98. More...
 
int main (int argc, char *argv[])
 Create C Cordic Tables and test the results. More...
 

Variables

static Cordic_T v_atan [Cordic_T_Bits+1]
 
static Cordic_T X
 
static Cordic_T Y
 
static Cordic_T Z
 

Macro Definition Documentation

#define Cordic2FP (   a)    ( (double) (a) / (double) (Cordic_One))

Definition at line 123 of file cordic2c.c.

Referenced by get_date(), and PrintXYZ().

#define Cordic_HalfPI   ((UCordic_T) (Cordic_One * M_PI_2) )

Definition at line 122 of file cordic2c.c.

Referenced by get_date().

#define Cordic_INVK   (Cordic_One / 0.6072529350088812561694)

Definition at line 119 of file cordic2c.c.

Referenced by get_date().

#define Cordic_INVKP   (Cordic_One * 1/1.20749706776307212887772)

Definition at line 121 of file cordic2c.c.

Referenced by get_date().

#define Cordic_K   (Cordic_One * 0.6072529350088812561694)

Definition at line 118 of file cordic2c.c.

Referenced by asinCordic(), get_date(), and main().

#define Cordic_KP   (Cordic_One * 1.20749706776307212887772)

Definition at line 120 of file cordic2c.c.

Referenced by get_date().

#define Cordic_One   (1UL << Cordic_T_FractionBits)

Definition at line 117 of file cordic2c.c.

Referenced by get_date().

#define Cordic_T_Bits   (int)(sizeof(Cordic_T) << 3)

Definition at line 102 of file cordic2c.c.

Referenced by get_date().

#define Cordic_T_FractionBits   (int)(Cordic_T_Bits - 3 - 1)

Definition at line 105 of file cordic2c.c.

Referenced by Circular(), cordit1(), and get_date().

#define Cordic_T_STR   "typedef int Cordic_T;"

Definition at line 107 of file cordic2c.c.

Referenced by get_date().

#define FCordic_T_Bits   (int)(sizeof(FCordic_T) << 3)

Definition at line 103 of file cordic2c.c.

Referenced by get_date().

#define FCordic_T_STR   "typedef double FCordic_T;"

Definition at line 109 of file cordic2c.c.

Referenced by get_date().

#define FP2Cordic (   a)    ((Cordic_T) (Cordic_One * (a)))

Definition at line 124 of file cordic2c.c.

Referenced by main().

#define UCordic_T_STR   "typedef unsigned int UCordic_T;"

Definition at line 108 of file cordic2c.c.

Referenced by get_date().

Typedef Documentation

typedef int Cordic_T

cordicC.c – J. Pitts Jarvis, III cordicC.c computes CORDIC constants and exercises the basic algorithms. Represents all numbers in fixed point notation. 1 bit sign, Cordic_T_Bits-1-n bit integral part, and n bit fractional part. n=29 lets us represent numbers in the interval [-4, 4) in 32 bit Cordic_T. Two's complement arithmetic is operative here.

IMPLEMENTING CORDIC ALGORITHMS by Pitts Jarvis Cordic algorithm identities for circular functions starting with [x, y, z] and then driving z to 0 gives: [P*(x*cos(z)-y*sin(z)), P*(y*cos(z)+x*sin(z)), 0] driving y to 0 gives: [P*sqrt(x^2+y^2), 0, z+atan(y/x)] where K = 1/P = sqrt(1+1)* . . . sqrt(1+(2^(-2*i))) special cases which compute interesting functions sin, cos [K, 0, a] -> [cos(a), sin(a), 0] atan [1, a, 0] -> [sqrt(1+a^2)/K, 0, atan(a)] [x, y, 0] -> [sqrt(x^2+y^2)/K, 0, atan(y/x)] for hyperbolic functions, starting with [x, y, z] and then driving z to 0 gives: [P(x*cosh(z)+y*sinh(z)), P*(y*cosh(z)+x*sinh(z)), 0] driving y to 0 gives: [P*sqrt(x^2-y^2), 0, z+atanh(y/x)] where K = 1/P = sqrt(1-(1/2)^2)* . . . sqrt(1-(2^(-2*i))) sinh, cosh [K, 0, a] -> [cosh(a), sinh(a), 0] exponential [K, K, a] -> [e^a, e^a, 0] atanh [1, a, 0] -> [sqrt(1-a^2)/K, 0, atanh(a)] [x, y, 0] -> [sqrt(x^2-y^2)/K, 0, atanh(y/x)] ln [a+1, a-1, 0] -> [2*sqrt(a)/K, 0, ln(a)/2] sqrt [a+(K/2)^2, a-(K/2)^2, 0] -> [sqrt(a), 0, ln(a(2/K)^2)/2] sqrt, ln [a+(K/2)^2, a-(K/2)^2, -ln(K/2)] -> [sqrt(a), 0, ln(a)/2] for linear functions, starting with [x, y, z] and then driving z to 0 gives: [x, y+x*z, 0] driving y to 0 gives: [x, 0, z+y/x] compute atan(x) and atanh(x) using infinite series atan(x) = x - x^3/3 + x^5/5 - x^7/7 + . . . for x^2 < 1 atanh(x) = x + x^3/3 + x^5/5 + x^7/7 + . . . for x^2 < 1 To calculate these functions to 32 bits of precision, pick terms[i] s.t. ((2^-i)^(terms[i]))/(terms[i]) < 2^-32 For x <= 2^(-11), atan(x) = atanh(x) = x with 32 bits of accuracy

Definition at line 97 of file cordic2c.c.

typedef double FCordic_T

Definition at line 99 of file cordic2c.c.

typedef unsigned int UCordic_T

Definition at line 98 of file cordic2c.c.

Function Documentation

Cordic_T asinCordic ( Cordic_T  a)

Compute ArcSine (a) Only works for |a| < 0.98.

Parameters
[in]aSine
Returns
ArcSine (a)

Definition at line 292 of file cordic2c.c.

void Circular ( Cordic_T  x,
Cordic_T  y,
Cordic_T  z 
)

Main Cordic routine - used for basic trig and vector rotations.

See also
http://en.wikipedia.org/wiki/CORDIC
Parameters
[in,out]xCordik_K, out: Cos of z
[in,out]y0, out: Sin of z
[in,out]zfixed point version of angle
Returns
void

Definition at line 216 of file cordic2c.c.

Referenced by main().

void cordit1 ( Cordic_T  x,
Cordic_T  y,
Cordic_T  z,
Cordic_T  vecmode 
)

This is the circular method. One slight change from the other methods is the y < vecmode test. this is to implement arcsin, otherwise it can be y < 0 and you can compute arcsin from arctan using trig identities, so it is not essential.

See also
http://en.wikipedia.org/wiki/CORDIC
Parameters
[in,out]xin: Cordik_K, out: Cos of z
[in,out]yin: 0
[in,out]zin: 0
[in]vecmodearcsize value
Returns
void

Definition at line 259 of file cordic2c.c.

Referenced by asinCordic().

void dump_tables ( FILE FO)

Create Cordic tables Normalize base number system to 1.0 == Cordic_One == PI/2 (90 degrees) Example .5 is 50 gradians or PI/4 This value as great advantages:

  • integer part is small on the unit circle
  • integer part is the circle quadrant number (think range reductions)Dump Cordic C structure
    Parameters
    [in]*FOFile handle to write tables to
    Returns
    void

Definition at line 153 of file cordic2c.c.

Referenced by get_date(), and main().

char* get_date ( )

Get the current date in a string.

Returns
void

Definition at line 128 of file cordic2c.c.

Referenced by main().

int main ( int  argc,
char *  argv[] 
)

Create C Cordic Tables and test the results.

Returns
0

Definition at line 317 of file cordic2c.c.

void PrintXYZ ( char *  str)

Display X,Y,Z as floating point.

Parameters
[in]strstring header
Returns
void

Definition at line 200 of file cordic2c.c.

Referenced by main().

Variable Documentation

Cordic_T v_atan[Cordic_T_Bits+1]
static

Definition at line 112 of file cordic2c.c.

Referenced by Circular(), cordit1(), and get_date().

Cordic_T X
static

Definition at line 113 of file cordic2c.c.

Referenced by Circular(), cordit1(), and PrintXYZ().

Cordic_T Y
static

Definition at line 114 of file cordic2c.c.

Referenced by Circular(), cordit1(), and PrintXYZ().

Cordic_T Z
static

Definition at line 115 of file cordic2c.c.

Referenced by asinCordic(), Circular(), cordit1(), and PrintXYZ().