原创 cordic verilog 程序及仿真结果 8级流水线

2008-6-20 12:29 8190 13 26 分类: FPGA/CPLD
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)


     


          out <= 16'b0000_0000_0000_0000;


         


    
else

       


        out <= y8;

end

endmodule

仿真结果
仿真结果 8级流水线 误差还不小

角度


10        20         30       40        50        60       70         80


输入


5690      11207     16384     21063     25102     28378    30792     32270


输出


5794      11436     16513     21080     25087     28302    30706     32251


正弦值


0.1736    0.3420    0.5000    0.6428    0.7660    0.8660   0.9397    0.9848




仿真正弦值


0.1768    0.3490    0.5039    0.6433    0.7656    0.8637   0.9371    0.9842




PARTNER CONTENT

文章评论13条评论)

登录后参与讨论

用户377235 2013-4-9 10:31

这个输出的正余弦值 用modelsim怎么观察呢?????

用户343365 2011-4-8 17:07

您好,我在使用ISE 9.2i CORDIC IP核时,输出为0,请问是什么原因呢?

用户146077 2009-5-30 19:32

可以这样处理吧 cos(pi/2 + sita) = - sin(sita)

用户1399267 2009-5-29 14:35

还有,如果我按0~2*PI的输入范围来进行角度(弧度)到16位2进制数转换,那输入的范围是不是就变成0~2*PI了??

用户1399267 2009-5-29 14:31

我按-pi/2~pi/2计算,你的数据是正确的,但我看资料,都是只计算第一象限的函数值,然后进行角度转换。输入范围到底是0~pi/2还是-p1/2~pi/2,这关系到角度值到16位定点数转换的问题,望解答~~~~

用户1399267 2009-5-29 14:28

请问:cordic的输入的角度(弧度)范围是多少?怎么计算的??

用户146077 2009-5-24 21:09

这个是c=0.6072扩大了2^15来的,不还意思这个具体我也不太记得了,就是2^16次方了 (pi*10/180)*2^15 我把输入输出写反了

用户199507 2009-4-2 20:49

按照角度计算方法 10°=(2^16/360)*10=1820(dec) 为什么你对应的却是5690??请详细解答 非常感谢!

用户199507 2009-4-2 20:47

你好 能不能留个QQ之类的 想请教你

用户199507 2009-4-1 10:22

应该是扩大2^15吧
相关推荐阅读
用户146077 2009-11-07 20:08
Pi 数值积分C语言算法
一个计算Pi的程序用的是数值积分算法#include <math.h>#include <stdio.h>double f(double x);main(){int     i...
用户146077 2009-05-30 13:54
锁存器 寄存器
第一个是锁存器第二个是寄存器,用两个锁存器组成锁存器aways@(*)beginif(b == 1'b1) c =  a ;end寄存器always @(posedge clk or negedge ...
用户146077 2009-04-17 21:37
cordic 算法的仿真modesim
`timescale 1ns / 1ps////////////////////////////////////////////////////////////////////////////////...
用户146077 2009-04-09 21:24
用加法器实现减法器!
正整數減法與減法器在二進數目系統中,若一整數的最高有效位元(MSB)不是拿來區分正數或負數,那麼此數只能表達為正整數,關於正整數的減法想要用加法來做,首先得建立一個補數(complement)的觀念,...
用户146077 2008-12-31 20:55
FIFO
读地址产生写地址产生状态信息...
用户146077 2008-12-31 20:43
时序分析基础
幻灯片 3  电路设计的难点在时序设计,而时序设计的实质就是满足每一个触发器的建立/保持时间的要求。 Setup Time(Ts):触发器建立时间。即要求数据端信号在时钟信号触发沿到来之前提前到达的最...
EE直播间
更多
我要评论
13
13
关闭 站长推荐上一条 /3 下一条