Introduction to Verilog HDL. Verilog 1

Similar documents
Combinational Circuit Design

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

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

Introduction to Verilog design. Design flow (from the book)

Advanced Digital Design Using FPGA. Dr. Shahrokh Abadi

Synthesis of Combinational and Sequential Circuits with Verilog

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

Lecture 2: Data Types, Modeling Combinational Logic in Verilog HDL. Variables and Logic Value Set. Data Types. Why use an HDL?

ECEN 468 Advanced Digital System Design

Lecture 15: System Modeling and Verilog

Introduction to Verilog design. Design flow (from the book) Hierarchical Design. Lecture 2

Synthesizable Verilog

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

Chapter 2 Using Hardware Description Language Verilog. Overview

Tutorial on Verilog HDL

ELCT 501: Digital System Design

Combinational Logic II

Why Should I Learn This Language? VLSI HDL. Verilog-2

Online Verilog Resources

Digital Design with FPGAs. By Neeraj Kulkarni

101-1 Under-Graduate Project Digital IC Design Flow

Digital Circuit Design and Language. Datapath Design. Chang, Ik Joon Kyunghee University

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

Design Using Verilog

Programmable Logic Devices Verilog VII CMPE 415

A Brief Introduction to Verilog Hardware Definition Language (HDL)

Introduction to Verilog/System Verilog

EECS 427 Lecture 14: Verilog HDL Reading: Many handouts/references. EECS 427 W07 Lecture 14 1

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

Federal Urdu University of Arts, Science and Technology, Islamabad VLSI SYSTEM DESIGN. Prepared By: Engr. Yousaf Hameed.

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

Lecture #2: Verilog HDL

EEL 4783: HDL in Digital System Design


EEL 4783: Hardware/Software Co-design with FPGAs

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

Topics. Midterm Finish Chapter 7

CSE140L: Components and Design Techniques for Digital Systems Lab

Speaker: Kayting Adviser: Prof. An-Yeu Wu Date: 2009/11/23

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

CSE140L: Components and Design

Verilog Coding Guideline

DIGITAL SYSTEM DESIGN

Synthesis vs. Compilation Descriptions mapped to hardware Verilog design patterns for best synthesis. Spring 2007 Lec #8 -- HW Synthesis 1

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

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

EN2911X: Reconfigurable Computing Topic 02: Hardware Definition Languages

Verilog Tutorial (Structure, Test)

EECS150 - Digital Design Lecture 10 Logic Synthesis

Verilog Fundamentals. Shubham Singh. Junior Undergrad. Electrical Engineering

VERILOG HDL. (and C) 1 ENGN3213: Digital Systems and Microprocessors L#5-6

ECE 2300 Digital Logic & Computer Organization. More Sequential Logic Verilog

ECE 353 Lab 3 (Verilog Design Approach)

Verilog introduction. Embedded and Ambient Systems Lab

Verilog Tutorial. Introduction. T. A.: Hsueh-Yi Lin. 2008/3/12 VLSI Digital Signal Processing 2

Module 4. Design of Embedded Processors. Version 2 EE IIT, Kharagpur 1

EECS150 - Digital Design Lecture 10 Logic Synthesis

Modeling Synchronous Logic Circuits. Debdeep Mukhopadhyay IIT Madras

Code No: R Set No. 1

Graduate Institute of Electronics Engineering, NTU. Lecturer: Chihhao Chao Date:

Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

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

VLSI Design 13. Introduction to Verilog

CSE 2021 Computer Organization. The Basics of Logic Design

Advanced Digital Design with the Verilog HDL

Lecture 32: SystemVerilog

DIGITAL SYSTEM DESIGN

Code No: R Set No. 1

ENGN1640: Design of Computing Systems Topic 02: Design/Lab Foundations

Verilog HDL Introduction

Chapter 2 Basic Logic Circuits and VHDL Description

Contents. Appendix D Verilog Summary Page 1 of 16

CS6710 Tool Suite. Verilog is the Key Tool

ECE 353 Lab 4. Verilog Review. Professor Daniel Holcomb With material by Professor Moritz and Kundu UMass Amherst Fall 2016

Verilog Module 1 Introduction and Combinational Logic

ENGN1640: Design of Computing Systems Topic 02: Design/Lab Foundations

Verilog 1 - Fundamentals

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

The Verilog Language COMS W Prof. Stephen A. Edwards Fall 2002 Columbia University Department of Computer Science

Chapter 3 Part 2 Combinational Logic Design

VHDL VS VERILOG.

VHDL for Synthesis. Course Description. Course Duration. Goals

Writing Circuit Descriptions 8

