Verilog 实验指导书

合集下载

实验项目Verilog组合逻辑设计实验指导书报告

实验项目Verilog组合逻辑设计实验指导书报告

电子科技大学计算机科学与工程学院实验指导书实验名称Verilog组合逻辑设计电子科技大学教务处制表一、概述本实验使用Xilinx ISE软件和Verilog语言进行组合逻辑的设计与实现。

实验内容包括1.3-8译码器的设计和实现。

2.4位并行进位加法器的设计和实现。

3.两输入4位多路选择器的设计和实现。

实验要求如下:1.采用Verilog语言设计,则使用门级方式进行描述。

2.编写仿真测试代码。

3.编写约束文件,使输入、输出信号与开发板的引脚对应。

4.下载到FPGA开发板,拨动输入开关,观察Led灯的显示是否符合真值表。

二、实验原理:1.74x138译码器是输出低有效的3-8译码器。

表1所示为74x138译码器的真值表。

表1 译码器的真值表根据上述函数表达式,可画出逻辑电路图为。

图1 3-8译码器的逻辑电路图2. 数据选择器的逻辑功能是根据地址选择端的控制,从多路输入数据中选择一路数据输出。

因此,它可实现时分多路传输电路中发送端电子开关的功能,故又称为复用器(Multiplexer),并用MUX来表示。

201Y 为数据选择器的输出,根据真值表可写出它的输出函数表达式为:如果输入再加上低有效的输入使能端,则输出的表达式变为根据上述函数表达式,可画出2输入4位多路选择器的逻辑电路图为。

图2 2输入4位多路选择器的逻辑电路图2. 1位全加器的真值表如下表3 1位全加器的真值表对于4位并行加法器,可以按入下公式进行设计图3所示为4位并行进位加法器框图,本实验中用Verilog语句来描述。

图3 4位并行进位加法器三、设计实现1.在ISE设计中可以直接输入如下3-8译码器的代码仿真结果如下图所示。

图4 译码器的仿真结果3.译码器在Nexys3开发板上的约束文件4.4位并行加法器的代码仿真结果如下图所示。

图5 加法器的仿真结果6.加法器在Nexys3开发板上的约束文件7.数据选择器的代码仿真结果如下图所示。

图6 数据选择器的仿真结果9.数据选择器在Nexys3开发板上的约束文件。

verilog实验1

verilog实验1

实验一一.实验内容:a.用数据流建模编写如图1奇偶校验电路模块,并编写测试模块仿真图1 奇偶校验电路模块b.编写2/4译码器电路模块,并编写测试模块仿真2.实验指导2.1创建工程及工程库a.在MODELSIM菜单栏中选择FILE-NEW-PROJECT输入工程名及工程库名称。

b.创建工程及工程库后,添加两个文件,电路模块文件及测试模块文件到所创建的工程中。

c.编写电路模块及测试模块程序。

d.编译电路模块及测试模块程序。

2.2运行仿真编译电路模块及测试模块程序通过后,在菜单栏中或快捷键选SIMULATE,启动仿真,进入START SIMULATION 对话框,在工作库名下,选中顶层测试模块,点击OK,进入仿真界面。

进入仿真界面后,在SIM工作区选中测试模块,添加仿真信号,选中测试模块,在右键弹出的菜单中选择ADD-ADD TO WAVE。

完成上述操作后,可运行仿真。

2.3参考设计2.3.1奇偶校a.电路模块module parity_9_bit(D,even,odd);input [8:0] D;output even,odd;assign #(4,3) odd=~even;assign #(4,4) even=(((D[0]^D[1])^D[2]^D[3]))^((D[4]^D[5])^(D[6]^D[7])))^D[8];endmoduleb.测试模块module test_parity;2.3.2译码器a.2/4译码器真值表b.电路模块module decode2_4(d,s);二.程序设计2.14奇偶校验程序module jioujiao (D, even,odd) ;input [8:0] D ;output even, odd;assign #(4,3) odd= ~even;assign #(4,4) even= (((D[0]^D[1])^(D[2]^D[3]))^ ((D[4]^D[5])^(D[6]^D[7])))^ D[8];endmodule测试程序`timescale 1 ns/ 1 nsmodule parity_9_bit_vlg_tst();// constants// general purpose registers// test vector input registersreg [8:0] D;// wireswire even;wire odd;// assign statements (if any)parity_9_bit i1 (// port map - connection between master ports and signals/registers .D(D),.even(even),.odd(odd));initialbegin#0 D = 0;#20 D = 1;#30 D = 9'b0_0000_0011;#30 D = 9'b0_0000_0111;#30 D = 9'b0_0000_1111;#30 D = 9'b0_0001_1111;#30 D = 9'b0_0011_1111;#30 D = 9'b0_0111_1111;#30 $stop;endendmodule2.24二四译码器程序module decode2_4(d, s, rst);input [1:0]s;input rst;output [3:0]d;reg [3:0]d;always @(s or rst)beginif(!rst)d <= 0;else if(s==2'b00) d <= 4'b0001;else if(s==2'b01) d <= 4'b0010;else if(s==2'b10) d <= 4'b0100;else if(s==2'b11) d <= 4'b1000;endendmodule测试程序`timescale 1 ns/ 1 psmodule decode2_4_vlg_tst();// constants// general purpose registersreg eachvec;// test vector input registersreg rst;reg [1:0] s;wire [3:0] d;// assign statements (if any)decode2_4 i1 (.d(d),.rst(rst),.s(s));initialbegins = 0;rst = 1;#1 rst = 0;#1 rst = 1;#10s=2'b00;#10s=2'b01;#10s=2'b10;#10s=2'b11;#10 $stop;endendmodule三.实验结果测试图1图2 1奇偶校验仿真图图22二四译码器仿真图四.实验总结本次实验是通过数据流建模的方式完成部分任务,通过本次实验。

