EDA技术与Verilog设计第7章.ppt_第1页
EDA技术与Verilog设计第7章.ppt_第2页
EDA技术与Verilog设计第7章.ppt_第3页
EDA技术与Verilog设计第7章.ppt_第4页
EDA技术与Verilog设计第7章.ppt_第5页
已阅读5页,还剩26页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

第7章 Verilog设计的层次与风格 主要 内容 结构(结构(StructuralStructural)描述描述 行为(行为(BehaviouralBehavioural)描述描述 数据流(数据流(Data FlowData Flow)描述描述 基本组合电路设计基本组合电路设计 基本时序电路设计基本时序电路设计 7.1 Verilog设计的层次 结构(Structural)描述 行为(Behavioural)描述 数据流(Data Flow)描述 在Verilog程序中可通过如下方式描述电路的 结构 调用Verilog内置门元件(门级结构描述) 调用开关级元件(晶体管级结构描述) 用户自定义元件UDP(也在门级) 7.2 结构(Structural)描述 Verilog的 内置门元件 门元件的调用 调用门元件的格式为: 门元件名字 () 其中普通门的端口列表按下面的顺序列出: (输出,输入1,输入2,输入3); 比如: and a1(out,in1,in2,in3);/三输入与门 对于三态门,则按如下顺序列出输入输出端口: (输出,输入,使能控制端); 比如: bufif1 mytri1(out,in,enable);/高电平使能的三态门 门级结构描述的2选1MUX module MUX1(out, a, b, sel); output out; input a, b, sel; not (sel_, sel); and (a1, a, sel_), (a2, b, sel); or (out, a1, a2); endmodule 7.3 行为描述 就是对设计实体的数学模型的描述,其抽象程度 远高于结构描述方式。行为描述类似于高级编程 语言,当描述一个设计实体的行为时,无需知道 具体电路的结构,只需要描述清楚输入与输出信 号的行为,而不需要花费更多的精力关注设计功 能的门级实现。 行为描述的2选1MUX module mux2(out, a, b, sel); output out; input a, b, sel; reg out; always (a or b or sel) begin if(sel) out = b; else out = a; end endmodule 7.4 数据流描述 数据流描述方式主要使用持续赋值语句,多用 于描述组合逻辑电路,其格式为: assign LHS_net=RHS_expression; 右边表达式中的操作数无论何时发生变化,都 会引起表达式值的重新计算, 并将重新计算后 的值赋予左边表达式的net型变量。 数据流描述的2选1MUX module MUX3(out, a, b, sel); output out; input a, b, sel; assign out = sel ? b : a; endmodule 7.5 不同描述风格的设计 对设计者而言,采用的描述级别越高,设计越 容易;对综合器而言,行为级的描述为综合器 的优化提供了更大的空间,较之门级结构描述 更能发挥综合器的性能,所以在电路设计中, 除非一些关键路径的设计采用门级结构描述外 ,一般更多地采用行为建模方式。 结构描述的一位全加器 module full_add1(a, b, cin, sum, cout); input a, b, cin; output sum, cout; wire s1,m1, m2, m3; and (m1, a, b), (m2, b, cin), (m3, a, cin); xor (s1, a, b), (sum, s1, cin); or (cout, m1, m2, m3); endmodule 数据流描述的1位全加器 module full_add2(a, b, cin, sum, cout); input a, b, cin; output sum, cout; assign sum = a b cin; assign cout = (a endmodule 行为描述的1位全加器 module full_add4(a,b,cin,sum,cout); input a,b,cin; output sum,cout; reg sum,cout,m1,m2,m3; always (a or b or cin) begin m1=a m2=b m3=a sum=(ab)cin; cout=(m1|m2)|m3; end endmodule 4位加法器 4-bit adder include “ full_add1.v“ module add4_1(sum, cout, a, b, cin); output 3:0 sum; output cout; input 3:0 a, b; input cin; full_add1 f0 (a0,b0,cin,sum0,cin1); full_add1 f1 (a1,b1,cin1,sum1, cin2); full_add1 f2 (a2,b2,cin2,sum2, cin3); full_add1 f3 (a3,b3,cin3,sum3, cout); endmodule 结构描述的4位级连全加器 module add4_2(cout,sum,a,b,cin); output3:0 sum; output cout; input3:0 a,b; input cin; assign cout,sum=a+b+cin; endmodule 数据流描述的4位加法器 行为描述的4位加法器 module add4_3(cout,sum,a,b,cin); output3:0 sum; output cout; input3:0 a,b; input cin; reg3:0 sum; reg cout; always ( a or b or cin ) begin cout,sum=a+b+cin; end endmodule 7.6 基本组合电路设计 门级结构描述 module gate1(F,A,B,C,D); input A,B,C,D; output F; nand(F1,A,B); /调用门元件 and(F2,B,C,D); or(F,F1,F2); endmodule 数据流描述 module gate2(F,A,B,C,D); input A,B,C,D; output F; assign F=(A /assign持续赋值 endmodule 行为描述 module gate3(F,A,B,C,D); input A,B,C,D; output F; reg F; always (A or B or C or D) /过程赋值 begin F=(A end endmodule 基本组合电路设计 用bufif1关键字描述的三态门 module tri_1 (in, en, out); input in, en; output out; tri out; bufif1 b1(out, in, en); endmodule 基本组合电路设计 3-to-8 decoder module decoder_38(out, in); output7:0 out; input2:0 in; reg7:0 out; always (in) begin case(in) 3d0: out=8b11111110; 3d1: out=8b11111101; 3d2: out=8b11111011; 3d3: out=8b11110111; 3d4: out=8b11101111; 3d5: out=8b11011111; 3d6: out=8b10111111; 3d7: out=8b01111111; endcase end endmodule 基本组合电路设计 奇偶校验位产生器 Module parity(even_bit,odd_bit,input_bus); output even_bit,odd_bit; input7:0 input_bus; assign odd_bit=input_bus; /产生奇校验位 assign even_bit=odd_bit; /产生偶校验 位 endmodule 基本组合电路设计 用if-else语句描述的4选1 MUX module mux4_1(out,in0,in1,in2,in3,sel); output out; input in0,in1,in2,in3; input1:0 sel; reg out; always (in0 or in1 or in2 or in3 or sel) begin if(sel=2b00) out=in0; else if(sel=2b01) out=in1; else if(sel=2b10) out=in2; else out=in3; end endmodule 7.7 基本时序电路设计 D-FF designs(基本D触发器) module DFF(Q, D, CLK); output Q; input D, CLK; reg Q; always (posedge CLK) begin Q = D; end endmodule 基本时序电路设计 带异步清0、异步置1的D触发发器 module DFF1(q,qn,d,clk,set,reset); input d,clk,set,reset; output q,qn;reg q,qn; always (posedge clk or negedge set or negedge reset) begin if (!reset) begin q = 0; qn = 1; /异步清0,低电平有效 end else if (!set) begin q = 1; qn = 0; /异步置1,低电平有效 end else begin q = d;qn = d; end end endmodule 基本时序电路设计 带同步清0、同步置1的D触发器 module DFF2(q, qn, d, clk, set, reset); input d, clk, set, reset; output q, qn; reg q, qn; always (posedge clk) begin if (reset) begin q=0;qn=1; end /同步清0,高电平有效 else if (set) begin q =1;qn =0; end /同步置1,高电平有效 else begin q=d; qn=d;end end endmodule 基本时序电路设计 8位数据锁锁存器 module latch_8(qout,data,clk); output7:0 qout; input7:0 data; input clk; reg7:0 qout; always (clk or data) begin if(clk) qout=data; end endmodule 基本时序电路设计 8位数据寄存器 module reg8(out_data,in_data,clk,clr); output7:0 out_data; input7:0 in_data; input clk,clr; reg7:0 out_data; always (posedge clk or posedge clr) begin if(clr) out_data =0; else out_data = in_data; end endmodule 基本时序电路设计 可变模加法/减法计数器 module updown_count(d,clk,clear,load,up_down,qd); input7:0 d; input clk,clear,load,up_down; output7:0 qd; reg7:0 cnt; assign qd=cnt; always (posedge clk) begin if(!clear) cnt=8h00;/同步清0,低电电平有效 else if(load) cnt=d

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论