Digital Design (VIMIAA01) Introduction to the Verilog HDL

VLSI II E. Özgür ATES

Under-Graduate Project Logic Design with Behavioral Models

HDLs and SystemVerilog. Digital Computer Design

Code No: R Set No. 1

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

Department of Computer Science and Electrical Engineering. Intro to Verilog II

Verilog 1 - Fundamentals

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

Course Topics - Outline

EECS150 - Digital Design Lecture 4 - Verilog Introduction. Outline

Verilog for High Performance

ENGN1640: Design of Computing Systems Topic 02: Lab Foundations

Register Transfer Level in Verilog: Part I

Hardware Description Languages (HDLs) Verilog

Verilog for Synthesis Ing. Pullini Antonio

Verilog for Combinational Circuits

Transcription:

Introduction to HDL

Hardware Description Language (HDL) High-Level Programming Language Special constructs to model microelectronic circuits Describe the operation of a circuit at various levels of abstraction Behavioral Functional (Register Transfer Level) Structural Express the concurrency of circuit operation Serve as input to synthesis 2

HDL Major HDLs Started by Gateway in 984 Became open to public by Cadence in 99 IEEE standard 364 in 995 Slightly better at gate/transistor level Language style close to C/C++ Pre-defined data type, easy to use VHDL Started by VHSIC project in 98s IEEE standard 76 in 987, IEEE 64 in 993 Slightly better at system level Language style close to Ada/Pascal User-defined data type, more flexible Equally effective, personal preference 3

Why HDL Facilitate a top-down design methodology using synthesis Design at a high implementation-independent level Delay decision on implementation details Easily explore design alternatives Automatically map high-level description to a technology-specific implementation Provides greater flexibility Reuse earlier design components Move designs between multiple vendors and tools 4

Typical Design Flow Design Specification Floorplanning Automatic Place & Route Behavioral Description Physical Layout RTL Description Functional Simulation Logic Synthesis Gate-Level Netlist Post-Layout Simulation Layout Verification (DRC, LVS, ) Implementation Pre-Layout Simulation 5

-Supported Levels of Abstraction Behavioral Describes a system by the flow of data between its functional blocks Defines signal values when they change Functional or Register Transfer Level (RTL) Describes a system by the flow of data and control signals between and within its functional blocks Defines signal values with respect to a clock Structural Describes a system by connecting predefined components Uses technology-specific, low-level components when mapping from an RTL description to a gate-level netlist, such as during synthesis. 6

Block Diagram & Schematic a b Add_half sum c_out block diagram a b sum c_out_bar c_out schematic 7

Modules A module is the basic building block in Every module starts with the keyword module, has a name, and ends with the keyword endmodule A module can be A design block A simulation block, i.e., a testbench module add_ (...);...... endmodule 8

Module Ports Module ports describe the input and output terminals of a module Listed in parentheses after the module name Declared to be input, output, or inout (bi-directional) module add_ (sum, a, b, c_in, c_out); output sum; input a; input b; input c_in; output c_out; // output sum, c_out; // input a, b, c_in;...... endmodule 9

Structural Level Description module name module ports module Add_half (sum, c_out, a, b); input a, b; output sum, c_out; wire c_out_bar; xor (sum, a, b); nand (c_out_bar, a, b); not (c_out, c_out_bar); endmodule declaration of port modes declaration of internal signal instantiation of primitive gates Note: All bold-faced items are keywords

Predefined Primitives Combinational logic gates and, nand or, nor xor, xnor buf, not

Full Adder Add_full c_in a b a b sum Add_half c_out a b sum Add_half c_out sum c_out module Add_full (sum, c_out, a, b, c_in); //parent module input a, b, c_in; output c_out, sum; wire w, w2, w2; module instance name Add_half M (w, w2, a, b); //child module Add_half M2 (sum, w3, w, c_in); //child module or (c_out, w2, w3); //primitive instantiation endmodule 2

Hierarchical Description Add_full M M2 Add_half Add_half or xor nand not xor nand not Nested module instantiation is the mechanism for hierarchical decomposition of a design 3

RTL Level Description An RTL model provides sufficient architectural details that a synthesis tool can construct the circuit module add_ (sum, a, b, c_in, c_out); output sum, c_out; input a, b, c_in; assign {c_out, sum} = a + b + c_in; endmodule 4

The Behavioral Level Describes the behavior of a design without implying any specific internal architecture High level constructs, such as @, case, if, repeat, wait, while, etc Testbench Limited support by synthesis tools The difference between a behavioral model and an RTL model and an RTL model is not always clear whether synthesizable or not 5

