Introduction To Verilog Design. Chun-Hung Chou

Similar documents
Introduction to Verilog/System Verilog

Synthesis of Language Constructs. 5/10/04 & 5/13/04 Hardware Description Languages and Synthesis

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

This Lecture. Some components (useful for the homework) Verilog HDL (will continue next lecture)

Introduction. Why Use HDL? Simulation output. Explanation

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

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

Lecture #2: Verilog HDL

Chapter 2 Using Hardware Description Language Verilog. Overview

ECEN 468 Advanced Logic Design

Lab 7 (All Sections) Prelab: Introduction to Verilog

Design Using Verilog

Introduction to Verilog HDL

Verilog Coding Guideline

Verilog HDL Introduction

Arithmetic Operators There are two types of operators: binary and unary Binary operators:

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

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

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

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

Verilog introduction. Embedded and Ambient Systems Lab

EN2911X: Reconfigurable Computing Topic 02: Hardware Definition Languages

Introduction to Digital Design with Verilog HDL

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

ECE 4514 Digital Design II. Spring Lecture 7: Dataflow Modeling

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

Synthesizable Verilog

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

ECE 353 Lab 3 (Verilog Design Approach)

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

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

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

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

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

Verilog. Like VHDL, Verilog HDL is like a programming language but:

VLSI Design 13. Introduction to Verilog

Contents. Appendix D Verilog Summary Page 1 of 16

Spring 2017 EE 3613: Computer Organization Chapter 5: Processor: Datapath & Control - 2 Verilog Tutorial

Introduction to Verilog. Garrison W. Greenwood, Ph.D, P.E.

Course Topics - Outline

Under-Graduate Project Logic Design with Behavioral Models

Chap 6 Introduction to HDL (d)

Verilog Overview. Verilog Overview. Simple Example. Simple Example. Simple Example. Simple Example

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

ECE Digital System Design & Synthesis Exercise 1 - Logic Values, Data Types & Operators - With Answers

Online Verilog Resources

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

Digital Design with FPGAs. By Neeraj Kulkarni

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

ECEN 449 Microprocessor System Design. Verilog. Texas A&M University

CMPE 415 Working with Operands and Variables Prof. Ryan Robucci

Chapter 3: Dataflow Modeling

Verilog. Reminder: Lab #1 due tonight! Fall 2008 Lecture 3

Lecture 15: System Modeling and Verilog

14. Introducton to Verilog

VLSI II E. Özgür ATES

Verilog Fundamentals. Shubham Singh. Junior Undergrad. Electrical Engineering

ECE 353 Lab 4. Verilog Review. Professor Daniel Holcomb UMass Amherst Fall 2017

14. Introducton to Verilog

Chap 6 - Introduction to HDL (b)

Verilog Dataflow Modeling

Lab #1. Topics. 3. Introduction to Verilog 2/8/ Programmable logic. 2. Design Flow. 3. Verilog --- A Hardware Description Language

EN2911X: Reconfigurable Computing Lecture 05: Verilog (2)

Lab 7 (All Sections) Prelab: Verilog Review and ALU Datapath and Control

ECEN 449 Microprocessor System Design. Verilog. Texas A&M University

CSE 2021 Computer Organization. The Basics of Logic Design

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

Chap 3. Modeling structure & basic concept of Verilog HDL

Brief Introduction to Verilog HDL (Part 1)

Verilog for Synthesis Ing. Pullini Antonio

Register Transfer Level in Verilog: Part I

EN164: Design of Computing Systems Lecture 06: Lab Foundations / Verilog 2

A Brief Introduction to Verilog Hardware Definition Language (HDL)

ENGN1640: Design of Computing Systems Topic 02: Lab Foundations

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

UNIT V: SPECIFICATION USING VERILOG HDL

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

Verilog. Verilog for Synthesis

Lab 7 (Sections 300, 301 and 302) Prelab: Introduction to Verilog

a, b sum module add32 sum vector bus sum[31:0] sum[0] sum[31]. sum[7:0] sum sum overflow module add32_carry assign

VERILOG 2: LANGUAGE BASICS

ECEN 468 Advanced Logic Design

Introduction to Verilog HDL. Verilog 1

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

CSE241 VLSI Digital Circuits Winter Recitation 1: RTL Coding in Verilog

Combinational Logic II

In this lecture, we will go beyond the basic Verilog syntax and examine how flipflops and other clocked circuits are specified.

Hardware Description Language (HDL)

SystemVerilog HDL - a programming language

ECE 4514 Digital Design II. Spring Lecture 3: Verilog Bread and Butter

Verilog Design Principles

VERILOG. Deepjyoti Borah, Diwahar Jawahar

