原创 pipiline加法器

2008-4-15 18:07 2740 5 6 分类: FPGA/CPLD

Pipeline:如果直接 {cout,sum}=ina+inb+cin; 构成一个并行的加法器,会消耗较多资源。而pipeline只是加了一些中间寄存器,把复杂的8位运算分成42位运算,求第一个结果需要延时4个周期,但是后面的结果就只需要一个周期,而且每级运算结构简单,所以可以高频率运行。


王金明书中的程序搞了很久,就是不正确,还好Lotus找到了错误的原因,但是不知道为什么会发生错误?


<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

 


Lotus更改正确的程序:


module addpipeline(cout,sum,ina,inb,cin,clk);


input [7:0]ina,inb;


input cin,clk;


output [7:0]sum;


output cout;


reg firstco,secondco,thirdco;


reg cout;


reg [7:0] sum;


reg [1:0]firsts,thirda,thirdb;


reg [5:0]firsta,firstb,thirds;


reg [3:0]seconda,secondb,seconds;


 


always @(posedge clk)


begin


{firstco,firsts}<=ina[1:0]+inb[1:0]+cin;


firsta<=ina[7:2];


firstb<=inb[7:2];


end


 


always @(posedge clk)


begin


seconds[1:0]<=firsts;


{secondco,seconds[3:2]}<=firsta[1:0]+firstb[1:0]+firstco;


seconda<=firsta[5:2];


secondb<=firstb[5:2];


end


 


always @(posedge clk)


begin


thirds[3:0]<=seconds;


{thirdco,thirds[5:4]}<=seconda[1:0]+secondb[1:0]+secondco;


thirda<=seconda[3:2];


thirdb<=secondb[3:2];


end


 


always @(posedge clk)


begin


sum[5:0]<=thirds;


{cout,sum[7:6]}<=thirda[1:0]+thirdb[1:0]+thirdco;


end


endmodule


 


 


// 去掉了temp变量,使延时少了1个周期。


// 书中程序仿真总是进位为0


  {secondco,seconds}<={firsta[1:0]+firstb[1:0]+firstco,firsts};


改为seconds[1:0]<=firsts;


{secondco,seconds[3:2]}<=firsta[1:0]+firstb[1:0]+firstco; 进位正确。


好像书中的这种拼接方式有误使得进位始终为0


 


 


王金明书中的程序:


module pipeline(cout,sum,ina,inb,cin,clk);


output[7:0] sum;


output cout;


input cin,clk;


input [7:0] ina,inb;


reg[7:0] tempa,tempb,sum;


reg tempci,firstco,secondco,thirdco,cout;


reg[1:0] firsts,thirda,thirdb;


reg[3:0] seconds,seconda,secondb;


reg[5:0] firsta,firstb,thirds;


 


always@(posedge clk)


  begin


     tempa<=ina;tempb<=inb;tempci<=cin;


  end


//firstco is the carry of the lowest 2 bit adding


//firsts is the summary of the lowest 2 bit adding


//firsta/firstb is the highest 6 bit of ina/inb


always@(posedge clk)


  begin


    {firstco,firsts}<=tempa[1:0]+tempb[1:0]+tempci;  这一句进位正确


    firsta<=tempa[7:2];firstb<=tempb[7:2];


  end


//seconds is the summary of the lowest 4 bit adding


//seconda/secondb is the highest 4 bit of ina/inb 


always@(posedge clk)


  begin


    {secondco,seconds}<={firsta[1:0]+firstb[1:0]+firstco,firsts};  进位错误


    seconda<=firsta[5:2];secondb<=firstb[5:2];


  end  


//thirds is the summary of the lowest 6 bit adding


//thirda/thirdb is the highest 2 bit of ina/inb


always@(posedge clk)


  begin


    {thirdco,thirds}<={seconda[1:0]+secondb[1:0]+secondco,seconds};


    thirda<=seconda[3:2]; thirdb<=secondb[3:2];


  end


always@(posedge clk)


  begin


    {cout,sum}<={thirda[1:0]+thirdb[1:0]+thirdco,thirds};


  end


 


endmodule


    


 

文章评论1条评论)

登录后参与讨论

用户1395232 2009-2-2 10:30

always @(posedge clk) begin tempa_d1<=cina; tempb_d1<=cinb; {cout2,sum2} <= {tempa_d1[3:2] + tempb_d1[3:2]+{2'b0,cout1},sum1}; end always @(posedge clk) begin tempa_d2 <= tempa_d1; tempb_d2 <= tempb_d1; {cout3,sum3} <= {tempa_d2[5:4] + tempb_d2[5:4] + {2'b0,cout2},sum2}; end always @(posedge clk) begin tempa_d3 <= tempa_d2; tempb_d3 <= tempb_d2; {cout,sum} <= {tempa_d3[7:6] + tempb_d3[7:6] + {2'b0,cout3},sum3}; end 这样就ok了,诡异的,呵呵
相关推荐阅读
用户1359586 2011-07-07 11:49
一个简单字符驱动
网上常见的一个linux字符驱动,见 http://www.dzsc.com/data/html/2009-5-31/76528.html insmod test.ko lsmod      就可...
用户1359586 2010-05-14 22:38
FPGA自己产生reset
遇到一个FPGA没有外部的reset,只能自己产生了,这么简单一个问题居然想了很久才实现。在modelsim仿真是对的,还没有实际操作,也希望和大家讨论一下module reset_generatio...
用户1359586 2010-05-10 22:27
SRAM的时序约束
http://blog.ednchina.com/ilove314/198969/message.aspx#85821  读SRAM时序约束分析分析了SRAM的IO计算,但是没有讲如何具体的计算和Ti...
用户1359586 2010-04-07 21:09
CCS6000安装问题
http://bbs.21ic.com/icview-39374-1-1.html在安装CCS6000的时候,运行ccs6000.exe的时候,碰到好几机子都装不上。主要问题是在安装到“compone...
用户1359586 2010-01-13 21:15
matlab 函数:sprintf
for i="1:20"     j="sprintf"('%03d',i)endj =001j =002j =003j =004j =005j =006j =007j =008j =009j =01...
用户1359586 2009-09-29 09:54
有着十三亿人众的孔孟之乡没有一个教育家
   耶鲁大学校长 小贝诺.施密德特  曾任耶鲁大学校长的小贝诺?施密德特,日前在耶鲁大学学报上公开撰文批判中国大学,引起了美国教育界人士对中国大学的激烈争论。 对中国大学近年来久盛不衰的“做大做强”...
我要评论
1
5
关闭 站长推荐上一条 /2 下一条