Behavioral Level Description module Add_half (sum, c_out, a, b); input a, b; output sum, c_out; reg sum, c_out; always@(a or b) begin sum = a ^ b; //exclusive or c_out = a & b; end endmodule //and procedural statements 6

Behavioral Description of D F/F rst data_in clk block diagram q module Flip_flop (q, data_in, clk, rst); input data_in, clk, rst; output q; reg q; always @ (posedge clk) begin if(rst == ) q=; else q = data_in; end endmodule declaration of synchronous behavior 7

Variables Nets wire : structural connectivity Registers reg : abstraction of storage (may or may not be physical storage) Both nets and registers are informally called signals, and may be either scalar or vector 8

signal values Logic Values : logical, or a FALSE condition : logical, or a TRUE condition x: an unknown value z: a high impedance condition 9

Hierarchical De-Referencing To reference a variable defined inside an instantiated module Supported by a variable s hierarchical path name X.w X.Y.Z.w Module A - Instance X wire w Module B - Instance Y Module C - Instance Z Wire w 2

if else else is paired with nearest if when ambiguous (use begin end in nesting to clarify) (a) if (a < b) c = d + ; (b) if (a < b); (c) if (k == ) begin : A_block sum_out = sum_reg; c_out = c_reg; end (d) if (a < b) sum = sum + ; else sum = sum + 2; 2

Example module mux4_pca (a, b, c, d, select, y_out); input a, b, c, d; input [:] select; output y_out; reg y_out; always @ (select or a or b or c or d) if (select == ) y_out = a; else if (select == ) y_out = b; else if (select == 2) y_out = c; else if (select == 3) y_out = d; else y_out = bx; endmodule 22

case Require complete bitwise match Example: always @ (a or b or c or d or select) begin case (select) : y = a; : y = b; 2: y = c; 3: y = d; default: y = bx; endcase end 23

Netlist of Primitives module or_nand_ (enable, x, x2, x3, x4, y); input enable, x, x2, x3, x4; output y; wire w, w2, w3; x x2 x3 x4 w w2 w3 y or (w, x, x2); or (w2, x3, x4); or (w3, x3, x4); // redundant nand (y, w, w2, w3, enable); endmodule enable (a) Pre-optimized circuit enable x x2 x3 x4 oai22_a (b) Circuit synthesized from the circuit in (a) nand2i_a y 24

Continuous Assignment module or_nand_2 (enable, x, x2, x3, x4, y); input enable, x, x2, x3, x4; output y; assign y = ~(enable & (x x2) & (x3 x4)); endmodule x x2 enable x3 x4 w w3 enable x x2 x3 x4 oai22_a nand2i_a y Synthesis result 25

Behavioral Description module or_nand_3 (enable, x, x2, x3, x4, y); input enable, x, x2, x3, x4; output y; reg y; always @ (enable or x or x2 or x3 or x4) begin y = ~(enable & (x x2) & (x3 x4)); end endmodule enable x x2 x3 x4 oai22_a nand2i_a y Circuit synthesized from a behavioral description 26

Avoid Latch Inference (/2) When if or case statements are used without specifying outputs in all possible conditions, a latch will be created always@(enable or data) if(enable) q = data; data enable DLA q always@(enable or data) begin if(enable) q = data; else enable data q = ; Specify all output values end AN2A Latch inferred q 27

Avoid Latch Inference (2/2) always@(a or b or c) case(a) 2 b : e = b; 2 b : e = ~c; endcase No latch always@(a or b or c) case(a) 2 b : e = b; 2 b : e = ~c; default : e = ; endcase Add a default statement result in a latch 28

29 Code Converter (/3) A code converter transforms one representation of data to another Ex: A BCD to excess-3 code converter BCD: Binary Coded Decimal Excess-3 code: the decimal digit plus 3 D C B A Z Y X W Input BCD Output Excess-3 Truth Table for Code Converter Example

Code Converter (2/3) Equations: (share terms to minimize cost) W = A + BC + BD = A + B(C + D) X = BC + BD + BCD = B(C + D) + BCD Y=CD+CD=C+D Z=D D Z AB CD C D C CD Y A B B C + D (C + D) X D W=A+BC+BD A W 3

Code Converter (3/3) RTL style assign W = A (B&(C D)); assign X = ~B&(C D) (B&~C&~D); assign Y = ~(C^D); assign Z = ~D; Behavior style assign ROM_in = {A, B, C, D}; assign {W, X, Y, Z} = ROM_out; always @(ROM_in) begin case (ROM_in) 4 b: ROM_out = 4 b; 4 b: ROM_out = 4 b; 4 b: ROM_out = 4 b; default: ROM_out = 4 b; endcase end 3

