数字逻辑设计及应用教学课件:5-1 verilog HDL-CHENYU_第1页
数字逻辑设计及应用教学课件:5-1 verilog HDL-CHENYU_第2页
数字逻辑设计及应用教学课件:5-1 verilog HDL-CHENYU_第3页
数字逻辑设计及应用教学课件:5-1 verilog HDL-CHENYU_第4页
数字逻辑设计及应用教学课件:5-1 verilog HDL-CHENYU_第5页
已阅读5页,还剩57页未读 继续免费阅读

下载本文档

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

文档简介

1、Chapter 5 Hardware Description Language Verilog HDL structure Signal and operations Structure description Behavioral decriptionAbout the HDL?What is the HDL?Hardware Description Language Sofe Core Hard CoreWhy we used the HDL?Verilog HDLIEEE std1364-2001Verilog HDL and C LanguaueVerilog HDL and VHDL

2、Verilog HDL structureHardware module: Name、port and structure;Verilog HDL structuremodule majority (a,b,c,f);input a,b,c;output f;structure description;endmodule;Verilog HDL structuremodule inhibit (a,b,s);input 3.0 a,b;output 8.0 s;structure description;endmoduleSignal and operationsTwo kinds of si

3、gnal : port : input and output; wire : any connect nets in module;The value of signals: 0 1 z (高阻) x(未知)Verilog HDL structuremodule majority (a,b,c,f);input a,b,c;output f;wire w1,w2,w3;structure description;endmodule;Logic operators for bit data:y = a & b;y = a | b;y = a;y = a b;Signal and operatio

4、nsOperators for bus datas:y = a & b;y = a | b;y = ! a;y = a + b;y = a - b;y = a * b;Signal and operationsVerilog HDL structuremodule majority (a,b,c,f);input a,b,c;output f;wire w1,w2,w3;assign w1=a&b;assign w2=b&c;assign w3=a&c;assign f=w1|w2|w3;endmoduleVerilog HDL structuremodule majority (a,b,c,

5、f);input a,b,c;output f;assign f=(a&b)|(b&c)|(a&c);endmoduleUse built_in gates for designVerilog HDL structuremodule majority (a,b,c,f);input a,b,c;output f;wire w1,w2,w3;and u1(w1,a,b);and u2(w2,b,c);and u3(w3,a,c);or u4(f,w1,w2,w3); endmoduleexamplem o d u l e m o d u l e _ n a m e (p o r t _ l i

6、s t) ;D e c l a r a t i o n s :reg, wire, parameter,input, output, inout,function, task, . . .S t a t e m e n t s :Initial statementAlways statementModule instantiationGate instantiationUDP instantiationContinuous assignmente n d m o d u l eHalf Adderm o d u l e H a l f A d d e r (A, B, Sum, Carry)

7、; i n p u t A, B; o u t p u t Sum, Carry; a s s i g n #2 Sum = A B; a s s i g n #5 Carry = A & B;e n d m o d u l e模块的名字是H a l f A d d e r。模块有4个端口: 两个输入端口A和B,两个输出端口S u m和C a rry。由于没有定义端口的位数, 所有端口大小都为1位;同时, 由于没有各端口的数据类型说明, 这四个端口都是线网数据类型。模块包含两条描述半加器数据流行为的连续赋值语句。从这种意义上讲,这些语句在模块中出现的顺序无关紧要,这些语句是并发的。每条语句的执

8、行顺序依赖于发生在变量A和B上的事件。Half Adderm o d u l e H a l f A d d e r (A, B, Sum, Carry) ; i n p u t A, B; o u t p u t Sum, Carry; a s s i g n #2 Sum = A B; a s s i g n #5 Carry = A & B;e n d m o d u l e# 2指2个时间单位。使用编译指令将时间单位与物理时间相关联。这样的编译器指令需在模块描述前定义,如下所示: timescale 1ns /100ps,此语句说明时延时间单位为1 n s并且时间精度为100ps (时

9、间精度是指所有的时延必须被限定在0 . 1 n s内)。如果此编译器指令所在的模块包含上面的连续赋值语句, #2 代表2 n s。时延举例 t i m e s c a l e 1ns/ 1nsm o d u l e D e c o d e r 2 x 4 (A, B, EN, Z) ; i n p u t A, B, EN; o u t p u t 0 :3 Z; wire Abar, Bbar; assign #1 Abar = A; / 语/ 句1。 assign #1 Bbar = B; / 语/ 句2。 assign #2 Z0 = (Abar & Bbar & EN ) ; / /

10、语句3。 assign #2 Z1 = (Abar & B & EN) ; / / 语句4。 assign #2 Z2 = (A & Bbar & EN) ; / / 语句5。 assign #2 Z3 = ( A & B & EN) ; / / 语句6。e n d m o d u l e以反引号“ ”开始的第一条语句是编译器指令, 编译器指令 t i m e s c a l e 将模块中所有时延的单位设置为1 n s,时间精度为1 ns。例如,在连续赋值语句中时延值# 1和# 2分别对应时延1 ns 和2 ns。Verilog HDL设计的行为功能使用下述过程语句结构描述:1) initia

