第二章_Verilog语法的基本概念.pptVIP

  • 15
  • 0
  • 约7.98千字
  • 约 44页
  • 2018-05-15 发布于四川
  • 举报
2006-2-24 第二章 Verilog语法的基本 概念 周晓波 北京交通大学电子信息学院 xbzhou@bjtu.edu.cn 内容提要 Verilog HDL 在不同抽象层次的描述 Verilog HDL 代码的基本结构及特点 仿真与测试 Verilog的特点(1) 既能进行面向综合的电路设计,也能进行电路的模拟仿真 多层次上对设计系统进行描述,从开关级、门级、寄存器传输级(RTL)到行为级,设计规模任意 灵活的电路描述风格:行为、结构、数据流或混和 Verilog的特点(2) 行为描述语句(条件、赋值、循环等)类似于软件高级语言,便于使用 内置各种基本逻辑门(and, or, nand, etc.)以及开关级元件(pmos,nmos,cmos) 用户定义原语(UDP):组合、时序逻辑 内容提要 Verilog HDL 在不同抽象层次的描述 Verilog HDL 代码的基本结构及特点 仿真与测试 例三: 一个二选一的mux module mux(out, a, b, sel); input a, b, sel; output out; reg out; always @ (sel or a or b) if (! sel) out = a; else out = b; endmodule 例四: 一个二选一的mux module mux(out, a, b, sel); input a, b, sel; output out; not u1(ns1,s1); and #1 u2(sela,a,nsl); and #1 u3(selb,b,sel); or #2 u4(out,sela,selb); endmodule module adder(count, sum, a, b, cin); input [2:0] a,b; input cin; output count; output [2:0] sum; assign {count, sum} = a+b+cin; endmodule module adder4(cout,sum,ina,inb,cin); output[3:0] sum; output cout; input[3:0] ina,inb; input cin; assign {cout,sum}=ina+inb+cin; endmodule Testbench(4位加法器) `timescale 1ns/1ns `include adder4.v module adder_tp; reg[3:0] a,b; reg cin; wire[3:0] sum; wire cout; integer i,j; adder4 adder(sum,cout,a,b,cin); always #5 cin=~cin; initial begin a=0;b=0;cin=0; for(i=1;i16;i=i+1) #10 a=i; end initial begin for(j=1;j16;j=j+1) #10 b=j; end initial begin $monitor($time,,,%d + %d + %b={%b,%d},a,b,cin,cout,sum); #160 $finish; end endmodule 仿真结果(4位加法器) module count4(out,reset,clk); output[3:0] out; input reset,clk; reg[3:0] out; always @(posedge clk) begin if (reset) out=0; else out=out+1; end endmodule Testbench(4位计数器) `timescale 1ns/1ns `include count4.v module coun4_tp; reg clk,reset; wire[3:0] out; parameter DELY=100; count4 mycount(out,reset,clk); always #(DELY/2) clk = ~clk; initial begin clk =0; reset=0; #DELY reset=1; #DELY reset=0; #(DELY*20) $finish; end endmodule 仿真结果(4位计数器) 内容提要

文档评论(0)

1亿VIP精品文档

相关文档