Introduction to Verilog

Similar documents
Modeling Sequential Circuits in Verilog

Hardware description language (HDL)

101-1 Under-Graduate Project Digital IC Design Flow

Speaker: Shao-Wei Feng Adviser: Prof. An-Yeu Wu Date: 2010/09/28

ANADOLU UNIVERSITY DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EEM Digital Systems II

FPGA Design Challenge :Techkriti 14 Digital Design using Verilog Part 1

NH 67, Karur Trichy Highways, Puliyur C.F, Karur District DEPARTMENT OF INFORMATION TECHNOLOGY CS 2202 DIGITAL PRINCIPLES AND SYSTEM DESIGN

CENG 241 Digital Design 1

Verilog Tutorial (Structure, Test)

N-input EX-NOR gate. N-output inverter. N-input NOR gate

Chap 6 Introduction to HDL (d)

Lecture 15: System Modeling and Verilog

Combinational Logic II

14:332:231 DIGITAL LOGIC DESIGN. Hardware Description Languages

2/14/2016. Hardware Synthesis. Midia Reshadi. CE Department. Entities, Architectures, and Coding.

Hardware Description Languages (HDLs) Verilog

Hardware Synthesis. References

Digital Design with FPGAs. By Neeraj Kulkarni

Verilog for Combinational Circuits

structure syntax different levels of abstraction

Here is a list of lecture objectives. They are provided for you to reflect on what you are supposed to learn, rather than an introduction to this

Concurrent Signal Assignment Statements (CSAs)

A Verilog Primer. An Overview of Verilog for Digital Design and Simulation

A Brief Introduction to Verilog Hardware Definition Language (HDL)

Spiral 1 / Unit 4 Verilog HDL. Digital Circuit Design Steps. Digital Circuit Design OVERVIEW. Mark Redekopp. Description. Verification.

תכן חומרה בשפת VERILOG הפקולטה להנדסה

Chapter 2a: Structural Modeling

Verilog Design Principles

What is Verilog HDL? Lecture 1: Verilog HDL Introduction. Basic Design Methodology. What is VHDL? Requirements

ACS College of Engineering. Department of Biomedical Engineering. Logic Design Lab pre lab questions ( ) Cycle-1

Introduction to Verilog

Digital Design Using VHDL Using Xilinx s Tool for Synthesis and ModelSim for Verification

Verilog Overview. The Verilog Hardware Description Language. Simulation of Digital Systems. Simulation of Digital Systems. Don Thomas, 1998, Page 1

Lab 1: Introduction to Verilog HDL and the Xilinx ISE

Verilog. What is Verilog? VHDL vs. Verilog. Hardware description language: Two major languages. Many EDA tools support HDL-based design

Hardware description languages

Verilog Overview. The Verilog Hardware Description Language. Simulation of Digital Systems. Simulation of Digital Systems. Don Thomas, 1998, Page 1

C-Based Hardware Design

Verilog Fundamentals. Shubham Singh. Junior Undergrad. Electrical Engineering

FPGA: FIELD PROGRAMMABLE GATE ARRAY Verilog: a hardware description language. Reference: [1]

Hardware Description Language VHDL (1) Introduction

Verilog Overview. The Verilog Hardware Description Language. Simulation of Digital Systems. Simulation of Digital Systems. Don Thomas, 1998, Page 1

Verilog HDL. Testing & Verification Dept. of Computer Science & Engg,, IIT Kharagpur

Lecture 8: Combinational Verilog. CSE 370, Autumn 2007 Benjamin Ylvisaker. Where We Are. Last lecture: Minimization with K!maps

Combinational Logic. Prof. Wangrok Oh. Dept. of Information Communications Eng. Chungnam National University. Prof. Wangrok Oh(CNU) 1 / 93

Tutorial on VHDL and Verilog Applications

Declarations of Components and Entities are similar Components are virtual design entities entity OR_3 is

MODELING LANGUAGES AND ABSTRACT MODELS. Giovanni De Micheli Stanford University. Chapter 3 in book, please read it.

ECEN 468 Advanced Digital System Design

Combinational Logic Circuits

Abi Farsoni, Department of Nuclear Engineering and Radiation Health Physics, Oregon State University

EE 8351 Digital Logic Circuits Ms.J.Jayaudhaya, ASP/EEE

Advanced Digital Design Using FPGA. Dr. Shahrokh Abadi

Introduction to Verilog HDL

Hardware Design Environments. Dr. Mahdi Abbasi Computer Engineering Department Bu-Ali Sina University

Introduction to VHDL. Module #5 Digilent Inc. Course

Introduction to Verilog HDL. Verilog 1

Verilog Design Principles

VeriLogger Tutorial: Basic Verilog Simulation

Department of Electrical and Computer Engineering Xilinx ISIM <Release Version: 14.1i> Simulation Tutorial Using Verilog