11、l语句:此语句只执行一次。2) always语句:此语句总是循环执行, 或者说此语句重复执行。initial语句 t i m e s c a l e 1ns / 1nsm o d u l e Test (Pop, Pid) ; o u t p u t Pop, Pid; r e g Pop, Pid; i n i t i a l b e g i n P o p = 0; / 语句1。 P i d = 0; / 语句2。 P o p = #5 1; / 语句3。 P i d = #3 1; / 语句4。 Pop = #6 0; / 语句5。 P i d = #2 0; / 语句6。 e n de

12、 n d m o d u l ei n i t i a l语句包含一个顺序过程。这一顺序过程在0 ns时开始执行,并且在顺序过程中所有语句全部执行完毕后, initial语句永远挂起。这一顺序过程包含带有定义语句内时延的分组过程赋值的实例。语句1和2在0 ns时执行。第三条语句也在0时刻执行,导致P o p 在第5 ns时被赋值。语句4在第5 ns 执行,并且P i d 在第8 ns被赋值。同样,P o p在14 ns被赋值0,P i d在第16 ns被赋值0。第6条语句执行后, i n i t i a l语句永远被挂起。2) always语句a l w a y s ( A o r B o r

13、 C i n ) b e g i n Sum = (A B) Cin ; T1 = A & Cin; T2 = B & Cin; T3 = A & B; C o u t = (T 1| T 2) | T 3;e n dalways 语句中有一个与事件控制(紧跟在字符 后面的表达式)。相关联的顺序过程( b e g i n - e n d对)。这意味着只要A、B或C i n 上发生事件,即A、B或C i n之一的值发生变化,顺序过程就执行。在顺序过程中的语句顺序执行,并且在顺序过程执行结束后被挂起。顺序过程执行完成后,always 语句再次等待A、B或C i n上发生的事件。To realize

14、 it in Quartus What is quartus Nothing is more important than practice!Build your first project!Any way, programs must belong to a project. A project include one or more verilog HDL files and other files,such as waveform file to simulate and diagram? files which also work as verilog files. The first

15、 practice1.Open quartus 2.Create a new project with project WIZARD3.Create our first verilog file4.Edit it5.Build it6.Create our first waveform fileThe first practice7.config the waveform file8.simulate our work9.view the conclusion10.How to write your code into FPGATipBy this way,You can write a CP

16、U in FPGA!Its Nothing but digital circuit!A door to hardware engineer opened!Congradulations!After your first projectYou can use Quartus to practice what you learn!If you try every example in our book, you can master digital logic and will be a good engineer!Lets go on to learn basic knowledge of ve

17、rilog!Assign连续赋值语句将值赋给线网(连续赋值不能为寄存器赋值),它的格式如下(简单形式):a s s i g n LHS_target = RHS_expressio;n例如,w i r e 3:0 Z, Preset, Clear; /线网说明 a s s i g n Z = Preset & Clear; /连续赋值语句连续赋值的目标为Z,表达式右端为“ Preset & Clear”。注意连续赋值语句中的关键词a s s i g n。连续赋值语句在什么时候执行呢? 只要在右端表达式的操作数上有事件(事件为值的变化)发生时,表达式即被计算;如果结果值有变化,新结果就赋给左边的

18、线网。在上面的例子中,如果P re s e t或C l e a r变化,就计算右边的整个表达式。如果结果变化,那么结果即赋值到线网Z。Conditional operators :Verilog HDL中的操作符可以分为下述类型:1) 算术操作符2) 关系操作符3) 相等操作符4) 逻辑操作符5) 按位操作符6) 归约操作符7) 移位操作符8) 条件操作符9) 连接和复制操作符Conditional operators :8) 条件操作符除条件操作符从右向左关联外,其余所有操作符自左向右关联。下面的表达式:A + B - C 等价于: (A + B ) - C / /自左向右而表达式:A ?

19、B : C ? D : F等价于: A ? B : (C ? D : F) /从右向左圆扩号能够用于改变优先级的顺序,如以下表达式: (A ? B : C) ? D : FConditional operators :8) 条件操作符条件操作符根据条件表达式的值选择表达式,形式如下:c o n d_e x p r ? e x p r 1 : e x p r 2如果c o n d _ e x p r 为真(即值为1 ),选择e x p r 1;如果c o n d _ e x p r为假(值为0 ),选择e x p r 2。如 果c o n d _ e x p r 为x或z,结果将是按以下逻辑e

20、x p r 1和e x p r 2按位操作的值: 0与0得0,1与1得1, 其余情况为x。Conditional operators :a = ba != ba ba = ba ba = bassign y = (s ? a:b);assign y = (s=1 ? a|b:a&b);conditional operations and comparatorsFull adder module fa (x,y,cin,s,cout);input x,y,cin;output s,cout;assign s = (xy)cin;assign cout=(x&y)|(x&cin)|(y&cin);endmodulemodule fa (x,y,cin,s,cout);input x,y,cin;output s,cout;wire p,g;assign p=xy;assign g=x&y;assign s = pcin;assign cout=g|(p&cin);endmoduleFull adder Full addermodule adder_4(a,b,ci,sum,co);input 3:0a,b;input ci;output3:0sum;output co;assign co,sum=a+b+ci;endmodul

温馨提示

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

评论

0/150

提交评论