module cordic(clk,rst_n,in,out); parameter DATA_WIDTH=16; input clk; input rst_n; input [DATA_WIDTH-1:0] in; output [DATA_WIDTH-1:0] out; reg [DATA_WIDTH-1:0] out; reg [DATA_WIDTH-1:0] x0,y0,z0; reg [DATA_WIDTH-1:0] x1,y1,z1; reg [DATA_WIDTH-1:0] x2,y2,z2; reg [DATA_WIDTH-1:0] x3,y3,z3; reg [DATA_WIDTH-1:0] x4,y4,z4; reg [DATA_WIDTH-1:0] x5,y5,z5; reg [DATA_WIDTH-1:0] x6,y6,z6; reg [DATA_WIDTH-1:0] x7,y7,z7; reg [DATA_WIDTH-1:0] x8,y8,z8; always @(posedge clk or negedge rst_n) begin if(!rst_n) begin x0<=16'b0000_0000_0000_0000; y0<=16'b0000_0000_0000_0000; z0<=16'b0000_0000_0000_0000; end else begin x0 <= 16'h4DBA; y0 <= 16'h0000; z0 <= in; end end
//level 1 always @(posedge clk or negedge rst_n) begin if(!rst_n) begin x1<=16'b0000_0000_0000_0000; y1<=16'b0000_0000_0000_0000; z1<=16'b0000_0000_0000_0000; end else if(z0[15]==1'b0) begin x1 <= x0 - y0; y1 <= y0 + x0; z1 <= z0 - 16'h4000; //45deg end else begin x1 <= x0 + y0; y1 <= y0 - x0; z1 <= z0 + 16'h4000; //45deg end end
//level2 always @(posedge clk or negedge rst_n) begin if(!rst_n) begin x2<=16'h0000 ; y2<=16'h0000 ; z2<=16'h0000 ; end else
if(z1[15]==1'b0) begin x2 <= x1 - {y1[DATA_WIDTH-1],y1[DATA_WIDTH-1:1]}; y2 <= y1 + {x1[DATA_WIDTH-1],x1[DATA_WIDTH-1:1]}; z2 <= z1 - 16'h25c8; //26.5651deg end else begin x2 <= x1 + {y1[DATA_WIDTH-1],y1[DATA_WIDTH-1:1]}; y2 <= y1 - {x1[DATA_WIDTH-1],x1[DATA_WIDTH-1:1]}; z2 <= z1 + 16'h25c8; //26.5651deg end end
//level3 always @(posedge clk or negedge rst_n) begin if(!rst_n) begin x3<=16'b0000_0000_0000_0000; y3<=16'b0000_0000_0000_0000; z3<=16'b0000_0000_0000_0000; end else
if(z2[15]==1'b0) begin x3 <= x2 - {{2{y2[DATA_WIDTH-1]}},y2[DATA_WIDTH-1:2]}; y3 <= y2 + {{2{x2[DATA_WIDTH-1]}},x2[DATA_WIDTH-1:2]}; z3 <= z2 - 16'h13f6; //14.0362deg end else begin x3 <= x2 + {{2{y2[DATA_WIDTH-1]}},y2[DATA_WIDTH-1:2]}; y3 <= y2 - {{2{x2[DATA_WIDTH-1]}},x2[DATA_WIDTH-1:2]}; z3 <= z2 + 16'h13f6; //14.0362deg end end
//level4 always @(posedge clk or negedge rst_n) begin if(!rst_n) begin x4<=16'b0000_0000_0000_0000; y4<=16'b0000_0000_0000_0000; z4<=16'b0000_0000_0000_0000; end else
if(z3[15]==1'b0) begin x4 <= x3 - {{3{y3[DATA_WIDTH-1]}},y3[DATA_WIDTH-1:3]}; y4 <= y3 + {{3{x3[DATA_WIDTH-1]}},x3[DATA_WIDTH-1:3]}; z4 <= z3 - 16'h0A22; //7.1250deg end else begin x4 <= x3 + {{3{y3[DATA_WIDTH-1]}},y3[DATA_WIDTH-1:3]}; y4 <= y3 - {{3{x3[DATA_WIDTH-1]}},x3[DATA_WIDTH-1:3]}; z4 <= z3 + 16'h0A22; //7.1250deg end end
//level5 always @(posedge clk or negedge rst_n) begin if(!rst_n) begin x5<=16'b0000_0000_0000_0000; y5<=16'b0000_0000_0000_0000; z5<=16'b0000_0000_0000_0000; end else
if(z4[15]==1'b0) begin x5 <= x4 - {{4{y4[DATA_WIDTH-1]}},y4[DATA_WIDTH-1:4]}; y5 <= y4 + {{4{x4[DATA_WIDTH-1]}},x4[DATA_WIDTH-1:4]}; z5 <= z4 - 16'h0516; // 3.5763 deg end else begin x5 <= x4 + {{4{y4[DATA_WIDTH-1]}},y4[DATA_WIDTH-1:4]}; y5 <= y4 - {{4{x4[DATA_WIDTH-1]}},x4[DATA_WIDTH-1:4]}; z5 <= z4 + 16'h0516; // 3.5763 deg end end
//level6 always @(posedge clk or negedge rst_n) begin if(!rst_n) begin x6<=16'b0000_0000_0000_0000; y6<=16'b0000_0000_0000_0000; z6<=16'b0000_0000_0000_0000; end else
if(z5[15]==1'b0) begin x6 <= x5 - {{5{y5[DATA_WIDTH-1]}},y5[DATA_WIDTH-1:5]}; y6 <= y5 + {{5{x5[DATA_WIDTH-1]}},x5[DATA_WIDTH-1:5]}; z6 <= z5 - 16'h028C; //1.7899deg end else begin x6 <= x5 + {{5{y5[DATA_WIDTH-1]}},y5[DATA_WIDTH-1:5]}; y6 <= y5 - {{5{x5[DATA_WIDTH-1]}},x5[DATA_WIDTH-1:5]}; z6 <= z5 + 16'h028C; //1.7899deg end end
//level7
always @(posedge clk or negedge rst_n) begin if(!rst_n) begin x7<=16'b0000_0000_0000_0000; y7<=16'b0000_0000_0000_0000; z7<=16'b0000_0000_0000_0000; end else
if(z6[15]==1'b0) begin x7 <= x6 - {{6{y6[DATA_WIDTH-1]}},y6[DATA_WIDTH-1:6]}; y7 <= y6 + {{6{x6[DATA_WIDTH-1]}},x6[DATA_WIDTH-1:6]}; z7 <= z6 - 16'h0146; // 0.8952deg end else begin x7 <= x6 + {{6{y6[DATA_WIDTH-1]}},y6[DATA_WIDTH-1:6]}; y7 <= y6 - {{6{x6[DATA_WIDTH-1]}},x6[DATA_WIDTH-1:6]}; z7 <= z6 + 16'h0146; // 0.8952deg end end //level8 always @(posedge clk or negedge rst_n) begin if(!rst_n) begin x8<=16'b0000_0000_0000_0000; y8<=16'b0000_0000_0000_0000; z8<=16'b0000_0000_0000_0000; end else
if(z7[15]==1'b0) begin x8 <= x7 - {{7{y7[DATA_WIDTH-1]}},y7[DATA_WIDTH-1:7]}; y8 <= y7 + {{7{x7[DATA_WIDTH-1]}},x7[DATA_WIDTH-1:7]}; z8 <= z7 - 16'h00A3; // 0.4476deg end else begin x8 <= x7 + {{7{y6[DATA_WIDTH-1]}},y7[DATA_WIDTH-1:7]}; y8 <= y7 - {{7{x7[DATA_WIDTH-1]}},x7[DATA_WIDTH-1:7]}; z8 <= z7 + 16'h00A3; // 0.4476deg end end always @(posedge clk or negedge rst_n) begin if(!rst_n)
用户377235 2013-4-9 10:31
这个输出的正余弦值 用modelsim怎么观察呢?????
用户343365 2011-4-8 17:07
用户146077 2009-5-30 19:32
用户1399267 2009-5-29 14:35
用户1399267 2009-5-29 14:31
用户1399267 2009-5-29 14:28
用户146077 2009-5-24 21:09
用户199507 2009-4-2 20:49
用户199507 2009-4-2 20:47
用户199507 2009-4-1 10:22