Digital System Design Introduction to Verilog ® HDL Maziar Goudarzi.

Slides:



Advertisements
Similar presentations
Verilog HDL -Introduction
Advertisements

Simulation executable (simv)
Verilog Overview. University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
Verilog Intro: Part 1.
Hardware Description Language (HDL)
SYEN 3330 Digital SystemsJung H. Kim Chapter SYEN 3330 Digital Systems Chapters 4 – Part3: Verilog – Part 1.
CSE 201 Computer Logic Design * * * * * * * Verilog Modeling
Logic Values 0:logic 0 / false 1:logic 1 / true X:unknown logic value Z:high-impedance.
CSE 341 Verilog HDL An Introduction. Hardware Specification Languages Verilog  Similar syntax to C  Commonly used in  Industry (USA & Japan) VHDL 
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
Verilog-HDL Reference: Verilog HDL: a guide to digital design and synthesis, Palnitkar, Samir Some of slides in this lecture are supported by Prof. An-Yeu.
Logic Values 0:logic 0 / false 1:logic 1 / true X:unknown logic value Z:high-impedance.
CSE241 R1 Verilog.1Kahng & Cichy, UCSD ©2003 CSE241 VLSI Digital Circuits Winter 2003 Recitation 1: Verilog Introduction.
Reconfigurable Computing (EN2911X, Fall07) Lecture 05: Verilog (1/3) Prof. Sherief Reda Division of Engineering, Brown University
Digital System Design Verilog ® HDL Modules and Ports Maziar Goudarzi.
Digital System Design Verilog ® HDL Maziar Goudarzi.
Digital System Design Verilog ® HDL Tasks and Functions Maziar Goudarzi.
University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
Hardware Description Language(HDL). Verilog simulator was first used beginning in 1985 and was extended substantially through The implementation.
Chap. 2 Hierarchical Modeling Concepts. 2 Hierarchical Modeling Concepts Design Methodologies 4-bit Ripple Carry Counter Modules Instances Components.
Chap. 3 Basic Concepts. 2 Basic Concepts Lexical Conventions Data Types System Tasks and Compiler Directives Summary.
Digital System Design Verilog ® HDL Basic Concepts Maziar Goudarzi.
Programmable Logic Architecture Verilog HDL FPGA Design Jason Tseng Week 2-3.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
1 VERILOG Fundamentals Workshop סמסטר א ' תשע " ה מרצה : משה דורון הפקולטה להנדסה Workshop Objectives: Gain basic understanding of the essential concepts.
ECE 2372 Modern Digital System Design
Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 2: Introduction to Verilog Syntax Spring.
Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 2: Introduction.
Workshop Topics - Outline
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
Verilog Language Concepts
ECE 551 Digital System Design & Synthesis Fall 2011 Midterm Exam Overview.
CS 3850 Lecture 3 The Verilog Language. 3.1 Lexical Conventions The lexical conventions are close to the programming language C++. Comments are designated.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
Module 1.2 Verilog Simulator.  A Verilog program for a particular application consists of two blocks : ◦ Design Block (Module) ◦ Testing Block (Stimulus.
CH71 Chapter 7 Hardware Description Language (HDL) By Taweesak Reungpeerakul.
Module 1.3 Verilog Basics UNIT 1 : Introduction to Verilog Data Types.
Digital System Design Verilog ® HDL Parameters, and Generate Blocks Maziar Goudarzi.
3/4/20031 ECE 551: Digital System Design * & Synthesis Lecture Set 3 3.1: Verilog - User-Defined Primitives (UDPs) (In separate file) 3.2: Verilog – Operators,
1 Hardware description languages: introduction intellectual property (IP) introduction to VHDL and Verilog entities and architectural bodies behavioral,
1 Verilog Digital System Design Z. Navabi, 2006 Verilog Language Concepts.
Digital System Design Verilog ® HDL Design at Structural Level Maziar Goudarzi.
ELEE 4303 Digital II Introduction to Verilog. ELEE 4303 Digital II Learning Objectives Get familiar with background of HDLs Basic concepts of Verilog.
Sharif University of Technology Department of Computer Engineering Verilog ® HDL Basic Concepts Alireza Ejlali.
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Logic Design Dr. Oliver Faust.
Chapter 3: Dataflow Modeling Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 3-1 Chapter 3: Dataflow Modeling.
Chapter1: Introduction Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 1-1 Chapter 1: Introduction Prof. Ming-Bo.
Verilog Intro: Part 1. Hardware Description Languages A Hardware Description Language (HDL) is a language used to describe a digital system, for example,
1 University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
Verilog-HDL Reference: Verilog HDL: a guide to digital design and synthesis, Palnitkar, Samir Some of slides in this lecture are supported by Prof. An-Yeu.
Sharif University of Technology Department of Computer Engineering Digital System Design Verilog ® HDL Basic Concepts Digital System Design Verilog ® HDL.
Structural Description
Verilog-HDL Reference: Verilog HDL: a guide to digital design and synthesis, Palnitkar, Samir Some of slides in this lecture are supported by Prof. An-Yeu.
Publisher: Prentice Hall PTR Pub Date: February 21, 2003 ISBN:
Discussion 2: More to discuss
Hardware Description Languages
Introduction to DIGITAL CIRCUITS MODELING & VERIFICATION using VERILOG [Part-I]
Behavioral Modeling in Verilog
Chapter 3: Dataflow Modeling
Logic Values 0:logic 0 / false 1:logic 1 / true X:unknown logic value
Introduction to Verilog® HDL
Logic Values 0:logic 0 / false 1:logic 1 / true X:unknown logic value
Introduction to Digital System and Microprocessor Design
Logic Values 0:logic 0 / false 1:logic 1 / true X:unknown logic value
Verilog-HDL Reference: Verilog HDL: a guide to digital design and synthesis, Palnitkar, Samir Some of slides in this lecture are supported by Prof. An-Yeu.
CS 153 Logic Design Lab Professor Ian G. Harris
Introduction to Verilog® HDL
Reconfigurable Computing (EN2911X, Fall07)
Presentation transcript:

Digital System Design Introduction to Verilog ® HDL Maziar Goudarzi

Today program Hello World! Hierarchical Modeling Concepts 2010DSD2

Verilog® HDL Hello World!

Basics of Digital Design Using HDLs 2010DSD4 Circuit Under Design (CUD) 8 4 Generating inputs to CUD Checking outputs of CUD Test bench Stimulus block

Typical Design Flow for Digital Systems 2010DSD5

ModelSim ® Simulation Environment You’ll see later today 2010DSD6

Verilog Basic Building Block: Module module not_gate(in, out); // module name+ports // comments: declaring port type input in; output out; // Defining circuit functionality assign out = ~in; endmodule 2010DSD7

useless Verilog Example module useless; initial $display(“Hello World!”); endmodule Note the message-display statement – Compare to printf() in C 2010DSD8

Hierarchical Modeling Concepts Verilog® HDL

Design Methodologies 2010DSD10

4-bit Ripple Carry Counter 2010DSD11

T-flipflop and the Hierarchy 2010DSD12

Modules module ( ); endmodule Example: module T_ff(q, clock, reset); endmodule 2010DSD13

Modules (cont’d) Verilog levels of abstraction – Behavioral (algorithmic) level Describe the algorithm used (almost) C programming – Dataflow level Flow of data among registers and their processing – Gate level Interconnect logic gates – Switch level Interconnect transistors (MOS transistors) Register-Transfer Level (RTL) – Behavioral + dataflow synthesizable by EDA tools 2010DSD14 Behavioral Data flow Structural problem Switch

Module Instances (cont’d) 2010DSD15 // module DFF with asynchronous reset module DFF(q, d, clk, reset); output q; input d, clk, reset; reg q; reset or negedge clk) if (reset) q = 1'b0; else q = d; endmodule D Flip-Flop

Module Instances (cont’d) module TFF(q, clk, reset); output q; input clk, reset; wire d; DFF dff0(q, d, clk, reset); not n1(d, q); // not is a Verilog provided primitive. endmodule 2010DSD16 T Flip-Flop

Module Instances module ripple_carry_counter(q, clk, reset); output [3:0] q; input clk, reset; //4 instances of the module TFF are created. TFF tff0(q[0],clk, reset); TFF tff1(q[1],q[0], reset); TFF tff2(q[2],q[1], reset); TFF tff3(q[3],q[2], reset); endmodule 2010DSD17

Module Instances (cont’d) Illegal instantiation example: – Nested module definition not allowed module definitionmodule instantiation – Note: module definition vs. module instantiation // Define the top level module called ripple carry counter. // It is illegal to define the module T_FF inside this module. module ripple_carry_counter(q, clk, reset); output [3:0] q; input clk, reset; module T_FF(q, clock, reset);// ILLEGAL MODULE NESTING : : endmodule // END OF ILLEGAL MODULE NESTING endmodule 2010DSD18

Simulation. Test Bench Styles 2010DSD19

Example Design block – ripple_carry_counter, T_FF, and D_FF modules Stimulus block 2010DSD20

Example (cont’d) 2010DSD21 module stimulus; reg clk; reg reset; wire[3:0] q; // instantiate the design block ripple_carry_counter r1(q, clk, reset); // Control the clk signal that drives the design block. initial clk = 1'b0; always #5 clk = ~clk; // Control the reset signal that drives the design block initial begin reset = 1'b1; #15 reset = 1'b0; #180 reset = 1'b1; #10 reset = 1'b0; #20 $stop; end initial // Monitor the outputs $monitor($time, " Output q = %d", q); endmodule

What we learned today An overview of Verilog programming (design) concepts 2010DSD22

Other Notes Course web-page on Sharif Courseware Do it yourself (You won’t, I know! :-) ) – Read Chapters 1 and 2 – Do Chapter 2 exercises – Install and use ModelSim, and simulate ripple_carry_counter example 2010DSD23