HDL for Combinational Circuits. ENEL211 Digital Technology

Lecture 3: Modeling in VHDL. EE 3610 Digital Systems

Module 2.1 Gate-Level/Structural Modeling. UNIT 2: Modeling in Verilog

EECS 3201: Digital Logic Design Lecture 4. Ihab Amer, PhD, SMIEEE, P.Eng.

ENGIN 241 Digital Systems with Lab

Computer Aided Design Basic Syntax Gate Level Modeling Behavioral Modeling. Verilog

Chap 3. Modeling structure & basic concept of Verilog HDL

EGC220 - Digital Logic Fundamentals

EECE-4740/5740 Advanced VHDL and FPGA Design. Lecture 3 Concurrent and sequential statements

Synthesizable Verilog

Software Engineering 2DA4. Slides 2: Introduction to Logic Circuits

COS/ELE 375 Verilog & Design Tools Tutorial

Lab 1 Modular Design and Testbench Simulation ENGIN 341 Advanced Digital Design University of Massachusetts Boston

Schematic design. Gate level design. 0 EDA (Electronic Design Assistance) 0 Classical design. 0 Computer based language

Field Programmable Gate Array

CHAPTER 2 INTRODUCTION TO VERILOG 2.1 COMPUTER-AIDED DESIGN. Copyrighted material; Do not copy or circulate. Page 46

Gate-Level Minimization

Embedded Systems CS - ES

CSE140L: Components and Design Techniques for Digital Systems Lab. Verilog HDL. Instructor: Mohsen Imani UC San Diego. Source: Eric Crabill, Xilinx

EEL 4783: HDL in Digital System Design

Unit 5. Hardware description languages

Lecture 2 Hardware Description Language (HDL): VHSIC HDL (VHDL)

CSCI Lab 3. VHDL Syntax. Due: Tuesday, week6 Submit to: \\fs2\csci250\lab-3\

Design Using Verilog

Chapter 3 Part 2 Combinational Logic Design

LAB K Basic Verilog Programming

Digital Systems Design

Hardware Description Language (HDL)

Lab 7 (All Sections) Prelab: Introduction to Verilog

Combinational Logic Design with Verilog. ECE 152A Winter 2012

Where We Are. Quick History Lesson. Lecture 8: Combinational Verilog. Specifying Circuits. Last lecture: Minimization with K!maps

Verilog Design Entry, Synthesis, and Behavioral Simulation

Lecture 32: SystemVerilog

Nikhil Gupta. FPGA Challenge Takneek 2012

VHDL Examples Mohamed Zaky

Tutorial on Verilog HDL

Xilinx ISE Simulation Tutorial

Lecture 1: VHDL Quick Start. Digital Systems Design. Fall 10, Dec 17 Lecture 1 1

IT T35 Digital system desigm y - ii /s - iii

Getting Started with Xilinx WebPack 13.1

Transcription:

Introduction to Verilog COE 202 Digital Logic Design Dr. Muhamed Mudawar King Fahd University of Petroleum and Minerals

Presentation Outline Hardware Description Language Logic Simulation versus Synthesis Verilog Module Gate-Level Description and Gate Delays Module Instantiation Continuous Assignment Writing a Simple Test Bench Introduction to Verilog COE 202 Digital Logic Design Muhamed Mudawar slide 2

Hardware Description Language Describes the hardware of digital systems in a textual form Describes the hardware structures and behavior Can represent logic diagrams, expressions, and complex circuits NOT a software programming language Two standard hardware description languages (HDLs) 1. Verilog (will be studied in this course) 2. VHDL (harder to learn than Verilog) Introduction to Verilog COE 202 Digital Logic Design Muhamed Mudawar slide 3

Verilog = "Verifying Logic" Invented as a simulation language in 1984 by Phil Moorby Opened to public in 1990 by Cadence Design Systems Became an IEEE standard in 1995 (Verilog-95) Revised and upgraded in 2001 (Verilog-2001) Revised also in 2005 (Verilog-2005) Verilog allows designers to describe hardware at different levels Can describe anything from a single gate to a full computer system Verilog is supported by the majority of electronic design tools Verilog can be used for logic simulation and synthesis Introduction to Verilog COE 202 Digital Logic Design Muhamed Mudawar slide 4

Logic Simulation Logic simulator interprets the Verilog (HDL) description Produces timing diagrams Predicts how the hardware will behave before it is fabricated Simulation allows the detection of functional errors in a design Without having to physically implement the circuit Errors detected during the simulation can be corrected By modifying the appropriate statements in the Verilog description Simulating and verifying a design requires a test bench The test bench is also written in Verilog Introduction to Verilog COE 202 Digital Logic Design Muhamed Mudawar slide 5