Date Performed: Marks Obtained: /10. Group Members (ID):. Experiment # 11. Introduction to Verilog II Sequential Circuits

Digital Design (VIMIAA01) Introduction to the Verilog HDL

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

Some Common Terms. Introduction To ASIC/IC/SoC Design. ASIC: Advantages. ASIC: Disadvantages. Definition. Verilog HDL Introduction

Digital Design with SystemVerilog

LANGUAGE CONSTRUCTS AND CONVENTIONS IN VERILOG

ECEN : Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University. Homework #1 Solutions

Introduction to Digital VLSI Design מבוא לתכנון VLSI ספרתי

Transcription:

Introduction To Verilog Design Chun-Hung Chou 1

Outline Typical Design Flow Design Method Lexical Convention Data Type Data Assignment Event Control Conditional Description Register Description Synthesizable Verilog Code Simulation Environment 2

Typical Design Flow Design Specification Behavior Language Structural Language Algorithmic Model RTL Model Gate-Level Model Switch-Level Model Verilog HDL Physical Layout 3

Design Method(1/3) Top-Down Design design form top module to bottom element Top Module Sub Module Sub Module Element Element Element Element 4

Design Method(2/3) Bottom-Up Design design from element module to top block Top Module Sub Module Sub Module Element Element Element Element 5

Design Method(3/3) Module module_name(port name); port declaration data type declaration task & function declaration Endmodule module functionality 6

Lexical Convention(1/10) Number Specification <size> <base><value> size is the size in bits base can be b(binary), o(octal), d(decimal), or h(hexadecimal) value is any legal number in the selected base, including x and z default value is 32 bits decimal number Negative: -<size> <base><value> Example 8 b1100_0001_1111 8 b110000011111 16 habc 0000 1010 1011 1100 12 b0 0000 0000 0000 6 hx xx xxxx 2 b1101 2 b01 7

Operators synthesis tool doesn t support!! Lexical Convention(2/10) Arithmetic Operator + - * / % add subtract multiply divide modulus Note: verilog automatically perform a 2 s complement when a negative value is assigned to an unsigned variable such as a reg module arithops(); integer ans, int; parameter five = 5; reg [3:0]rega, regb; reg [3:0]num; initial begin rega = 3; regb = 4 b1010; int = -3; initial begin #10 ans = five * int; // ans = -15 #10 ans = (int + 5) / 2; // ans = 1 #10 ans = five / int; // ans = -1 #10 num = rega + regb; // num = 1101 #10 num = rega + 1; // num = 0100 #10 num = int; // num = 1101 #10 num = regb % rega; // num = 1 module 8

Operators Lexical Convention(3/10) Bit-Wise Operator ~ & ^ ~^ ^~ not and or xor xnor xnor module bitwise(); reg [3:0]rega, regb, regc; reg [3:0]num; initial begin rega = 4 b1001; regb = 4 b1010; regc = 4 b11x0 initial begin #10 num = rega & 0; // num = 0000 #10 num = rega & regb; // num = 1000 #10 num = rega regb; // num = 1011 #10 num = regb & regc; // num = 10x0 #10 num = regb regc; // num = 1110 module 9

Operators Lexical Convention(4/10) Logical Operator! && not and or Note1: if it contains any ones, its logical value is true. If an operand contains all zeros, its logical value is false Note2: if it is unknown(contains only zeros and/or unknown bits), its logical value is ambiguous module logical(); parameter five = 5; reg [3:0]rega, regb, regc; reg [3:0]ans; initial begin rega = 4 b0011; regb = 4 b10xz; regc = 4 b0z0x; initial begin #10 ans = rega && 0; // ans = 0 #10 ans = rega 0; // ans = 1 #10 ans = rega && five; // ans = 1 #10 ans = regb && rega; // ans = 1 #10 ans = regc 0; // ans = x module 10

Operators Lexical Convention(5/10) module shift(); Shift Operator >> << shift right shift left reg [7:0]rega; reg [9:0]num; initial rega = 8 b0000_1100; initial begin #10 num = rega << 5; // num = 0110000000 #10 num = rega >> 3;// num = 0000000001 module 11

Lexical Convention(6/10) Operators Relational Operator > greater than < less than >= greater than or equal <= less than or equal module relationals(); reg [3:0]rega, regb, regc; reg val; initial begin rega = 4 b0011; regb = 4 b1010; regc = 4 b0x10; initial begin #10 val = regc > rega; //val=x #10 val = regb < rega; //val=0 #10 val = regb >= rega; //val=1 #10 val = regb > regc; //val=x module 12

