数电课件verilog_intr
- 格式:pdf
- 大小:262.67 KB
- 文档页数:155
6-3Vrilog HDL语言简介硬件描述语言HDL是EDA技术中的重要组成部分,常用的硬件描述语言有Verilog HDL 、VHDL、System Verilog、System C、ABEL HDL和AHDL等,而Verilog HDL和VHDL是当前最流行的并成为IEEE标准的硬件描述语言。
3.1 HDL简介VHDL是超高速集成电路硬件描述语言(Very-High-Speed Integrated Circuit Hardware Description Language)的缩写。
VHDL作为IEEE标准的硬件描述语言和EDA的重要组成部分,经过十几年的发展、应用和完善,以其强大的系统描述能力、规范的程序设计结构、灵活的语言表达风格和多层次的仿真测试手段,在电子设计领域受到了普遍的认同和广泛的接受,成为现代EDA领域的重要的硬件设计语言。
HDL的特点1、HDL具有强大的功能,覆盖面广,描述能力强。
HDL支持门级电路的描述,也支持寄存器传输级电路的描述,还支持以行为算法描述为对象的电路的描述。
2、HDL有良好的可读性。
它可以被计算机接受,也容易被读者理解。
用HDL书写的源文件,既是程序又是文档,既是工程技术人员之间交换信息的文件,又可作为合同签约者之间的文件。
3、HDL具有良好的可移植性。
作为一种已被IEEE承认的工业标准,HDL事实上已成为通用的硬件描述语言,可以在各种不同的设计环境和系统平台中使用。
4、使用HDL可以延长设计的生命周期。
用HDL描述的硬件电路与工艺无关,不会因工艺而过时。
与工艺有关的参数可以通过HDL提供的属性加以描述,工艺改变时,只需要修改相应程序中属性参数即可。
5、HDL支持对大规模设计的分解和已有设计的再利用。
HDL可以描述复杂的电路系统,支持对大规模设计的分解,由多人、多项目组来共同承担和完成。
标准化的规则和风格,为设计的再利用提供了有力的支持。
6、HDL有利于保护知识产权。
第2章 Verilog HDL基础知识2.1 Verilog HDL的语言要素2.2 数据类型2.3 运算符2.4 模块本章小结12 Verilog HDL 语法来源于C 语言基本语法,其基本词法约定与C 语言类似。
程序的语言要素也称为词法,是由符号、数据类型、运算符和表达式构成的,其中符号包括空白符、注释符、标识符和转义标识符、关键字、数值等。
2.1 Verilog HDL 的语言要素2.1.1 空白符 空白符包括空格符(\b)、制表符(\t)、换行符和换页符。
空白符使代码看起来结构清晰,阅读起来更方便。
在编译和综合时,空白符被忽略。
Verilog HDL程序可以不分行,也可以加入空白符采用多行编写。
3 例2.1-1空白符使用示例。
initial begin a = 3'b100; b = 3'b010; end 相当于: initial begin a = 3'b100; b = 3'b010; end452.1.2 注释符 Verilog HDL语言中允许插入注释,标明程序代码功能、修改、版本等信息,以增强程序的可阅读性和帮助管理文档。
Verilog HDL中有两种形式的注释。
(1) 单行注释:单行注释以“//”开始,Verilog HDL忽略从此处到行尾的内容。
(2) 多行注释:多行注释以“/*”开始,到“*/”结束,Verilog HDL忽略其中的注释内容。
需要注意的是,多行注释不允许嵌套,但是单行注释可以嵌套在多行注释中。
例2.1-2 注释符使用示例。
单行注释: assign a=b & c; //单行注释 多行注释: assign a[3:0]=b[3:0]&c[3:0;]; /*注释行1 注释行2 */ 非法多行注释:/*注释内容 /*多行注释嵌套多行注释*/ 注释内容*/ 合法多行注释:/*注释内容 //多行注释嵌套单行注释*/672.1.3 标识符和转义标识符 在Verilog HDL中,标识符(Identifier)被用来命名信号名、模块名、参数名等,它可以是任意一组字母、数字、$符号和_(下划线)符号的组合。
Introduction to Verilog Course Objectivesn Learn the basic constructs of Verilogn Learn the modeling structure of Verilogn Learn the concept of delays and their effects in simulationCourse Outlinen Verilog Overviewn Basic Structure of a Verilog Model n Components of a Verilog Module –Ports–Data Types–Assigning Values and Numbers–Operators–Behavioral Modeling•Continuous Assignments•Procedural Blocks–Structural Modelingn Summary: Verilog Environment VerilogOverview What is Verilog?n IEEE industry standard Hardware Description Language(HDL) - used to describe a digital system n For both Simulation & SynthesisVerilog Historyn Introduced in 1984 by Gateway Design Automation n1989 Cadence purchased Gateway (Verilog-XL simulator)n1990 Cadence released Verilog to the publicn O pen V erilog I nternational (OVI) was formed to control the language specifications.n1993 OVI released version 2.0n1993 IEEE accepted OVI Verilog as a standard, Verilog 1364Verilog Structuren Verilog HDL : Consists of Keywords, syntax and semantics used to describe hardware functionalityand timing.n PLI : P rogramming L anguage I nterface provides C language routines used to interact between Verilog and EDA tools. (Simulators,Waveform displays) n SDF : S tandard D elay F ormat - a file used to back-annotate accurate timing information to simulatorsand other tools.Terminologyn HDL - Hardware Description Language is a software programming language that is used to model a piece of hardwaren Behavior Modeling - A component is described by its input/output responsen Structural Modeling - A component is described by interconnecting lower-level components/primitives Behavior Modelinginput 1, .., input n output 1, .., output nif (input 1)for (j=0, j<8, j=j+2)#5 output 1 = 1’b0;elsefor (j=1, j<8, j=j+2)#5 output 1 = 1’b1;n Only the functionality of the circuit, no structure n No specific hardware intentn For the purpose of synthesis, as well as simulationMore Terminologyn Register Transfer Level (RTL) - A type of behavioral modeling, for the purpose of synthesis.–Hardware is implied or inferred–Synthesizablen Synthesis - Translating HDL to a circuit and then optimizing the represented circuitn RTL Synthesis - The process of translating a RTL model of hardware into an optimized technologyspecific gate level implementationn Verilog–“Tell me how your circuit should behave and I will give you the hardware that does the job.”n VHDL–Similar to Verilogn ABEL, PALASM, AHDL–“Tell me what hardware you want and I will give it to you”n Verilog–“Give me a circuit whose output only changes when there isa low-to-high transition on a particular input. When thetransition happens, make the output equal to the input untilthe next transition.”–Result: Verilog Synthesis provides a positive edge-triggered flipflopn ABEL, PALASM, AHDL–“Give me a D-type flipflop.”–Result: ABEL, PALASM, AHDL synthesis provides a D-type flipflop. The sense of the clock depends on the synthesistool.VerilogModeling module Module_name (Port_list)Port declarations (if ports are present)Parameters (optional)Data type declarationsContinuous Assignments (assign)Procedural Blocks (initial and always)- behavioral statementsInstantiation of lower-level modulesTasks and FunctionsTiming SpecificationsendmoduleSchematic Representation - MACPortsn Port List:– A listing of the port names–Example:module mult_acc (out, ina, inb, clk, clr);n Port Types:–input--> input port–output--> output port–inout--> bidirectional portn Port Declarations:–<port_type><port_name>;–Example:input [7:0] ina, inb;input clk, clr;output [15:0] out;n wire--> represents a noden tri--> represents a tri-state noden Bus Declarations:–<data_type> [MSB : LSB ] <signal name> ;–<data_type> [LSB : MSB] <signal name> ;n Examples:–wire<signal name> ;–wire [15:0] mult_out, adder_out;n reg- unsigned variable of any bit sizen integer- signed variable (usually 32 bits)n Bus Declarations:–<data_type> [MSB : LSB ] <signal name> ;–<data_type> [LSB : MSB] <signal name> ;n Examples:–reg<signal name> ;–reg [7 : 0] out ;Data Typen Every signal (which includes ports) must have a data type–Signals must be explicitly declared in the data typedeclarations of your module–Ports are, by default, wire net data types if theyare not explicitly declaredAssigning Values - NumbersandOperatorsAssigning Values - Numbersn Are sized or unsized: <size>‘<base format><number>–Sized example: 3’b010 = 3-bit wide binary number•The prefix (3) indicates the size of number–Unsized example: 123 = 32-bit wide decimal number by default •Defaults–No specified <base format> defaults to decimal–No specified <size> defaults to 32-bit wide number n Base Format:–Decimal (‘d or ‘D) 16’d255 = 16-bit wide decimal number–Hexadecimal (‘h or ‘H) 8’h9a = 8-bit wide hexadecimal number–Binary (‘b or ‘B) ’b1010 = 32-bit wide binary numer–Octal (‘o or ‘O) ‘o21 = 32-bit wide octal numbern Negative numbers - specified by putting a minus sign before the <size>–Legal: -8’d3 = 8-bit negative number stored as 2’s complement of 3–Illegal: 4’d-2 = ERROR!!n Special Number Characters:–‘_’ (underscore): used for readability•Example: 32’h21_65_bc_fe = 32-bit hexadecimal number –‘x’ or ‘X’ (unknown value)•Example: 12’h12x = 12-bit hexadecimal number; LSBs unknown –‘z’ or ‘Z’ (high impedance value)•Example: 1’b z = 1-bit high impedance numbern Extended–If MSB is 0, x, or z, number is extended to fill MSBs with 0, x,or z, respectively•Examples: 3’b01 = 3’b001, 3’bx1 = 3’bxx1, 3’bz = 3’bzzz –If MSB is 1, number is extended to fill MSBs with 0•Example: 3’b1 = 3’b001Short Quizn Short Quiz:–Q: What is the actual value for 4’d017 in binary? Answersn Short Quiz:–Q: What is the actual value for 4’d017 in binary?–A: 4’b0001, MSB is truncated (10001)Operator Precedencen Operators default precedence+ , - , ! , ~ (unary)Highest Priority+ , - (Binary)<< , >>< , > , <= , >=== , !=&^ , ^~ or ~^|&&||?: (ternary)Lowest Priority n( ) can be used to override default。