实验项目Verilog组合逻辑设计实验指导书

实验项目Verilog组合逻辑设计实验指导书

电子科技大学计算机科学与工程学院实验指导书实验名称Verilog组合逻辑设计电子科技大学教务处制表一、概述本实验使用Xilinx ISE软件和Verilog语言进行组合逻辑的设计与实现。

实验内容包括1.3-8译码器的设计和实现。

2.4位并行进位加法器的设计和实现。

3.两输入4位多路选择器的设计和实现。

实验要求如下:1.采用Verilog语言设计,则使用门级方式进行描述。

2.编写仿真测试代码。

3.编写约束文件,使输入、输出信号与开发板的引脚对应。

4.下载到FPGA开发板,拨动输入开关,观察Led灯的显示是否符合真值表。

二、实验原理:1.74x138译码器是输出低有效的3-8译码器。

表1所示为74x138译码器的真值表。

12_2_ 0_1_2_3_4_5_6_7_G G G A L G B LY L C B A GY L C B A GY L C B A GY L C B A GY L C B A GY L C B A GY L C B A GY L C B A G=⋅⋅=⋅⋅⋅=⋅⋅⋅=⋅⋅⋅=⋅⋅⋅=⋅⋅⋅=⋅⋅⋅=⋅⋅⋅=⋅⋅⋅根据上述函数表达式,可画出逻辑电路图为。

图1 3-8译码器的逻辑电路图2. 数据选择器的逻辑功能是根据地址选择端的控制,从多路输入数据中选择一路数据输出。

因此,它可实现时分多路传输电路中发送端电子开关的功能,故又称为复用器(Multiplexer),并用MUX来表示。

表2 2输入1位多路选择器的真值表数据输入选择控制S 输出Y D0 D10 0 0 00 1 00 1 0 0 1 1 1 0 1 0 0 1 0 0 1 1 1 1 0 1 0 1 1 1 101为选择控制端,Y 为数据选择器的输出,根据真值表可写出它的输出函数表达式为:01Y SD SD =+如果输入再加上低有效的输入使能端,则输出的表达式变为0101_()__Y EN L SD SD EN L S D EN L S D =⋅+=⋅⋅+⋅⋅根据上述函数表达式,可画出2输入4位多路选择器的逻辑电路图为。

《FPGA设计与应用》实验指导书全(Verilog版)

《FPGA设计与应用》实验指导书全(Verilog版)

《FPGA设计与应用》实验指导书熊利祥编武汉理工大学华夏学院2011年9月前言一、实验课目的数字电路与系统设计实验课是电子工程类专业教学中重要的实践环节,包括了ISE开发环境基本操作及FPGA的基本原理、基带传输系统的设计、Uart串口控制器电路的设计、PS/2接口的设计、VGA显示接口设计。

要求学生通过实验学会正确使用EDA技术,掌握FPGA器件的开发,熟练使用ISE开发环境,掌握Verilog语言的编程,掌握数字电路和系统的设计。

通过实验,使学生加深对课堂专业教学内容的理解,培养学生理论联系实际的能力,实事求是,严谨的科学作风,使学生通过实验结果,利用所学的理论去分析研究EDA技术。

培养学生使用Basys 2开发板的能力以及运用实验方法解决实际问题的能力。

二、实验要求:1.课前预习①认真阅读实验指导书,了解实验内容;②认真阅读有关实验的理论知识;③读懂程序代码。

2.实验过程①按时到达实验室;②认真听取老师对实验内容及实验要求的讲解;③认真进行实验的每一步,观察程序代码与仿真结果是否相符;④将实验过程中程序代码和仿真结果提交给老师审查;⑤做完实验后,整理实验设备,关闭实验开发板电源、电脑电源后方可离开。

3.实验报告①按要求认真填写实验报告书;②认真分析实验结果;③按时将实验报告交给老师批阅。

三、实验学生守则1.保持室内整洁,不准随地吐痰、不准乱丢杂物、不准大声喧哗、不准吸烟、不准吃东西;2.爱护公务,不得在实验桌及墙壁上书写刻画,不得擅自删除电脑里面的文件;3.安全用电,严禁触及任何带电体的裸露部分,严禁带电接线和拆线;4.任何规章或不按老师要求操作造成仪器设备损坏须论价赔偿。