Logic Synthesis Logic synthesis is similar to translating a program However, the output of logic synthesis is a digital circuit A digital circuit modeled in Verilog can be translated into a list of components and their interconnections, called netlist Synthesis can be used to fabricate an integrated circuit Synthesis can also target a Field Programmable Gate Array An FPGA chip can be configured to implement a digital circuit The digital circuit can also be modified by reconfiguring the FPGA Logic simulation and synthesis are automated Using special software, called Electronic Design Automation (EDA) tools Introduction to Verilog COE 202 Digital Logic Design Muhamed Mudawar slide 6

Verilog Module A digital circuit is described in Verilog as a set of modules A module is the design entity in Verilog A module is declared using the module keyword A module is terminated using the endmodule keyword A module has a name and a list of input and output ports A module is described by a group of statements The statements can describe the module structure or behavior Introduction to Verilog COE 202 Digital Logic Design Muhamed Mudawar slide 7

Example of a Module in Verilog // Description of a simple circuit module simple_circuit(input A, B, C, output x, y); wire w; and g1(w, A, B); not g2(y, C); or g3(x, w, y); endmodule Order is not important A B C g1 g2 w g3 x y The input keyword defines the input ports: A, B, C The output keyword defines the output ports: x, y The wire keyword defines an internal connection: w The structure of simple_circuit is defined by three gates: and, not, or Each gate has an optional name, followed by the gate output then inputs Introduction to Verilog COE 202 Digital Logic Design Muhamed Mudawar slide 8

Verilog Syntax Keywords: have special meaning in Verilog Many keywords: module, input, output, wire, and, or, etc. Keywords cannot be used as identifiers Identifiers: are user-defined names for modules, ports, etc. Verilog is case-sensitive: A and a are different names Comments: can be specified in two ways (similar to C) Single-line comments begin with // and terminate at end of line Multi-line comments are enclosed between /* and */ White space: space, tab, newline can be used freely in Verilog Operators: operate on variables (similar to C: ~ & ^ + - etc.) Introduction to Verilog COE 202 Digital Logic Design Muhamed Mudawar slide 9

Basic Gates Basic gates: and, nand, or, nor, xor, xnor, not, buf Verilog define these gates as keywords Each gate has an optional name Each gate has an output (listed first) and one or more inputs The not and buf gates can have only one input Examples: and g1(x,a,b); or g2(y,a,b,c); // 2-input and gate named g1 // 3-input or gate named g2 nor g3(z,a,b,c,d); // 4-input nor gate named g3 name output inputs Introduction to Verilog COE 202 Digital Logic Design Muhamed Mudawar slide 10

Modeling a Half Adder A half adder adds two bits: a and b Two output bits: 1. Carry bit: cout = a b 2. Sum bit: sum = a b module Half_Adder(a, b, cout, sum); input a, b; output sum, cout; Verilog-95 Syntax Truth Table a b cout sum 0 0 0 0 0 1 0 1 1 0 0 1 1 1 1 0 a b and (cout, a, b); xor (sum, a, b); Half_Adder endmodule cout sum Introduction to Verilog COE 202 Digital Logic Design Muhamed Mudawar slide 11

Full Adder Full adder adds 3 bits: a, b, and c Two output bits: 1. Carry bit: cout 2. Sum bit: sum Sum bit is 1 if the number of 1's in the input is odd (odd function) sum = (a b) c Carry bit is 1 if the number of 1's in the input is 2 or 3 cout = a b + (a b) c Truth Table a b c cout sum 0 0 0 0 0 0 0 1 0 1 0 1 0 0 1 0 1 1 1 0 1 0 0 0 1 1 0 1 1 0 1 1 0 1 0 1 1 1 1 1 Introduction to Verilog COE 202 Digital Logic Design Muhamed Mudawar slide 12

Full Adder Module module Full_Adder(input a, b, c, output cout, sum); wire w1, w2, w3; and (w1, a, b); xor (w2, a, b); and (w3, w2, c); xor (sum, w2, c); or (cout, w1, w3) endmodule Full_Adder w1 w3 cout w2 a b c sum Introduction to Verilog COE 202 Digital Logic Design Muhamed Mudawar slide 13

Gate Delays When simulating Verilog modules, it is sometime necessary to specify the delay of gates using the # symbol The `timescale directive specifies the time unit and precision timescale is also used as a simulator option `timescale 1ns/100ps Time unit = 1ns = 10-9 sec Precision = 100ps = 0.1ns module Half_Adder(input a, b, output cout, sum); and #2 (cout, a, b); // gate delay = 2ns xor #3 (sum, a, b); // gate delay = 3ns endmodule Introduction to Verilog COE 202 Digital Logic Design Muhamed Mudawar slide 14