Lexical Conventions in Verilog® HDL 2010DSD24

Lexical Conventions Very similar to C – Verilog is case-sensitive – All keywords are in lowercase – A Verilog program is a string of tokens Whitespace Comments Numbers Strings Identifiers Keywords 2010DSD25

Lexical Conventions (cont’d) Whitespace – Blank space (\b) – Tab (\t) – Newline (\n) Whitespace is ignored in Verilog except – In strings – When separating tokens Comments – Used for readability and documentation – Just like C: // single line comment /* multi-line comment */ /* Nested comments /* like this */ may not be acceptable (depends on Verilog compiler) */ 2010DSD26

Lexical Conventions (cont’d) Operators – Unary a = ~b; – Binary a = b && c; – Ternary a = b ? c : d; // the only ternary operator 2010DSD27

Lexical Conventions (cont’d) Number Specification – Sized numbers – Unsized numbers – Unknown and high-impedance values – Negative numbers 2010DSD28

Lexical Conventions (cont’d) Sized numbers – General syntax: ’ : number of bits (in decimal) : – d or D for decimal (radix 10) – b or B for binary (radix 2) – o or O for octal (radix 8) – h or H for hexadecimal (radix 16) : is the number in radix Examples: – 4’b1111 – 12’habc – 16’d255 Unsized numbers – Default base is decimal – Default size is at least 32 (depends on Verilog compiler) – Examples ’habc ’o DSD29