Operators Lexical Convention(7/10) module equalities(); Equality Operator ==!= logical equality logical inequality reg [3:0]rega, regb, regc; reg val; initial begin rega = 4 b0011; regb = 4 b1010; regc = 4 b0x10; initial begin #10 val = regc > rega; //val=x #10 val = regb < rega; //val=0 #10 val = regb >= rega; //val=1 #10 val = regb > regc; //val=x module 13

Lexical Convention(8/10) Operators Conditional Operator <LHS> = <condition>? <true_expression> : <false_expression> a b 1 0 out module mux(a, b, sel, out); input a, b, sel; output out; assign out = (sel == 1)? a : b; module sel 14

Lexical Convention(9/10) Comment single-line comments with // multiple-line comments with /* */ 15

Lexical Convention(10/10) Concatenation Note1: allows you to select bits form different vectors and join them into a new vector { } rega[3:0] regb[3:0] new[7:0] Note2: a[4:0] = {a[3:0], 1 b0}; a = a<<1; module concatenation(); reg regc, regd; reg [3:0]rega, regb; reg [7:0]new; reg [3:0]out; reg [5:0]val; initial begin rega = 8 b0000_0011; regb = 8 b0000_0100; regc = 1 b1; regd = 1 b0; initial begin #10 new = {rega, regb}; // new = 8 b00110100 #10 out = {4{regc}}; //out=4 b1111 #10 out = {4{regd}}; //out=4 b0000 #10 val = {regc,{2{regc,regd}},regd}; // val = 6 b110100 module 16

Data Type(1/6) 4-Value Logic System in Verilog 0 Zero 1 One x z Unknown NOTE: In real hardware, this node will most be at either 1 or 0 High Impedance 0 17

Data Type(2/6) Three Major Data type classes in Verilog Nets represent physical connection between devices Registers represent abstract storage elements Parameters are run-time constants Declaration Syntax <data_type> [<MSB>:<LSB>] <list_of_identifier> 18

Nets Data Type(3/6) wire is the most common net type a a1 sel out b b1 wire NOTE: Verilog automatically propagates a new value onto a wire when the drivers on the wire change value. This means that whatever value is on the or gate will be automatically driven onto the wire out 19

Registers Data Type(4/6) reg is the most common register type reg_a a a1 reg_sel sel out reg_b b b1 NOTE1: a register holds its value until a new value is assigned to it NOTE2: apply values to registers form procedural blocks 20

Vectors Data Type(5/6) the wire and register can be represented as a vector Arrays wire [7:0]temp1; 8-bit bus reg [7:0]temp2; <array_name>[<subscript>] integer temp1[7:0]; (8x32)bit reg [7:0]temp2[0:1023] Memory(1k,1byte) NOTE: array is not well for the back verification 21

Data Type(6/6) module and1(out, in1, in2); input in1, in2; output out; wire out; assign out = in1 & in2; module module and2(out, in1, in2); input in1, in2; output out; reg out; always@ (in1 or in2) out = in1 & in2; module 22