32 Decoder (/2) A decoder is to generate the 2 n (or fewer) minterms of n input variables Ex: a 3-to-8 line decoder D D D D D D D D z y x 7 6 5 4 3 2 Inputs Outputs z y x D = x y z D = x y z D 2 = x yz D 3 = x yz D 4 = xy z D 5 = xy z D 6 = xyz D 7 = xyz

Decoder (2/2) Behavior style input x, y, z; output [7:] D; reg [7:] D; always @(x or y or z) begin case ({x, y, z}) 3 b: D = 8 b; 3 b: D = 8 b; 3 b: D = 8 b; default: D = 8 b; endcase end Behavior style 2 input x, y, z; output [7:] D; wire [2:] addr; reg [7:] D; assign addr = {x, y, z}; always @(addr) begin D = 8 b; D[addr] = ; end 33

Multiplexer (/2) A multiplexer uses n selection bits to choose binary info. from a maximum of 2 n unique input lines I I I 2 I 3 S S S S Y decoder!! Y I I I I 2 3 (b) Function table (a) Logic diagram 34

Behavior style input [:] S; input [3:] I; output Y; reg Y; always @(S or I) begin case (S) 2 b: Y = I[]; 2 b: Y = I[]; 2 b: Y = I[2]; 2 b: Y = I[3]; default: Y = ; endcase end Multiplexer (2/2) Behavior style 2 input [:] S; input [3:] I; output Y; reg Y; always @(S or I) begin Y = I[S]; end 35

BCD Adder (/2) Addend Augend C detects whether the binary sum is greater than 9 () C = K + Z 8 Z 4 + Z 8 Z 2 Carry out K 4-bit binary adder Z 8 Z 4 Z 2 Z Carry in Output carry If C=, it is necessary to add 6 () to binary sum 4-bit binary adder S 8 S 4 S 2 S 36

BCD Adder (2/2) module bcd_add (S, Cout, A, B, Cin); input [3:] A, B; input Cin; output [3:] S; output Cout; reg [3:] S; reg Cout; always @(A or B or Cin) begin {Cout, S} = A + B + Cin; if (Cout!= S > 9) begin S = S + 6; Cout = ; end end endmodule 37

Latch Inference Incompletely specified wire in the synchronous section D latch always @(enable or data) if (enable) q = data; 38

More Latches D latch with gated enable always @(enable or d or gate) if (enable & gate) q = d; d enable gate q D latch with asynchronous reset always @(reset or data or enable) if (reset) q = b; else if (enable) q = data; 39

Flip-Flop Inference Wire (port) assigned in the synchronous section module FF_PN (Clock, X, X2, Y, Y2); input Clock; input X, X2; X output Y, Y2; reg Y, Y2; Clock always @(posedge Clock) Y = X; X2 always @(negedge Clock) Y2 = X2; endmodule Clock Y Y2 4

Modeling Reset Synchronous reset always@(posedge clk) if(!reset) q= b; else q=data; Asynchronous reset always@(posedge clk or negedge reset) if(!reset) q= b; else q=data; reset data AN2S DFS q clk data reset INA DFQ3A q clk set INA 4

The Simplest Shift Register Serial input SI D D D D SO Serial output C C C C CLK 4-Bit Shift Register Clock SRG4 SI SO Symbol 42

Procedural Assignment Assign value to registers Blocking procedural assignment Use = An assignment is completed before the next assignment starts Non-blocking procedural assignment Use <= Assignments are executed in parallel 43

Examples a = ; b = ; a <= b; // use b= b <= a; // use a= a = ; b = ; b <= a; // use a= a <= b; // use b= a = ; b = ; a = b; // use b= b = a; // use a= a = ; b = ; b = a; // use a= a = b; // use b= 44

HDL Modeling for Shift Reg. Blocking assignment assign SO = D; always @(posedge CLK) begin if (reset) begin A=; B=; C=; D=; end else if (shift) begin D = C; C = B; B = A; A = SI; end end order dependent Non-blocking assignment assign SO = D; always @(posedge CLK)begin if (reset) begin A<=; B<=; C<=; D<=; end else if (shift) begin A <= SI; C <= B; D <= C; B <= A; end end can be any order 45

Non-Blocking Assignment always@(posedge clk) begin outa<=in; outb<=outa; outc<=outb; end always@(posedge clk) outa=in; always@(posedge clk) outb=outa; always@(posedge clk) outc=outb; in D Q D Q D Q outc clk 46

References T.-C. Wang, course slides of HDL and Synthesis, Dept. of CS, NTHU. C.-N. Liu, course slides of Digital System Design, Dept. of EE. NCU. 47