Lexical Conventions (cont’d) X or Z values – Unknown value: lowercase x 4 bits in hex, 3 bits in octal, 1 bit in binary – High-impedance value: lowercase z 4 bits in hex, 3 bits in octal, 1 bit in binary – Examples 12’h13x 6’hx 32’bz – Extending the most-significant part Applied when is bigger than the specified value – Filled with x if the specified MSB is x – Filled with z if the specified MSB is z – Zero-extended otherwise Examples: – 6’hx 2010DSD30

Lexical Conventions (cont’d) Negative numbers – Put the sign before the – Two’s complement is used to store the value – Examples: -6’d3 4’d-2// illegal Underscore character and question marks – Use ‘ _ ’ to improve readability 12’b1111_0000_1010 Not allowed as the first character – ‘ ? ’ is the same as ‘ z ’ (only regarding numbers) 4’b10?? // the same as 4’b10zz 2010DSD31

Lexical Conventions (cont’d) Strings – As in C, use double-quotes – Examples: “Hello world!” “a / b” “text\tcolumn1\bcolumn2\n” Identifiers and keywords – identifiers Alphanumeric characters, ‘ _ ’, and ‘ $ ’ Should start with an alphabetic character or ‘ _ ’ Only system tasks can start with ‘ $ ’ – Keywords Identifiers reserved by Verilog – Examples: reg value; input clk; 2010DSD32

Lexical Conventions (cont’d) Escaped identifiers – Start with ‘ \ ’ – End with whitespace (space, tab, newline) – Can have any printable character between start and end – The ‘ \ ’ and whitespace are not part of the identifier – Examples: \a+b-c// a+b-c is the identifier \**my_name** // **my_name** is the identifier – Used as name of modules 2010DSD33

Data Types in Verilog® HDL 2010DSD34

Data Types Value set and strengths Nets and Registers Vectors Integer, Real, and Time Register Data Types Arrays Memories Parameters Strings 2010DSD35

Value Set Hardware modeling requirements – Value level – Value strength Used to accurately model – Signal contention – MOS devices – Dynamic MOS – Other low-level details 2010DSD36

Value Set and Strength Levels Value levelHW Condition 0Logic zero, false 1Logic one, true xUnknown zHigh imp., floating Strength levelType supplyDriving strongDriving pullDriving largeStorage weakDriving mediumStorage smallStorage highzHigh Impedance 2010DSD37

Register Data Types Registers represent data storage elements – Retain value until next assignment – NOTE: this is not a hardware register or flipflop – Keyword: reg – Default value: x – Example: reg reset; initial begin reset = 1’b1; #100 reset=1’b0; end 2010DSD38

