1 / 17

第五章 Verilog HDL

第五章 Verilog HDL. § 5.1 引言.

base
Download Presentation

第五章 Verilog HDL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第五章 Verilog HDL § 5.1 引言 Verilog HDL语言最初始于1983年由Getway Design Automation公司为其模拟器产品开发的硬件建模语言。那时他只是一种专用语言。由于他们的模拟、仿真器产品的广泛使用,Verilog HDL作为一种便于使用而且使用的语言逐渐为众多设计者所接受。在一次努力增加语言普及性活动中,Verilog HDL语言于1990年被推向公众领域。Open Verilog International (OVI)是促进Verilog发展的国际性组织。1992年,OVI决定致力于推广Verilog标准成为IEEE标准。这一努力最后获得成功,Verilog语言于1995年成为IEEE标准,称为IEEE Std 1364—1995。完整的标准Verilog硬件描述语言参数手册中有详细描述。

  2. § 5.2 Verilog HDL基本结构 Verilog HDL程序是由模块构成的。每个模块的内容都是嵌在module和endmodule两个语句之间。 Verilog HDL的基本设计单元是“模块(block)”。一个模块是由两部分组成的,一部分描述接口;另一部分描述逻辑功能,即定义输入是如何影响输出的。 如: module模块名称 (端口变量1,端口变量2,…); 模块内容 endmodule

  3. 例:8位计数器 modulecounter8 (out,cout,data,load,cin,clk); //模块名 output[7:0] out; //输出端口说明 output cout; //输入端口说明 input[7:0] data; //输入端口说明 input load,cin,clk; //输入端口说明 reg[7:0] out; //变量类型说明 always @(posedge clk) begin if(load) out=data; else out=ou+cin; 逻辑功能定义 endassign cout=&out&cin; endmodule //模块描述结束

  4. 在模块描述中,可以用下述方式进行 逻辑功能定义: 1、数据流描述方式 使用“assign”语句,如:assign cout=&out&cin;   2、行为描述方式 用“always”或“initial”块语句。 3、结构描述方式 使用元件例化(instantiate),如:and A1(f,a,b); 4、上述描述方式的混合

  5. module Decoder2_4 (A,B,En,Z); input A,B,En; output[3:0] Z; wire Abar,Bbar; assign #1 Abar=~A; assign #1 Bbar=~b; assign #2 Z[0]=~(Abar & Bbar & En); assign #2 Z[1]=~(Abar & B & En); assign #2 Z[2]=~(A & Bbar & En); assign #2 Z[3]=~(A & B & En); endmodule

  6. module Fulladder (A,B,Cin,Sum,Cout); input A,B,Cin; output Sum,Cout; reg Sum,Cout; always @(A or B or Cin) begin Sum=A^B^Cin; Cout=Cin & (A | B)|(A & B); end endmodule

  7. module Fulladder (A,B,Cin,Sum,Cout); input A,B,Cin; output Sum,Cout; wire S1,T1,T2,T3; xor X1(S1,A,B), X2(Sum,S1,Cin); and A1(T1,A,B), A2(T2,B,Cin), A3(T3,A,Cin);

  8. or O1(Cout,T1,T2,T3); endmodule

  9. § 5.3 数据类型及常量、变量 Verilog HDL中共有19种数据类型。数据类型是用来表示数字电路中的数据存储和传送单元的。我们仅介绍最基本的3种数据类型,它们是parameter型、reg型和wire型。 一、常量 1、数字 基数表示法 格式: +/- <位宽>’<基数><数值>

  10. 位宽:定义以二进制计算的常量的位长。 基数:即进制,b或B(二进制),o或O(八进制),d或D (十进制),h或H(十六进制)。 系统默认为十进制。 数值:要表示的具体数字。(十六进制中,A-F不区分大小写) 注:十进制数可以缺省位宽和基数,如:197,0。 如: 3’b001, 4’d2,12’h01f 。 x 和 z 值 x表示不定值,z表示高阻值。每个字符代表的为宽取决于所用的进制。 如: 8'b1001xxxx,8'h7x。

  11. 注意: (1)“_”增加可读性,没有实际意义。 如: 8’b0111_1100=8’b01111100 (2)问号“?”是高阻态的一种表示。 如:16’ha7?3=16’ha7z3 (3)数值中左边为最高位,右边为最低位。 (4)位宽 < 数值位数时,高位舍去。 如:6’hf3 = 6’h11_0011 8’hf3 = 8’h1111_0011

  12. (5)位宽 > 数值位数,高位补0(Z,X补相应的Z,X)。 如:6’hf = 6’b00_1111 6’hx = 6’bxx_xxxx (6)+/- 在最前面(左边)。 (7)位宽与基数、基数与数值、数值与数值之间可以 空格。 (8)位宽不允许为表达式

  13. 2、parameter常量 Verilog HDL中,用parameter来定义常量,即用parameter来定义一个标识符,代表一个常量,称为符号常量。 格式如下: parameter 参数名1=表达式,参数名2=表达式……; 如:parameter sel=8,code=8’ha3; 二、变量 变量是在程序运行过程中其值可以改变的量。变量分为两种:网络型(nets type)、寄存器型( register type)。

  14. 1、nets型变量 nets型变量指输出始终根据输入的变化而更新其值的变量,它一般指的是硬件电路中各种物理连接。 Verilog HDL中,nets类型的变量有多种:wire、tri、wor、trior、wand、triand、tri1、tri0、supply1、supply0。我们这里只介绍wire型变量。 格式如下: wire [MSB:LSB] 变量1,变量2……; wire型变量常用来表示以assign语句赋值的组合逻辑信号。模块中的输入\输出信号类型缺省时自动定义为wire型。

  15. 2、register型变量 register型变量对应得是具有状态保持作用的电路元件,如触发器、寄存器等。Register型最大的特点是,register型变量需要被明确赋值,并且在被重新赋值前一直保持原值。设计者必须把register型变量放在过程块语句中(如:always、initial)。在VerilogHDL中,有四种寄存器型变量:reg型、integer型、real型、time型。我们介绍常用的reg型。 格式如下: reg [MSB:LSB] 变量1,变量2……;

  16. 3、数组 若干个相同宽度的向量构成数组。 如: reg[7:0] mymem[1023:0]; 这里定义了一个1024个字节、每个字节宽度为8位的存储器。通常定义格式为: parameter wordwidth=8,memsize=1024; reg[wordwidth-1:0] mymem[memsize-1:0];

More Related