Modular Design A full adder can be designed using two half adders and one OR gate a b c First Half Adder: HA1 a b c a b w1 = a b HA1 Half_Adder cout sum w2 = a b Full_Adder w1 w2 a b Second Half Adder: HA2 w3 = w2 c = (a b) c cout sum HA2 Half_Adder cout sum w3 sum = w2 c=(a b) c cout = w1 + w3 = a b + (a b) c cout sum Introduction to Verilog COE 202 Digital Logic Design Muhamed Mudawar slide 15

Module Instantiation Module declarations are like templates Module instantiation is like creating an object Modules are instantiated inside other modules at different levels The top-level module does not require instantiation Module instantiation defines the structure of a digital design It produces a tree of module instances at different levels The ports of a module instance must match those declared The matching of the ports can be done by name or by position Introduction to Verilog COE 202 Digital Logic Design Muhamed Mudawar slide 16

Example of Module Instantiation module Full_Adder (input a, b, c, output cout, sum); wire w1, w2, w3; a b c // Instantiate two Half Adders: HA1, HA2 // The ports are matched by position Half_Adder HA1 (a, b, w1, w2); Half_Adder HA2 (w2, c, w3, sum); or #2 (cout, w1, w3); // Can also match the ports by name // Half_Adder HA2 HA1 a b Half_Adder cout sum w1 w2 HA2 a b Half_Adder cout sum w3 // (.a(w2),.b(c),.cout(w3),.sum(sum)); endmodule cout sum Introduction to Verilog COE 202 Digital Logic Design Muhamed Mudawar slide 17

Continuous Assignment The assign statement defines continuous assignment Syntax: assign name = expression; Assigns expression value to name (output port or wire) Examples: assign x = a&b c&~d; assign y = (a b) & ~c; assign z = ~(a b c); assign sum = (a^b) ^ c; // x = ab + cd' // y = (a+b)c' // z = (a+b+c)' // sum = (a b) c Verilog uses the bit operators: ~ (not), & (and), (or), ^ (xor) Operator precedence: (parentheses), ~, &,, ^ Introduction to Verilog COE 202 Digital Logic Design Muhamed Mudawar slide 18

Continuous Assignment with Delay Syntax: assign #delay name = expression; The optional #delay specifies the delay of the assignment To have a delay similar to the gate implementation module Full_Adder (input a, b, c, output cout, sum); assign #6 sum = (a^b)^c; // delay = 6 assign #7 cout = a&b (a^b)&c; // delay = 7 endmodule The order of the assign statements does not matter They are sensitive to inputs (a, b, c) that appear in the expressions Any change in value of the input ports (a, b, c) will re-evaluate the outputs sum and cout of the assign statements Introduction to Verilog COE 202 Digital Logic Design Muhamed Mudawar slide 19

Test Bench In order to simulate a circuit, it is necessary to apply inputs to the circuit for the simulator to generate an output response A test bench is written to verify the correctness of a design A test bench is written as a Verilog module with no ports It instantiates the module that should be tested It provides inputs to the module that should be tested Test benches can be complex and lengthy, depending on the complexity of the design Introduction to Verilog COE 202 Digital Logic Design Muhamed Mudawar slide 20

Writing a Simple Test Bench module Test_Full_Adder; // No need for Ports reg a, b, c; // variables wire sum, cout; // wires // Instantiate the module to be tested Full_Adder FA (a, b, c, cout, sum); initial begin // initial block a=0; b=0; c=0; // at t=0 time units #20 a=1; b=1; // at t=20 time units #20 a=0; b=0; c=1; // at t=40 time units #20 a=1; c=0; // at t=60 time units #20 $finish; // at t=80 finish simulation end // end of initial block endmodule Introduction to Verilog COE 202 Digital Logic Design Muhamed Mudawar slide 21

Difference Between wire and reg Verilog has two major data types 1. Net data types: are connections between parts of a design 2. Variable data types: can store data values The wire is a net data type A wire cannot store a value Its value is determined by its driver, such as a gate, a module output, or continuous assignment The reg is a variable data type Can store a value from one assignment to the next Used only in procedural blocks, such as the initial block Introduction to Verilog COE 202 Digital Logic Design Muhamed Mudawar slide 22

The initial Statement The initial statement is a procedural block of statements The body of the initial statement surrounded by begin-end is sequential, like a sequential block in a programming language Procedural assignments are used inside the initial block Procedural assignment statements are executed in sequence Syntax: #delay variable = expression; Procedural assignment statements can be delayed The optional #delay indicates that the variable (of reg type) should be updated after the time delay Introduction to Verilog COE 202 Digital Logic Design Muhamed Mudawar slide 23

Running the Simulator Examine the waveforms to verify the correctness of your design At t = 0 ns, the values of cout and sum are unknown (shown in red) The cout and sum signals are delayed by 7ns and 6ns, respectively Introduction to Verilog COE 202 Digital Logic Design Muhamed Mudawar slide 24