目录实验一Uart通用串口接口的设计 (4)实验二PS/2接口的设计 (28)实验三VGA显示接口设计 (30)附录一 basys 2开发板资料 (36)实验一 Uart串口控制接口电路的设计一、实验目的1.掌握分频模块的设计方法。

天大Verilog实验说明书

天大Verilog实验说明书

试验一:开关、LED灯及多路复用器1.1将输入/输出器件连接到FPGA上实验原理:用18 个波段开关作为电路的输入,用18 个红色LED作为电路的输出,实现用波段开关控制红色LED,将开关拨到上方,相应的LED灯亮,否则LED灯灭实验步骤:实验步骤:(1)新建一个QuartusII工程(2)新建一个Verilog文件,将该Verilog文件添加到工程中并编译整个工程(3)分配引脚LEDR[0],PIN_AE23 SW[0],PIN_N25LEDR[1],PIN_AF23 SW[1],PIN_N26LEDR[2],PIN_AB21 SW[2],PIN_P25LEDR[3],PIN_AC22 SW[3],PIN_AE14LEDR[4],PIN_AD22 SW[4],PIN_AF14LEDR[5],PIN_AD23 SW[5],PIN_AD13LEDR[6],PIN_AD21 SW[6],PIN_AC13LEDR[7],PIN_AC21 SW[7],PIN_C13LEDR[8],PIN_AA14 SW[8],PIN_B13LEDR[9],PIN_Y13 SW[9],PIN_A13LEDR[10],PIN_AA13 SW[10],PIN_N1LEDR[11],PIN_AC14 SW[11],PIN_P1LEDR[12],PIN_AD15 SW[12],PIN_P2LEDR[13],PIN_AE15 SW[13],PIN_T7LEDR[14],PIN_AF13 SW[14],PIN_U3LEDR[15],PIN_AE13 SW[15],PIN_U4LEDR[16],PIN_AE12 SW[16],PIN_V1LEDR[17],PIN_AD12 SW[17],PIN_V2(4)编译该工程,完成后下载到FPGA中(5)通过拨动波段开关并观察红色LED的变化来验证所设计的功能是否正确参考代码:module led1(sw,d);input [17:0] sw;output [17:0] d;assign d=sw;endmodule1.2 3位宽5选1多路复用器实验原理:实现一个5选1的多路复用器,即从5个输入x,y,w,u,v中选取一个输出到m,输出选择用一个3位的输入s0s1s2实现实验步骤:(1)新建一个QuartusII工程(2)新建一个Verilog文件,用SW17~SW15作为选择端输入s0s1s2,用剩下的15个波段开关SW14~SW0作为u,v,w,x,y,用绿色LED即LEDG2~LEDG0作为输出M,将该Verilog 文件添加到工程中(3)分配连接波段开关、绿色LED的FPGA管脚LEDG[0],PIN_AE22LEDG[1],PIN_AF22LEDG[2],PIN_W19LEDG[3],PIN_V18LEDG[4],PIN_U18LEDG[5],PIN_U17LEDG[6],PIN_AA20LEDG[7],PIN_Y18(4)编译工程,完成后下载到FPGA中(5)拨动波段开关并观察绿色LED的变化,以验证3位5选1多路复用器的功能是否正确,确定从u到v的所有输入都能够被选择输出到M参考代码:module sel5to1(s,u,v,w,x,y,m);input[2:0] s,u,v,w,x,y;output[2:0] m;reg[2:0] m;always@(s)beginif(s=='b000)m=u;else if(s=='b001)m=v;else if(s=='b010)m=w;else if(s=='b011)m=x;else if(s=='b100)m=y;elsem=m;endendmodule1.3并行加法器实验原理:全加器的电路如图1(a)所示,输入为a,b和ci,输出为s和co,图1(b)是该电路的符号表示,表1为全加器的真值表,全加器实现了二进制加法,其输出为一个2位的二进制和co s=a+b+ci,用四个全加器模块的电路可以实现4位二进制数的加法,如图1(c)所示,这种加法器电路一般称为并行加法器(a ) (b )表1 实验步骤:(1)新建一个QuartusII 工程(2)建立一个Verilog 文件,然后用4个全加器电路来实现并行加法器电路(3)分别用SW7~SW4和SW3~SW0代表A 和B ,使用SW8代表加法器的进位输入cin ,而加法器的输出cout 和S 连接到LEDG4~LEDG0上,将代码添加到工程中 (4)进行引脚分配(5)改变输入A ,B 和cin 的值,观察计算结果是否正确 参考代码:module add(a,b,s,cout); input[3:0] a,b; output [3:0] s; output cout;wire c0,c1,c2;addone addone1(a[0],b[0],0,s[0],c0), addone2(a[1],b[1],c0,s[1],c1), addone3(a[2],b[2],c1,s[2],c2),addone4(a[3],b[3],c2,s[3],cout);endmoduleciabbcoF AFA FA FA FAs0s1s2s3c o c ic 1c 2c 3a1a2a3b1b2b3a0b0omodule addone(a,b,cin,s,cout);input a,b, cin;output s,cout;assign {cout,s}=a+b+cin;endmodule实验二:乘法器、锁存器及触发器2.1无符号乘法器实验原理:图1(a)位两位十进制数乘法的实现P=A*B,其它A=12,B=11,P=132,图1(b)是用4位二进制乘法实现的A和B的乘积,B的每一位要么是0,要么是1,因此算式中的加数要么是一位的A,要么是0000,图1(c)是用逻辑与实现的二进制乘法的过程12* 111212132(a)(b)图1(c)图2是实现4位二进制乘法P=A*B的电路,该电路中,用逻辑与实现每一行的乘法,用全加器实现每一列的加法,从而得到所需要的和。

Verilog实验指导书(2)

Verilog实验指导书(2)

实验二:存储器的设计在计算机系统中,一般都提供一定数量的存储器。

在用FPGA实现的系统中,除可以使用FPGA本身提供的存储器资源外,还可以使用FPGA的外部扩充存储器。

本实验要求设计一个32×8 RAM,如下图所示,它包含5位地址、8位数据口和一个写控制端口。

实现这个存储器有两种方法:一种是采用FPGA上的存储器块实现。

EP2C35 FPGA片内共有105个M4K RAM块,每个M4K包含4096位,支持4K×1、2K×2、1K×4和512×8四种配置。

本实验选择512×8配置,而且只使用RAM中的32个字节。

另一种是采用外部存储器芯片实现。

每个M4K都有专用的寄存器用于所有输入、输出与时钟同步,因此在使用M4K时,要让输入、输出端口之一或全部与输入时钟同步。

改进之后的32×8 RAM 模块如下图所示。

1.用LPM实现32×8 RAM常用的逻辑电路如加法器、计数器、寄存器和存储器都可调用QuartusII提供的参数化功能模块LPM实现。

本实验采用LPM altsyncram实现存储器。

第1步:新建一个Quartus项目,并命名为lpm_sram。

第2步:新建一个图形文件,新建一个图形文件,并命名为lpm_sram.bdf。

打开符号(symbol)库,如下图所示。

从左边符号库中选中”altsyncram”,点击“ok”出现如下图所示的界面,第4步:点击Next按钮,在下一个对话框中选择“with one read/write port”模式,如下图所示。

第5步:点击Next按钮,在下一个对话框中选择存储器容量是32个字节,如下图所示。

第6步:其他对话框均采用默认值即可,最后按Finish按钮即完成RAM模块的设计。

第8步:添加相应的输入和输出端口,端口命名如下图所示。

第9步:进行语法检查,检查通过后,打开Pin Planner,用SW7~SW0作为数据输入、SW12~SW8作为地址的输入、SW13作为Write信号、结果显示在LEDG 上。

Verilog HDL基础实验指南说明书

Verilog HDL基础实验指南说明书

Using Fundamental Gates LabOverview:In this lab you will learn how to model simple gates using Verilog HDL and use them to create a more complex design. You will use fundamental gates using language supported primitive gates. After building the basic models you will create a hierarchical design. Outcome:You will understand how to use Verilog primitive gates. You will learn how to create a model using ISE Create Project wizard. You will instantiate lower-level models to create a bigger model. You will use ISE simulator to simulate the design. You will add user constraint file (ucf) to assign pins so the design can be targeted to National Instruments (NI) Digital Electronics FPGA Board. You will implement the design and create a bitstream file using ISE’s implementation tools. Once bitstream is created, you will download using ISE’s iMPACT program and verify the design functionality. Background:Verilog HDL is a hardware description language that can be used to model a digital system at many levels of abstraction ranging from algorithmic- to the gate- to the switch-level. The complexity of the digital system being modeled could vary from a simple gate to a complete system. Various levels of abstractions can be used in modeling the digital system based on its functionality and complexity. The language supports constructs and means to model the digital system in a hierarchical fashion. It also allows designer to describe timing explicitly. The richness of the language constructs is exploited by using same language constructs to test the system.A system- from a simple gate to a complex circuit- typically will have some input signals and some output signals to interact with either other digital devices or external board, and will have some functionality for which it has been designed. The basic unit of description in Verilog is the module. A module describes the functionality of a design and also describes the ports through which it communicates. The basic syntax of the module is:module module_name (port_list);DeclarationsStatementsendmoduleThe Verilog language is case sensitive. In the above example module and endmodule are keywords describing beginning of a module definition and ending of the module definition. You can not have nested module definitions, i.e. you can not have another module keyword within a module-endmodule pair. In the language, a statement is delimited by a semicolon. You can have multiple statements on a given line. The declarations in the above example can be definition of data types such as wire and reg, can be parameter definition, ports direction, functions, and tasks to name few. The Statements can be initial, always, and continuous assignment statements as well as module, gate, UDP (User Defined Primitives) instantiations. The Statements describe theactual functionality of the module. The identifiers must be defined using Declarations before they ca be used.The language defines three fundamental modeling styles. In a given module all or subset of these styles can be used. The three modeling styles are: Structural, Dataflow, and Behavioral. This lab exercise uses Structural style modeling. Structure can be described in Verilog using Built-in gate primitives, Switch-level primitives, User-Defined Primitives (UDP), and module instances. The Switch-level primitives are used to model fundamental gate functionality or a system built with switches or transistors. The UDP are used to define a unit as a black-box with providing functionality in truth-table form and explicit timing relationships between input and output ports. In this lab exercise you will use gate primitives and module instantiations. The language defines the following gates:[Verilog Quick Reference]Here is an example of instantiating a nor gate:nor X1 (S1, A, B);where X1 is the instance name. It is optional for the gate- or switch-level instantiation. The instance name is required for a module instantiation. S1 is output, and A and B are input.References:1. National Instruments’ Digital Electronics FPGA Board user manual2. Verilog HDL booksStephen Brown, Zvonko G. Vranesic, “Fundamentals of Digital Logic with Verilog Design”, 2002 Zainalabedin Navabi, “Verilog Digital Systems Design: RT Level Synthesis, Testbench, andVerification”, 2005Samir Paltinkar, “Verilog HDL: A Guide to Digital Design and Synthesis”, 2003Joseph Cavanagh, “Verilog HDL: Digital Design and Modeling”, 2007Michael D. Ciletti, “Modeling, Synthesis, and Rapid Prototyping with Verilog HDL”, 2003Douglas J. Smith, “HDL Chip Design: A Practical Guide for Designing, Synthesizing and Simulating ASICs and FPGAs using VHDL or Verilog”, 19963. On-line references:Verilog HDL Reference Card: /class/ee183/handouts_win2003/VerilogQuickRef.pdfVerilog Quick Reference: /~howard/pulsenet/docs/verilog_quikref.pdfTutorial on Verilog: .sa/COE/abouh/COE%20202%20Verilog%20Guidelines.pdfProblem Statement:Design a minority gate that has three inputs and one output. The output is logic 1 whenever the numbers of inputs which are logic 1 are zero or less than half of the input (i.e. 1 in this case).Implementation:The circuit to be designed consists of three inputs and one output. Typically such circuit can be implemented using a combinational network. A truth table is created and then some Boolean minimization technique (e.g. K-Map) may be used to reduce the number of logic gates used. The truth table for the design at hand is shown next along with K-Map and minimized Boolean expression.Inputs A B C OutputF0 0 0 1 0 0 1 1 0 1 0 10 1 1 01 0 0 1 1 0 1 0 1 1 0 0 1 1 1 01 1 0 11 0 0 000 01 11 1001AB C F = A C + B C + A B F = (A+C) * (B+C) * (A+B)The two expressions are equivalent. We will use the 2nd expression in this design.Procedure:1. Create a ISE project• Launch ISE: Select Start → Programs → Xilinx ISE Design Suite 10.1 →ISE → Project Navigator• In the Project Navigator, select File → New Project. The New Project Wizard opens• For Project Location, use the “…” button to browse to C:\NI\Verilog_labs, and then click OK• For Project Name, type minoritygate_lab • Click Next • Select the following options and click Next Device Family: Spartan3E Device: xc3s500E Package: ft256 Speed Grade: –5 Synthesis Tool: XST (VHDL/Verilog) Simulator: ISE Simulator (VHDL/Verilog)Preferred Language: Verilog•The Create New Source dialog will appear. You can use this dialog to createa new HDL source file by defining the module name and ports. You will dothis once to get experience. Subsequent files creation will be done using a text file rather than using the dialog. Click New Source button• A new source wizard will appear. Select Verilog Module as a source type andenter my_2or in the File name field and click Next• A Define Module form will appear. Enter in1, in2 as the input in Port Nam e field and out1 as the output. Change the input Direction to output by clicking and drop-down button and selection output as the direction. Click Next and then OK to create the file•Click Next and Add Existing Sources form will be displayed. Click Finish as we do not have anything to add•Click Finish. A project will be created and my_or2.v file be created and added to the project. The file will be opened and displayed in the editorwindow. You can enter related information regarding project name, target devices, etc. You will also see a module and endmodule statements arecreated. The only thing that is needed is to add the functionalityYou will notice that the project hierarchy view window showing the part information as well as my_2or as the top-level model•Enter a gate-level instantiation statement that uses primitive gate to perform or function on the two inputs and output the result with 2 ns delay•Save and close the file•Click New button () and select text file and click OK•Enter the module, endmodule, and gate-level instantiation statement to model 2-input and function using the port names as in1, in2, and out1•Save and close the file, giving my_2and.v as the filename•Similarly, create a new model for the minority gate functionality (3 inputs [in1, in2, and in3] and one output [out1]), instantiating my_2or and my_2and models, and using necessary number of fundamental gates instantiations and having 2 ns as the delay. Use named-mapped port convention. The named-port convention requires a port name of the parent module be listed firstpreceded with “.” followed by a net name that is connecting that port in the current module. In the below figure, .in1 is the port name of my_or2 mdoule (parent module) where as in1_n is the net name connecting to that port. In named-port mapping convention, one need not mention all the ports of the parent module. The unlisted parent module ports are drive logic 0 if theyinput and left unconnected if they are output.•Right-click on my_2or entry in the Sources window and select Add Source …•Select minoritygate.v and my_2and.v files and click Open•Click OK to finish the addition2. Simulate the design using ISIM•Right-click on the minoritygate entry in Sources window and select New Source•Select Test Bench Waveform as the source type and enter minoritygate_tb in the File name field. Click Next•Select minoritygate as the UUT to associate the testbench to the source model and click Next followed by clicking Finish button•Select combinatorial (internal clock) and click Finish to display the input and output signals. Click appropriately in the waveform window to generate input stimulus as shown below•Save the file•Select Sources tab and then click minoritygate in Sources window, and click on the drop-down button of the Sources for window and select Behavioral Simulation•Select minoritygate_tb in Sources tab, expand its entry to see UUT. Select Processes tab, expand Xilinx USE Simulator, and double-click on Simulate Behavioral Model entry to run the simulator•The source files will be compiled and the executable file(minoritygate_tb_ism_beh.exe) be generated which is then run, displaying the result in a waveform window•You can view lower-level signals by selecting Sim Insulator tab in Sources window, expanding hierarchy, selecting a particular instance, then clicking Sim Objects in tab in Processes window, and then selecting and dragging a desired signal(s) in the waveform window•You can zoom-in or zoom-out the waveform window by clicking on appropriate buttons ()•You can restart by clicking on () button and re-run by clicking on run for the specified time()button•You can change the run-time by typing in the new time field(), clicking restart button, and then clicking on run for the specified time button•Close the simulator by closing the waveform window and click OK to close the active simulator3. Implement the design•Select implementation in Sources for window•Select minoritygate module in Sources window•Expand User Constraints processes in Processes window•Double-click on Floorplan IO Pre-Synthesis to open PACE program•Click OK and then Yes to add ucf file•In PACE window assign pin locations and I/O Std as shown below•Click Save button• A dialog box will appear. Choose XST Default: <> option and click OK as we are using XST synthesis tools•Close the PACE program using File→Close• A minoritygate.ucf file will be added to the project. Open that file and see how the constraints are written•Close the file•Select minoritygate in Sources window and double-click on Implement Design process in Processes window. This will go through Synthesis, and Implementation stages•Expand Synthesis processes and double click on View RTL Schematic and View Technology Schematic processes to get different views•You can push-in to a lower-level schematic by double-clicking on the top-level•When the implementation is completed, expand Implement Design process to view the Place & Route report•Double-click on the Place & Route Report to view the report. Look at the resource utilization and note that 1 slice is being used•You can see similar information by clicking on Design Summary tab and looking at the various information4. Verify the design in hardware•Select minoritygate in Sources window and double-click on GenerateProgramming File process to generate the bit file for the designConfiguration Project (iMPACT) process•Connect the board with the USB-JTAG cable•Power ON the board•Click Finish to use the JTAG chain•Select minoritygate.bit file to be assigned to xc3s500e device and click Open•Click Bypass button for xcf04s and then OK to use FPGA device programming•Right-click on the FPGA and select Program•This will program the FPGA and DONE light will lit on the board•Once programmed successfully, verify the functionality by using SW0 thru SW2 and monitoring LD0 output. Verify that when more than one switch isturned ON, LD0 turns OFF•Once confirmed the functionality, power down the board and close ISE saving project changesConclusion:In this lab exercise you learned how to design a hierarchical system. You also learned how to model a circuit using gate-level as well as module-instantiations. You were able to simulate the design at each level and then verify the complete design in hardware board.。

verilog实验指导

verilog实验指导

verilog实验指导预览说明:预览图片所展示的格式为文档的源格式展示,下载源文件没有水印,内容可编辑和复制一、ISE软件的基本介绍1、ISE用户界面ISE的界面如图1-1所示,由上到下主要分为标题栏、菜单栏、工具栏、工程管理区、源文件编辑区、过程管理区、信息显示区、状态栏等8部分。

标题栏:主要显示当前工程的名称和当前打开的文件名称。

菜单栏:主要包括文件(File)、编辑(Edit)、视图(View)、工程(Project)、源文件(Source)、操作(Process)、窗口(Window)和帮助(Help)等8个下拉菜单。

其使用方法和常用的Windows软件类似。

工具栏:主要包含了常用命令的快捷按钮。

灵活运用工具栏可以极大地方便用户在ISE中的操作。

在工程管理中,此工具栏的运用极为频繁。

工程管理区:提供了工程以及其相关文件的显示和管理功能,主要包括源文件视图(Source View),快照视图(Snapshot View)和库视图(Library View)。

其中源文件视图比较常用,显示了源文件的层次关系。

快照是当前工程的备份,设计人员可以随时备份,也可以将当前工程随时恢复到某个备份状态。

快照视图用于查看当前工程的快照。

执行快照功能的方法是选择菜单项Project | Take Snapshot。

库视图则显示了工程中用户产生的库的内容。

源文件编辑区:源文件编辑区提供了源代码的编辑功能。

过程管理区:本窗口显示的内容取决于工程管理区中所选定的文件。

相关操作和FPGA设计流程紧密相关,包括设计输入、综合、仿真、实现和生成配置文件等。

对某个文件进行了相应的处理后,在处理步骤的前面会出现一个图标来表示该步骤的状态。

信息显示区:显示ISE中的处理信息,如操作步骤信息、警告信息和错误信息等。

信息显示区的下脚有两个标签,分别对应控制台信息区(Console)和文件查找区(Find in Files)。

如果设计出现了警告和错误,双击信息显示区的警告和错误标志,就能自动切换到源代码出错的地方。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

实验一简单组合逻辑电路的设计一实验要求1.用verilog HDL语言描写出简单的一位数据比较器及其测试程序;2.用测试程序对比较器进行波形仿真测试;画出仿真波形;3. 总结实验步骤和实验结果。

二实验原理与内容这是一个可综合的数据比较器,很容易看出它的功能是比较数据a与数据b,如果两个数据相同,则给出结果1,否则给出结果0。

在Verilog HDL中,描述组合逻辑时常使用assign结构。

注意equal=(a==b)?1:0,这是一种在组合逻辑实现分支判断时常使用的格式。

模块源代码://--------------- compare.v -----------------module compare(equal,a,b);input a,b;output equal;assign equal=(a==b)?1:0; //a等于b时,equal输出为1;a不等于b时,//equal输出为0。

endmodule测试模块用于检测模块设计得正确与否,它给出模块的输入信号,观察模块的内部信号和输出信号,如果发现结果与预期的有所偏差,则要对设计模块进行修改。

测试模块源代码:`timescale 1ns/1ns //定义时间单位。

module comparetest;reg a,b;wire equal;initial //initial常用于仿真时信号的给出。

begina=0;b=0;#100 a=0; b=1;#100 a=1; b=1;#100 a=1; b=0;#100 $stop; //系统任务,暂停仿真以便观察仿真波形。

endcompare compare1(.equal(equal),.a(a),.b(b)); //调用模块。

endmodule实验二 简单时序逻辑电路的设计一 实验要求1.用verilog HDL 语言描写出简单的二分之一分频器及其测试程序;2.用测试程序对分频器进行波形仿真测试;画出仿真波形;3.总结实验步骤和实验结果。

二 实验原理与内容在Verilog HDL 中,相对于组合逻辑电路,时序逻辑电路也有规定的表述方式。

在可综合的Verilog HDL 模型,我们通常使用always 块和 @(posedge clk)或 @(negedge clk)的结构来表述modelsim6.0使用教程1.modelsim简介Modelsim仿真工具是Model公司开发的。

它支持Verilog、VHDL以及他们的混合仿真,它可以将整个程序分步执行,使设计者直接看到他的程序下一步要执行的语句,而且在程序执行的任何步骤任何时刻都可以查看任意变量的当前值,可以在Dataflow窗口查看某一单元或模块的输入输出的连续变化等,比quartus自带的仿真器功能强大的多,是目前业界最通用的仿真器之一。

对于初学者,modelsim自带的教程是一个很好的选择,在Help->SE PDF Documentation->Tutorial里面.它从简单到复杂、从低级到高级详细地讲述了modelsim的各项功能的使用,简单易懂。

但是它也有缺点,就是它里面所有事例的初期准备工作都已经放在example文件夹里,直接将它们添加到modelsim就可以用,它假设使用者对当前操作的前期准备工作都已经很熟悉,所以初学者往往不知道如何做当前操作的前期准备。

2. 安装3. Modelsim仿真方法Modelsim的仿真分为前仿真和后仿真,下面先具体介绍一下两者的区别。

3.1 前仿真前仿真也称为功能仿真,主旨在于验证电路的功能是否符合设计要求,其特点是不考虑电路门延迟与线延迟,主要是验证电路与理想情况是否一致。

可综合FPGA代码是用RTL级代码语言描述的,其输入为RTL级代码与Testbench.3.2 后仿真后仿真也称为时序仿真或者布局布线后仿真,是指电路已经映射到特定的工艺环境以后,综合考虑电路的路径延迟与门延迟的影响,验证电路能否在一定时序条件下满足设计构想的过程,是否存在时序违规。

其输入文件为从布局布线结果中抽象出来的门级网表、Testbench和扩展名为SDO或SDF的标准时延文件。

SDO或SDF的标准时延文件不仅包含门延迟,还包括实际布线延迟,能较好地反映芯片的实际工作情况。

一般来说后仿真是必选的,检查设计时序与实际的FPGA运行情况是否一致,确保设计的可靠性和稳定性。

3.3 Modelsim仿真的基本步骤Modelsim的仿真主要有以下几个步骤:建立库并映射库到物理目录;编译原代码(包括Testbench;执行仿真。

3.3.1 建立库在执行一个仿真前先建立一个单独的文件夹,后面的操作都在此文件下进行,以防止文件间的误操作。

然后启动Modelsim将当前路径修改到该文件夹下,修改的方法是点File->Change Directory选择刚刚新建的文件夹见下图。

仿真库是存储已编译设计单元的目录,modelsim 中有两类仿真库,一种是工作库,默认的库名为work,另一种是资源库。

Work 库下包含当前工程下所有已经编译过的文件。

所以编译前一定要建一个work 库,而且只能建一个work 库。

资源库存放work 库中已经编译文件所要调用的资源,这样的资源可能有很多,它们被放在不同的资源库内。

例如想要对综合在cyclone 芯片中的设计做后仿真,就需要有一个名为cyclone_ver 的资源库。

映射库用于将已经预编译好的文件所在的目录映射为一个modelsim 可识别的库,库内的文件应该是已经编译过的,在Workspace 窗口内展开该库应该能看见这些文件,如果是没有编译过的文件在库内是看不见的。

建立仿真库的方法有两种。

一种是在用户界面模式下,点File->New->Library出现下面的对话框,选择a new library and a logical mapping to it,在LibraryName 内输入要创建库的名称,然后OK ,即可生成一个已经映射的新库。

另一种 方法是在Transcript 窗口输入以下命令: vlib work /* 库名 */vmap work work/* 映射的逻辑名称 存放的物理路径 */ 如果要删除某库,只需选中该库名,点右键选择Delete 即可。

需要注意的是不要在modelsim 外部的系统盘内手动创建库或者添加文件到库里;也不要modelsim 用到的路径名或文件名中使用汉字,因为modelsim 可能无法识别汉字而导致莫名其妙的错误。

3.3.2 编写与编译测试文件在编写Testbench 之前最好先将要仿真的目标文件编译到工作库中,点Compile->Compile 或需要注意的是不要在modelsim 外部的系统盘内手动创建库或者添加文件到库里;也不要modelsim 用到的路径名或文件名中使用汉字,因为modelsim 可能无法识别汉字而导致莫名其妙的错误。

3.3.2 编写与编译测试文件在编写Testbench 之前最好先将要仿真的目标文件编译到工作库中,点Compile->Compile 或将出现下面的对话框,在Library 中选择工作库,在查找范围内找到要仿真的目标文件,然后点Compile 和Done 。

或在命令行输入vlog fulladder.v 。

此时目标文件已经编译到工作库中,在Library 中展开工作库会发现该文件。

当对要仿真的目标文件进行仿真时需要给文件中的各个输入变量提供激励源,并对输入波形进行的严格定义,这种对激励源定义的文件称为Testbench,即测试台文件。

下面先讲一下Testbench的产生方法。

我们可以在modelsim内直接编写Testbench,而且modelsim还提供了常用的各种模板。

具体步骤如下:⑴.执行File->New->Source->verilog,或者直接点击工具栏上的新建图标,会出现一个verilog 文档编辑页面,在此文档内设计者即可编辑测试台文件。

需要说明的是在Quartus中许多不可综合的语句在此处都可以使用,而且testbench只是一个激励源产生文件,只要对输入波形进行定义以及显示一些必要信息即可,切记不要编的过于复杂,以免喧宾夺主。

⑵.Modelsim提供了很多Testbench模板,我们直接拿过来用可以减少工作量。

点View->Source->Show Language Templates然后会出现一个加载工程,接着你会发现在刚才的文档编辑窗口左边出现了一个Language Templates窗口,见下图。

展开Verilog项,双击Creat Testbench会出现一个创建向导,见下图选择Specify Design Unit工作库下的目标文件,点Next,出现下面对话框可以指定Testbench的名称以及要编译到的库等,此处我们使用默认设置直接点Finish。

这时在Testbench内会出现对目标文件的各个端口的定义还有调用函数接下来,设计者可以自己往Testbench内添加内容了,然后保存为.v格式即可。

按照前面的方法把Testbench文件也编译到工作库中。

3.3.3 执行仿真因为仿真分为前仿真和后仿真,下面分别说明如何操作。

⑴. 前仿真前仿真,相对来说是比较简单的。

在上一步我们已经把需要的文件编译到工作库内了,现在我们只需点simulate->Start Simulation或快捷按钮会出现start simulate对话框。

点击Design标签选择Work库下的Testbench文件,然后点OK即可,也可以直接双击Testbench文件,此时会出现下面的界面。

在主界面中会多出来一个Objects窗口,里面显示Testbench里定义的所有信号引脚,在Workspace里也会多出来一个Sim标签。

右键点击fuladder_tb.v,选择Add->Add to Wave,如下图所示。

然后将出现Wave窗口,现在就可以仿真了,见下图。

窗口里面已经出现了待仿真的各个信号,点将开始执行仿真到100ns,继续点仿真波形也将继续延伸,见下图.若点,则仿真一直执行,直到点才停止仿真。

也可以在命令行输入命令:run @1000则执行仿真到1000ns,后面的1000也可以是别的数值,设计者可以修改。

在下一次运行次命令时将接着当前的波形继续往后仿真。

对于复杂的设计文件,最好是自己编写testbench文件,这样可以精确定义各信号以及各个信号之间的依赖关系等,提高仿真效率。

对于一些简单的设计文件,也可以在波形窗口自己创建输入波形进行仿真。

具体方法是双击work库里的目标仿真文件fulladder.v,然后点workspace窗口中出现的sim标签,右键点击fuladder,选择Add->Add to Wave,如下图所示。

相关文档
最新文档