Data Assignment(1/3) Continuous Assignment you can model combinational logic with continuous assignments, instead of using gates and interconnect wires imply that whatever any change on the RHS of the assignment occurs, it is evaluated and assigned to the LHS assign [#delay] <wire_name> = <expression> wire [3:0]a; assign a = b + c; //continuous assignment 23

Data Assignment(2/3) Procedural Assignment assignment to register data types may occur within always, initial, task and function. These expressions are controlled by triggers which cause the assignment to evaluate regclk; always #10 CLK = ~CLK; //procedural assignment reg a, b; always@ (b) //procedural assignment with trigger a = ~b; procedural assignment consists blocking & nonblocking assignment 24

Data Assignment(3/3) Blocking Assignment Sequential!! always@ (posedge clk) begin b = a; c = b; Non-Blocking Assignment Parallel!! always@ (posedge clk) begin b <= a; c <= b; 25

Event Control Combinational Circuit @(a): act if signal a changes always@ (a) c = a + 1; @(a or b): act if signal a or b changes always@ (a or b) c = a + b; Sequential Circuit @(posedge clk): act when rising edge of clk always@ (posedge clk) c = a + 1; @(negedge clk): act when falling edge of clk always@ (negedge clk) c = a + 1; 26

Conditional Description(1/2) if and if-else Statements if (index > 0) // beginning of outer if if (rega > regb) //beginning of the 1st inner if result = rega; else result = 0; else if (index == 0) begin $display( Note : Index is zero ); result = regb; else $display( Note : Index is negative ); critical path.. 27

Conditional Description(2/2) case Statement module compute(result,rega,regb,opcode); input [7:0]rega, regb; input [2:0]opcode; output [7:0]result; critical path reg [7:0]result; always@ (rega or regb or opcode) begin case (opcode) 3 b000 : result = rega + regb; 3 b001 : result = rega regb; 3 b100 : result = rega / regb; default : result = 8 bx; case module. 28

Register Description(1/2) Informal Description combinational circuit and memory element is combined in one always bolck module MUX(out, sel, clk, reset, in1, in2); input sel, clk, reset; input [7:0]in1, in2; output [7:0]out; reg [7:0]out; always@ (posedge reset or posedge CLK) begin if(reset==1 b1) out <= 1 b0; else if(sel==1 b0) out <= in1; else out <= in2; module 29

Register Description(2/2) Normative Description separate the combinational and sequential parts module MUX(out, sel, clk, reset, in1, in2); input sel, clk, reset; input [7:0]in1, in2; output [7:0]out; reg [7:0]out; wire c; // combinational part assign c = (sel)? in1 : in2; //sequential part always@ (posedge reset or posedge CLK) begin if(reset) out <= 1 b0; else out <= c; module NOTE: it s the better way 30

Synthesizable Verilog Code(1/2) Four data type can be synthesized input, output, wire, reg 1-D data type is convenient for synthesis reg [7:0] a; reg [7:0]a[3:0]; Synthesizable Verilog functions assign, always block, called sub-module Synthesizable register description always@ (posedge clk) always@ (negedge clk) always@ (posedge clk or posedge reset) if(reset)..else.. always@ (negedge clk or posedge reset) if(reset)..else.. always@ (posedge clk or negedge reset) if(~reset)..else.. always@ (negedge clk or negedge reset) if(~reset)..else.. 31

Synthesizable Verilog Code(2/2) What kind of Verilog code can t be synthesized? always@ (posedge clk or negedge clk) wire [7:0]a; reg [3:0]b; assign a[b] = 0; always@ (posedge clk) out = out + 1; always@ (negedge clk) out = a; always@ (posedge clk or posedge reset) if(reset) out = 0; else out <= out + in; 32

Simulation Environment(1/5) module 33

Simulation Environment(2/5) MUX.v module MUX(OUT,CLK,SEL,RESET,IN1,IN2); input CLK,SEL,RESET,IN1,IN2; output OUT; reg OUT; wire C; Your Design!! assign C = (SEL)? IN1 : IN2; TEST_MUX.v `timescale 1 ns/10 ps `include MUX.v module stimulus; reg CLK,SEL,RESET,IN1,IN2; wire OUT; Testbench!! //connect port by ordering MUX t(out,clk,sel,reset,in1,in2); always@ (posedge CLK) begin if(reset) OUT <= 1 b0; else OUT <= C; module //connect port by name MUX t(.out(out),.clk(clk),.sel(sel),.reset(reset),.in1(in1),.in2(in2)); initial begin.. module 34

Simulation Environment(3/5) Clock Generation Initial clk = 0; always #20 clk = ~clk; Display Simulation Result(Texture Format) $display( %t,clk=%d in=%d out=%d\n,$time clk,in,out); $monitor($time, clk=%d out=%d\n, clk,out); $time: current time $finish: finish the simulation Dump a FSDB file for debug(debussy) $fsdbdumpfile( file_name.fsdb ); $fsdbdumpvars; 20 20 NOTE: $ denotes Verilog system tasks and functions 35

Simulation Environment(4/5) Format Specifiers: ----------------------------------------------------------------------------------------------------- %h %o %d %b %c %s %v %m %t hex octal decimal binary ASCII string strength module time ----------------------------------------------------------------------------------------------------- Escaped Literals: ----------------------------------------------------------------------------------------------------- \t \n \\ \ \<1-3 digit octal number> tab new line backslash double quote ASCII representation of above ----------------------------------------------------------------------------------------------------- 36

Simulation Environment(5/5) Complier Directive `define <macro_neme> <macro_text> `define delay #1 and `delay and1(a1, a, sel); `include <file_name> `include counter.v `timescale <time_unit> / <time_precision> `timescale 1ns / 10ps 37

`timescale 1 ns/10 ps `include MUX.v module stimulus; reg CLK,SEL,RESET,IN1,IN2; wire OUT; parameter cycle = 5; MUX m(.out(out),.clk(clk),.sel(sel),.reset(reset),.in1(in1),.in2(in2)); always #(cycle) CLK = ~CLK; initial begin $fsdbdumpfile( MUX.fsdb ); $fsdbdumpvars; IN1 = 0; IN2 = 1; SEL = 0; RESET = 0; CLK = 0; //time = 0 #(cycle) IN2 = 0; //time = 5 #(cycle) IN2 = 1; SEL = 1; //time =10 #(cycle*2) IN1 = 1; //time =20 $display( %d, OUT); $finish; End module 38