promach
Advanced Member level 4
Hi,
I am implementing CORDIC algorithm.
The source code could be found at https://www.edaplayground.com/x/3tHk or below:
I have some problem with the look up table 'arctan' in the code. My fraction representation could be incorrect for the calculation of z[i+1].
Could anyone help ?
I am implementing CORDIC algorithm.
The source code could be found at https://www.edaplayground.com/x/3tHk or below:
I have some problem with the look up table 'arctan' in the code. My fraction representation could be incorrect for the calculation of z[i+1].
Could anyone help ?
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 module cordic(z0, xn, yn); input [6:0] z0; output [6:0] xn, yn; parameter N= 40; // number of iterations reg [(N-1):0] d; reg [(N-1):0] x, y, z, arctan [(N-1):0]; initial begin arctan[0] = 1; for(integer j=0; j<(N-1); j=j+1) begin arctan[j+1] = arctan[j] >> (j+1); end end always @(*) begin for(integer i=0; i<N; i=i+1) begin d[i] = (z[i]<0) ? -1 : 1; x[i+1] = x[i] - y[i]*d[i] >> i; y[i+1] = y[i] + x[i]*d[i] >> i; z[i+1] = z[i] - d[i]*arctan[i]; end end assign x[0] = 0.6073; assign y[0] = 0; assign z[0] = z0; assign xn = x[N-1]; // xn = cos(z0) assign yn = y[N-1]; // yn = sin(z0) endmodule
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 `timescale 1ns/100ps module cordic_tb; reg [6:0] z0, xn, yn; cordic C1 ( .z0(z0), .xn(xn), .yn(yn) ); initial begin $dumpfile("cordic.vcd"); $dumpvars(0, cordic_tb); z0 = 30; #20 $finish; end endmodule