Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] cordic calculations of sine and cosine functions in fpga

Status
Not open for further replies.

brainiac_rus

Newbie level 5
Joined
May 28, 2014
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
103
Hi all!

I tryed to calculate a value of sine and cosine functions using cordic algorithm. But it does not work in fixed point system and i wrote it as simple program.

Here is a code:
Code:
module cordic_test0(
    );
real cordic_iter[15:0];

real angle;
integer i = 0;
real xi;
real yi;
real zi;


initial begin
	cordic_iter[0] = 45.0;
	cordic_iter[1] = 26.56505118;
	cordic_iter[2] = 14.03624347;
	cordic_iter[3] = 7.125016349;
	cordic_iter[4] = 3.576334375;
	cordic_iter[5] = 1.789910608;
	cordic_iter[6] = 0.89517371;
	cordic_iter[7] = 0.447614171;
	cordic_iter[8] = 0.2238105;
	cordic_iter[9] = 0.111905677;
	cordic_iter[10] = 0.055952892;
	cordic_iter[11] = 0.027976453;
	cordic_iter[12] = 0.013988227;
	cordic_iter[13] = 0.006994114;
	cordic_iter[14] = 0.003497057;
	cordic_iter[15] = 0.001748528;
	#100;
	angle = 45.0;
	zi = angle;
	xi = 0.6071;
	yi = 0.0;
	for(i = 0; i < 16; i = i + 1)
		begin
			if(zi > 0)
				begin
					zi = zi - cordic_iter[i];
					xi = xi - (yi / 2.0**i);//cos
					yi = yi + (xi / 2.0**i);//sin
				end
			else
				begin
					zi = zi + cordic_iter[i];
					xi = xi + (yi / 2.0**i);
					yi = yi - (xi / 2.0**i);
				end
			$display(i,"  ", zi);
			$display(xi,"   ", yi);
		end
	$display("Cos angle is ", xi);
	$display("Sin angle is ", yi);
	$display("Cos angle is ", xi*0.6071);
	$display("Sin angle is ", yi*0.6071);
	#100;
	$stop;
end



endmodule

But it does not work again.
I use this article as source http://andraka.com/files/crdcsrvy.pdf
What is wrong in my code? I think there are some stupied errors, but i can't find it.

this is what i see in console

Code:
          0  0
0.6071   0.6071
          1  26.5651
0.91065   0.151775
          2  12.5288
0.872706   0.369952
          3  5.40379
0.826462   0.473259
          4  1.82746
0.796884   0.523065
          5  0.0375464
0.780538   0.547456
          6  -0.857627
0.771984   0.559519
          7  -0.410013
0.776355   0.553453
          8  -0.186203
0.778517   0.550412
          9  -0.074297
0.779592   0.54889
         10  -0.0183441
0.780128   0.548128
         11  0.00963236
0.780396   0.547747
         12  -0.00435587
0.780262   0.547937
         13  0.00263825
0.780329   0.547842
         14  -0.000858809
0.780295   0.54789
         15  0.000889719
0.780312   0.547866
Cos angle is 0.780312
Sin angle is 0.547866
Cos angle is 0.473727
Sin angle is 0.332609
 

"i" should probably start at 1 in the loop, not 0.
 

No, this is wrong, because input angles are from -pi/2 to pi/2 and first angle which tg(phi) = 2^0, i.e. 45 degrees
 

Ok, I see the problem:

Code:
zi = zi - cordic_iter[i];
xi = xi - (yi / 2.0**i);//cos
yi = yi + (xi / 2.0**i);//sin

In the third line you are using the new value for xi, it should be the old value.
 
Ahahahahaah!!!!!
This is professional deformation!!! I started to think parallel as an FPGA)))

Thank you so much!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top