Register Data Types (cont’d) Integer – Keyword: integer – Very similar to a vector of reg integer variables are signed numbers reg vectors are unsigned numbers, unless specified – reg signed [63:0] m; // 64 bit signed value – Bit width: implementation-dependent (at least 32-bits) Designer can also specify a width: integer [7:0] tmp; – Examples: integer counter; initial counter = -1; 2010DSD39

Register Data Types (cont’d) Real – Keyword: real – Values: Default value: 0 Decimal notation: Scientific notation: 3e6 (=3x10 6 ) – Cannot have range declaration – Example: real delta; initial begin delta = 4e10; delta = 2.13; end integer i; initial #5 i = delta; // i gets the value 2 (rounded value of 2.13) 2010DSD40

Register Data Types (cont’d) Time – Used to store values of simulation time – Keyword: time – Bit width: implementation-dependent (at least 64) – $time system function gives current simulation time – Example: time save_sim_time; initial save_sim_time = $time; 2010DSD41

Net Data Type Used to represent connections between HW elements – Values continuously driven on nets Keyword: wire – Default: One-bit values unless declared as vectors – Default value: z For trireg, default is x – Examples wire a; wire b, c; wire d=1’b0; 2010DSD42

Vectors Vector ≡ Multiple-bit width data Applicable to both net and register data types Syntax: – wire/reg [msb_index : lsb_index] data_id; Example wire a; wire [7:0] bus; wire [31:0] busA, busB, busC; reg clock; reg [0:40] virtual_addr; 2010DSD43

Vectors (cont’d) Consider wire [7:0] bus; wire [31:0] busA, busB, busC; reg [0:40] virtual_addr; Bit-select and part-select allowed: busA[7] bus[2:0] // three least-significant bits of bus bus[0:2] // illegal virtual_addr[0:1] /* two most-significant bits * of virtual_addr */ 2010DSD44

Vectors( cont’d) Variable Vector Part Select reg [255:0] data1; //Little endian notation reg [0:255] data2; //Big endian notation reg [7:0] byte; //Using a variable part select, one can choose parts byte = data1[31-:8]; //starting bit = 31, width =8 => data1[31:24] byte = data1[24+:8]; //starting bit = 24, width =8 => data1[31:24] byte = data2[31-:8]; //starting bit = 31, width =8 => data2[24:31] byte = data2[24+:8]; //starting bit = 24, width =8 => data2[24:31] //The starting bit can also be a variable. The width has //to be constant. Therefore, one can use the variable part select //in a loop to select all bytes of the vector. for (j=0; j<=31; j=j+1) byte = data1[(j*8)+:8]; //Sequence is [7:0], [15:8]... [255:248] //Can initialize a part of the vector data1[(byteNum*8)+:8] = 8'b0; //If byteNum = 1, clear 8 bits [15:8] 2010DSD45

Arrays Allowed for all data types Multi-dimensional Syntax: [start_idx : end_idx] [start_idx : end_idx]... [start_idx : end_idx]; Examples: integer count[0:7]; reg bool[31:0]; time chk_point[1:100]; reg [4:0] port_id[0:7]; integer matrix[4:0][0:16]; reg [63:0] array_4d [15:0][7:0][7:0][255:0]; wire [7:0] w_array2 [5:0]; wire w_array1[7:0][5:0]; Difference between vectors and arrays 2010DSD46

Arrays (cont’d) Examples (cont’d) integer count[0:7]; time chk_point[1:100]; reg [4:0] port_id[0:7]; integer matrix[4:0][0:16]; reg [63:0] array_4d[15:0][7:0][7:0][255:0]; count[5] = 0; chk_point[100] = 0; port_id[3] = 0; matrix[1][0] = 33559; array_4d[0][0][0][0][15:0] = 0; port_id = 0; // Illegal matrix [1] = 0; // Illegal 2010DSD47

Memories RAM, ROM, and register-files used many times in digital systems Memory = array of registers (register data type) in Verilog Word = an element of the array – Can be one or more bits Examples: reg membit [0:1023]; reg [7:0] membyte[0:1023]; membyte[511] Note the difference (as in arrays): reg membit[0:127]; reg [0:127] register; 2010DSD48

Strings Strings are stored in reg vectors. 8-bits (1 byte) required per character Stored from the least-significant part to the most-significant part of the reg vector Example: reg [8*18:1] string_value; initial string_value = “Hello World!”; Escaped characters – \n: newline\t: tab – %: % \\: \ – \”: “\ooo: character number in octal 2010DSD49

Have you learned this topic? Various data types – 4-valued logic: 0, 1, x, z – Strength levels – Register vs. Net data types reg, integer, real, time register data types wire data type – Vectors – Arrays – Strings 2010DSD50