VerilogHDL高级程序设计举例.ppt
《VerilogHDL高级程序设计举例.ppt》由会员分享,可在线阅读,更多相关《VerilogHDL高级程序设计举例.ppt(80页珍藏版)》请在三一办公上搜索。
1、第六章 Verilog HDL高级程序设计举例,7/8/2023,1,Microelectronics School Xidian University,6.1数字电路系统设计的层次化描述方法,Bottom-Up:,7/8/2023,2,Microelectronics School Xidian University,串行加法器:一个四位串行加法器由4个全加器构成。全加器是串行加法器的子模块,而全加器是由基本的逻辑门构成,这些基本的逻辑门就是所说的叶子模块。这个设计中运用叶子模块(基本逻辑门)搭建成子模块(全加器),再用子模块搭建成所需要的电路(串行加法器)。显然,Bottom-Up的设计方
2、法没有明显的规律可循,主要依靠设计者的实践经验和熟练的设计技巧,用逐步试探的方法最后设计出一个完整的数字系统。系统的各项性能指标只有在系统构成后才能分析测试。此种设计方法常用于原理图的设计中,相比于其它方法此种方法对于实现各个子模块电路所需的时间较短。,7/8/2023,3,Microelectronics School Xidian University,Top-Down:,7/8/2023,4,Microelectronics School Xidian University,使用Top-Down设计方法对一个典型cpu进行设计:,7/8/2023,5,Microelectronics S
3、chool Xidian University,向量点积乘法器:采用模块层次化设计方法,设计4维向量点积乘法器,其中向量a=(a1,a2,a3,a4);b=(b1,b2,b3,b4)。点积乘法规则为:,7/8/2023,6,Microelectronics School Xidian University,7/8/2023,7,Microelectronics School Xidian University,Verilog HDL程序代码为:module vector(a1,a2,a3,a4,b1,b2,b3,b4,out);input 3:0 a1,a2,a3,a4,b1,b2,b3,b4
4、;output 9:0 out;wire 7:0 out1,out2,out3,out4;wire 8:0 out5,out6;wire 9:0 out;mul_addtree U1(.x(a1),.y(b1),.out(out1);mul_addtree U2(.x(a2),.y(b2),.out(out2);mul_addtree U3(.x(a3),.y(b3),.out(out3);mul_addtree U4(.x(a4),.y(b4),.out(out4);add#(8)U5(.a(out1),.b(out2),.out(out5);add#(8)U6(.a(out3),.b(ou
5、t4),.out(out6);add#(9)U7(.a(out5),.b(out6),.out(out);endmodule/addermodule add(a,b,out);parameter size=8;input size-1:0 a,b;output size:0 out;assign out=a+b;endmodule,/Multipliermodule mul_addtree(mul_a,mul_b,mul_out);input 3:0 mul_a,mul_b;/IO declarationoutput 7:0 mul_out;wire 3:0 mul_out;/Wire dec
6、laration wire 3:0 stored0,stored1,stored2,stored3;wire 3:0 add01,add23;assign stored3=mul_b3?1b0,mul_a,3b0:8b0;/Logic design assign stored2=mul_b2?2b0,mul_a,2b0:8b0;assign stored1=mul_b1?3b0,mul_a,1b0:8b0;assign stored0=mul_b0?4b0,mul_a:8b0;assign add01=stored1+stored0;assign add23=stored3+stored2;a
7、ssign mul_out=add01+add23;endmodule,6.2典型电路设计,加法器树乘法器加法器树乘法器的设计思想是“移位后加”,并且加法运算采用加法器树的形式。乘法运算的过程是,被乘数与乘数的每一位相乘并且乘以相应的权值,最后将所得的结果相加,便得到了最终的乘法结果。例:下图是一个4位的乘法器结构,用Verilog HDL设计一个加法器树4位乘法器,7/8/2023,8,Microelectronics School Xidian University,7/8/2023,9,Microelectronics School Xidian University,module mu
8、l_addtree(mul_a,mul_b,mul_out);input 3:0 mul_a,mul_b;/IO declarationoutput 7:0 mul_out;wire 7:0 mul_out;/Wire declaration wire 7:0 stored0,stored1,stored2,stored3;wire 7:0 add01,add23;assign stored3=mul_b3?1b0,mul_a,3b0:8b0;/Logic designassign stored2=mul_b2?2b0,mul_a,2b0:8b0;assign stored1=mul_b1?3
9、b0,mul_a,1b0:8b0;assign stored0=mul_b0?4b0,mul_a:8b0;assign add01=stored1+stored0;assign add23=stored3+stored2;assign mul_out=add01+add23;endmodule,module mult_addtree_tb;reg 3:0mult_a;reg 3:0mult_b;wire 7:0mult_out;/module instancemul_addtree U1(.mul_a(mult_a),.mul_b(mult_b),.mul_out(mult_out);init
10、ial/Stimuli signal begin mult_a=0;mult_b=0;repeat(9)begin#20 mult_a=mult_a+1;mult_b=mult_b+1;end end endmodule,流水线结构,例:下图是一个4位的乘法器结构,用Verilog HDL设计一个两级流水线加法器树4位乘法器。两级流水线加法器树4位乘法器结构如图所示,通过在第一级与第二级、第二级与第三级加法器之间插入D触发器组,可以实现两级流水线设计。,7/8/2023,10,Microelectronics School Xidian University,7/8/2023,11,Micro
11、electronics School Xidian University,module mul_addtree_2_stage(clk,clr,mul_a,mul_b,mul_out);input clk,clr;input 3:0 mul_a,mul_b;/IO declaration output 7:0 mul_out;reg 7:0 add_tmp_1,add_tmp_2,mul_out;wire 7:0 stored0,stored1,stored2,stored3;assign stored3=mul_b3?1b0,mul_a,3b0:8b0;/Logic designassign
12、 stored2=mul_b2?2b0,mul_a,2b0:8b0;assign stored1=mul_b1?3b0,mul_a,1b0:8b0;assign stored0=mul_b0?4b0,mul_a:8b0;always(posedge clk or negedge clr)/Timing controlbegin if(!clr)begin add_tmp_1=8b0000_0000;add_tmp_2=8b0000_0000;mul_out=8b0000_0000;end else begin add_tmp_1=stored3+stored2;add_tmp_2=stored
13、1+stored0;mul_out=add_tmp_1+add_tmp_2;end endendmodule,7/8/2023,12,Microelectronics School Xidian University,module mult_addtree_2_stag_tb;reg clk,clr;reg 3:0mult_a,mult_b;wire 7:0mult_out;mul_addtree_2_stage U1(.mul_a(mult_a),.mul_b(mult_b),.mul_out(mult_out),.clk(clk),.clr(clr);initial begin clk=0
14、;clr=0;mult_a=1;mult_b=1;#5 clr=1;end always#10 clk=clk;initial begin repeat(5)begin#20 mult_a=mult_a+1;mult_b=mult_b+1;end end endmodule,6.2.2 Wallace 树乘法器,Wallace树乘法器运算原理如下图所示,其中FA为全加器HA为半加器。其基本原理是,加法从数据最密集的地方开始,不断地反复使用全加器半加器来覆盖“树”。这一级全加器是一个3输入2输出的器件,因此全加器又称为3-2压缩器。通过全加器将树的深度不断缩减,最终缩减为一个深度为2的树。最后一
15、级则采用一个简单的两输入加法器组成。,7/8/2023,13,Microelectronics School Xidian University,7/8/2023,14,Microelectronics School Xidian University,module wallace(x,y,out);parameter size=4;/Define parameters input size-1:0 x,y;output 2*size-1:0 out;/IO declaration wire size*size-1:0 a;wire 1:0 b0,b1,c0,c1,c2,c3;/Wire de
16、claration wire 5:0 add_a,add_b;wire 6:0 add_out;wire 2*size-1:0 out;,7/8/2023,15,Microelectronics School Xidian University,assign a=x3,x3,x2,x2,x1,x3,x1,x0,x3,x2,x1,x0,x2,x1,x0,x0endmodule,module fadd(x,y,z,out);output 1:0out;input x,y,z;assign out=x+y+z;endmodule,module hadd(x,y,out);output 1:0out;
17、input x,y;assign out=x+y;endmodule,7/8/2023,16,Microelectronics School Xidian University,module wallace_tb;reg 3:0 x,y;wire 7:0 out;wallace m(.x(x),.y(y),.out(out);/module instance initial/Stimuli signal begin x=3;y=4;#20 x=2;y=3;#20 x=6;y=8;end endmodule,复数乘法器复数乘法的算法是:设复数,则复数乘法结果复数乘法器的电路结构如下图所示。将复数
18、x的实部与复数y的实部相乘,减去x的虚部与y的虚部相乘,得到输出结果的实部。将x的实部与y的虚部相乘,加上x的虚部与y的实部相乘,得到输出结果的虚部。,7/8/2023,17,Microelectronics School Xidian University,7/8/2023,18,Microelectronics School Xidian University,module complex(a,b,c,d,out_real,out_im);input 3:0a,b,c,d;output 8:0 out_real,out_im;wire 7:0 sub1,sub2,add1,add2;wal
19、laceU1(.x(a),.y(c),.out(sub1);wallace U2(.x(b),.y(d),.out(sub2);wallace U3(.x(a),.y(d),.out(add1);wallace U4(.x(b),.y(c),.out(add2);assignout_real=sub1-sub2;assign out_im=add1+add2;endmodulemodule complex_tb;reg 3:0 a,b,c,d;wire 8:0 out_real;wire 8:0 out_im;complex U1(.a(a),.b(b),.c(c),.d(d),.out_re
20、al(out_real),.out_im(out_im);,initial begin a=2;b=2;c=5;d=4;#10 a=4;b=3;c=2;d=1;#10 a=3;b=2;c=3;d=4;end endmodule,6.2.4 FIR滤波器设计,有限冲激响应(FIR)滤波器就是一种常用的数字滤波器,采用对已输入样值的加权和来形成它的输出。其系统函数为其中z-1表示延时一个时钟周期,z-2表示延时两个时钟周期。对于输入序列Xn的FIR滤波器可用下图所示的结构示意图来表示,其中Xn是输入数据流。各级的输入连接和输出连接被称为抽头,并且系数(b0,b1,bn)被称为抽头系数。一个M阶的F
21、IR滤波器将会有M+1个抽头。通过移位寄存器用每个时钟边沿n(时间下标)处的数据流采样值乘以抽头系数,并将它们加起来形成输出Yn。,7/8/2023,19,Microelectronics School Xidian University,7/8/2023,20,Microelectronics School Xidian University,module FIR(Data_out,Data_in,clock,reset);output 9:0 Data_out;input 3:0 Data_in;input clock,reset;wire 9:0 Data_out;wire 3:0 sa
22、mples_0,samples_1,samples_2,samples_3,samples_4,samples_5,samples_6,samples_7,samples_8;shift_register U1(.Data_in(Data_in),.clock(clock),.reset(reset),.samples_0(samples_0),.samples_1(samples_1),.samples_2(samples_2),.samples_3(samples_3),.samples_4(samples_4),.samples_5(samples_5),.samples_6(sampl
23、es_6),.samples_7(samples_7),.samples_8(samples_8);caculator U2(.samples_0(samples_0),.samples_1(samples_1),.samples_2(samples_2),.samples_3(samples_3),.samples_4(samples_4),.samples_5(samples_5),.samples_6(samples_6),.samples_7(samples_7),.samples_8(samples_8),.Data_out(Data_out);endmodule,7/8/2023,
24、21,Microelectronics School Xidian University,module shift_register(Data_in,clock,reset,samples_0,samples_1,samples_2,samples_3,samples_4,samples_5,samples_6,samples_7,samples_8);input 3:0 Data_in;input clock,reset;output 3:0 samples_0,samples_1,samples_2,samples_3,samples_4,samples_5,samples_6,sampl
25、es_7,samples_8;reg 3:0 samples_0,samples_1,samples_2,samples_3,samples_4,samples_5,samples_6,samples_7,samples_8;always(posedge clock or negedge reset)begin if(reset)begin samples_0=4b0;samples_1=4b0;samples_2=4b0;samples_3=4b0;samples_4=4b0;samples_5=4b0;samples_6=4b0;samples_7=4b0;samples_8=4b0;en
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VerilogHDL 高级 程序设计 举例
链接地址:https://www.31ppt.com/p-5452058.html