Verilog Coding Guideline

Similar documents
ECE 353 Lab 3 (Verilog Design Approach)

Verilog introduction. Embedded and Ambient Systems Lab

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

Lecture #2: Verilog HDL

Modeling Sequential Circuits in Verilog

Introduction to Verilog/System Verilog

Synthesizable Verilog

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

Introduction To Verilog Design. Chun-Hung Chou

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

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

Introduction. Why Use HDL? Simulation output. Explanation

Lecture 32: SystemVerilog

Chapter 2 Using Hardware Description Language Verilog. Overview

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

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

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

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

ECE 2300 Digital Logic & Computer Organization. More Finite State Machines

Introduction to Verilog HDL. Verilog 1

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

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

Verilog HDL Introduction

Digital Design (VIMIAA01) Introduction to the Verilog HDL

FSM and Efficient Synthesizable FSM Design using Verilog

Quick Introduction to SystemVerilog: Sequental Logic

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

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

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

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

Digital Design with FPGAs. By Neeraj Kulkarni

register:a group of binary cells suitable for holding binary information flip-flops + gates

Graduate Institute of Electronics Engineering, NTU Design of Datapath Controllers

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

Brief Introduction to Verilog HDL (Part 1)

EECS150 - Digital Design Lecture 5 - Verilog Logic Synthesis

Digital Design with SystemVerilog

Contents. Appendix D Verilog Summary Page 1 of 16

Verilog for High Performance

EN2911X: Reconfigurable Computing Topic 02: Hardware Definition Languages

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

Hardware Description Language (HDL)

ECE 551: Digital System *

Homework deadline extended to next friday

Verilog for Synthesis Ing. Pullini Antonio

A Brief Introduction to Verilog Hardware Definition Language (HDL)

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

EN2911X: Reconfigurable Computing Lecture 05: Verilog (2)

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

Laboratory Exercise 3 Davide Rossi DEI University of Bologna AA

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

CS6710 Tool Suite. Verilog is the Key Tool

CSE140L: Components and Design Techniques for Digital Systems Lab

Advanced Digital Design Using FPGA. Dr. Shahrokh Abadi

Lecture 15: System Modeling and Verilog

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

CSE140L: Components and Design

Register Transfer Level in Verilog: Part I

Course Topics - Outline

Chap 6 Introduction to HDL (d)

Digital Integrated Circuits

Verilog Module 1 Introduction and Combinational Logic

Chapter 4. Digital Design and Computer Architecture, 2 nd Edition. David Money Harris and Sarah L. Harris. Chapter 4 <1>

Chapter 4. Digital Design and Computer Architecture, 2 nd Edition. David Money Harris and Sarah L. Harris. Chapter 4 <1>

HDL. Hardware Description Languages extensively used for:

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

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

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

Chapter 4 :: Topics. Introduction. SystemVerilog. Hardware description language (HDL): allows designer to specify logic function only.

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

Synthesis of Combinational and Sequential Circuits with Verilog

Design Using Verilog

ECE 2300 Digital Logic & Computer Organization. More Verilog Finite State Machines

Digital Integrated Circuits

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

DIGITAL SYSTEM DESIGN

CSE 502: Computer Architecture

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

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

ECEN 468 Advanced Logic Design

HDLs and SystemVerilog. Digital Computer Design

Verilog Fundamentals. Shubham Singh. Junior Undergrad. Electrical Engineering

EEL 4783: HDL in Digital System Design

EECS150 - Digital Design Lecture 4 - Verilog Introduction. Outline

Control in Digital Systems

EPC6055 Digital Integrated Circuits EXAM 1 Fall Semester 2013

Sequential Logic Design

Outline. EECS Components and Design Techniques for Digital Systems. Lec 11 Putting it all together Where are we now?

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

CSCB58 - Lab 3. Prelab /3 Part I (in-lab) /2 Part II (in-lab) /2 TOTAL /8

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

EE178 Lecture Verilog FSM Examples. Eric Crabill SJSU / Xilinx Fall 2007

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

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

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

ECE 551 Digital System Design and Synthesis. Instructor: Kewal K. Saluja. Midterm Exam

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Department of Electrical Engineering and Computer Sciences

Veriolog Overview. CS/EE 3710 Fall 2010

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

VHDL for Synthesis. Course Description. Course Duration. Goals

Transcription:

Verilog Coding Guideline Digital Circuit Lab TA: Po-Chen Wu

Outline Introduction to Verilog HDL Verilog Syntax Combinational and Sequential Logics Module Hierarchy Write Your Design Finite State Machine 2

Introduction to Verilog HDL 3

What is Verilog Doing Wafer Chip Logic Module CIS PE3 PE4 PE6 PE0 Feature Processor RISC Registers Memory PE7 PE1 PE2 PE5 + - MUX Abs DFF Verilog Standard Cell Layout Backend EDA Tools 4

Verilog HDL Verilog HDL Hardware Description Language Programming language Describes a hardware design Other hardware description language VHDL 5

Represent a Circuit (1/2) In software max_abcd = max( max(a,b), max(c,d) ); a b c d max max max_ab max_cd max max_abcd In verilog?? 6

Represent a Circuit (2/2) a b c d max max max_ab max_cd max max_abcd wire [3:0] a, b, c, d; reg [3:0] max_ab; max_cd; reg [3:0] max_abcd; data declaration always@(*) begin max_ab = (a > b)? a: b; logic behavior max_cd = (c > d)? c: d; max_abcd = (max_ab > max_cd)? max_ab: max_cd; end 7

Verilog Syntax 8

Blocking and Nonblocking Statements (1/2) Blocking Statements "=" A blocking statement must be executed before the execution of the statements that follow it in a sequential block. Nonblocking Statements "<=" Nonblocking statements allow you to schedule assignments without blocking the procedural flow. 9

Blocking and Nonblocking Statements (2/2) module block_nonblock(); reg a, b, c, d, e, f; // Blocking assignments initial begin a = #10 1'b1; // The simulator assigns 1 to a at time 10 b = #20 1'b0; // The simulator assigns 0 to b at time 30 c = #40 1'b1; // The simulator assigns 1 to c at time 70 end // Nonblocking assignments initial begin d <= #10 1'b1; // The simulator assigns 1 to d at time 10 e <= #20 1'b0; // The simulator assigns 0 to e at time 20 f <= #40 1'b1; // The simulator assigns 1 to f at time 40 end endmodule 10

Data Types (1/3) wire Used as inputs and outputs within an actual module declaration. Must be driven by something, and cannot store a value without being driven. Cannot be used as the left-hand side of an = or <= sign in an always@ block. The only legal type on the left-hand side of an assign statement. Only be used to model combinational logic. 11

Data Types (2/3) reg Can be connected to the input port (but not output port) of a module instantiation. Can be used as outputs (but not input) within an actual module declaration. The only legal type on the left-hand side of an always@ (or initial) block = or <= sign. Can be used to create registers when used in conjunction with always@(posedge Clock) blocks. Can be used to create both combinational and sequential logic. 12

Data Types (3/3) data declaration wire [15:0] longdata; // 16-bit wire wire shortvalue; // 1-bit wire reg [3:0] areg; //4-bit reg wire reg assign longdata = areg + 88; always@(*) begin if(shortvalue == 1'b1) areg = shortvalue + 3; else areg = shortvalue + 7; end logic behavior 13

Value Set 0 - logic zero, or false condition 1 - logic one, or true condition z - high-impedance state x - unknown logic value unrealistic value in design 0 logic low 1 logic high x unknown z high-impedance 14

Numbers binary('b), decimal('d), hexadecimal('h), octal('o) Format <number>: reg data = 127; '<base><number>: reg data = 'd127; <width>'<base><number> complete format reg data = 659 // decimal 'o7460 // octal 4'b1001 // 4-bit binary 3'b01x // 3-bit with unknown 16'hz // 16-bit high impedance -8'd6 // two s complement of 6 8'd-6 // illegal syntax 4af // illegal (requires 'h) 15

Case-Sensitive Control Suspends subsequent statement execution until any of the specified list of events occurs Support event driven simulation Sensitivity list always@( or or or ) always@(a or b or c ) always@(*) verilog 2001, automatic list generation 16

Operators (1/6) Arithmetic operators +, -, *, /, % Bitwise operators Perform the operation one bit of a operand and its equivalent bit on the other operand to calculate one bit for the result ~, &,, ^, ~^ 17 Arithmetic operators Bitwise operators

Operators (2/6) Unary reduction operators Perform the operation on each bit of the operand and get a one-bit result &, ~&,, ~, ^, ~^ Unary reduction operators &4 b1110 0 &4 b1111 1 Unary reduction AND 4 b0000 0 4 b0001 1 Unary reduction OR ^4 b1111 0 ^4 b1110 1 Unary reduction XOR 18

Operators (3/6) Logical operators operate with logic values Equality operators Logical equality ==,!= Case equality ===,!== Logical negation! Logical &&, example!4 b0100 0!4 b0000 1 Logical operators 19!4 b00z0 x

Operators (4/6) 20

Operators (5/6) Concatenation operator {} Join bits from two or more expressions together Very convenient Multiple layers {{},{} } Replication operator {n{}} a b c d y y = {a[1:0], b[2], c[4,3], d[7:5]} a y y = {{4{a[3]}},a} 21

Operators (6/6) Shift operators <<, >> Relational operators <, <=, >=, > Conditional operator? : if(a <= b) d = 0; else d = 1; d = (a<=b)? 0 : 1 Operator precedence 22

Combinational and Sequential Logics 23

Two Types of Logics (1/2) Combinational Logics data-in data-out instant response fixed arrangement a b c d max max max_ab max max_abcd max_cd 24

Two Types of Logics (2/2) Sequential Logics always and only update at clock edges posedge / negedge memory 1 cycle a a_d1 a_d2 a_d3 D Q D Q D Q clk clk clk clk 25

Case-Sensitive Control (1/2) register in sequential changes only at clock edges always@(posedge clk) begin end always@(negedge clk) begin end with reset signal always @(posedge clk or negedge rst_n) begin... end 26

Case-Sensitive Control (2/2) Sequential Logics always and only update at clock edges posedge / negedge reg [3:0] a, b; // declaration always @(posedge clk or negedge rst_n) begin if(rst_n ==1'b0) begin //registers a <= 4'd0; b <= 4'd0; end else begin a <= next_a; b <= next_b; end 27

The Use of Sequential Circuits? Temporal storage (memory) Split long computation lines timing issue divide circuits into independent stages work at the same time!! Combinational logics handle the computation Sequential logics store inter-stage temporal data 28

Sequential and Combinational Logics Sequential Logic (Register) Combinational Logic Sequential Logic (Register) Combinational Logic Sequential Logic (Register) clk always @(posedge clk) begin if(~rst_n) begin a <= 3'd0; end else begin a <= next_a; end assign c = b [2:0]; assign d = c & 3'b101; always@(a or d) begin sum = a + d;... end 29

Sequential Circuit (1/3) Synchronous reset always @(posedge clk) begin if(~rst_n) begin a <= 8'd0; end else begin a <= next_a; end clk rst_n next_ a a XX 8'h01 8'h5a 8 h00 8 h01 8 h5a 30

Sequential Circuit (2/3) Asynchronous reset always @(posedge clk or negedge rst_n) if(~rst_n) begin a <= 8'd0; end else begin clk a <= next_a; end rst_n next_ a a XX 8'h01 begin 8'h5a 8 h00 8 h01 8 h5a 31

Sequential Circuit (3/3) Synchronous reset Asynchronous reset Prefer Pros Cons Pros Cons Easy to synthesize, just another synchronous input to the design Require a free-running clock, especially at power-up, for reset to occur Does not require a free-running clock Uses separate input on FF, so it does not affect FF data timing Harder to implement, usually a tree of buffers is inserted at P&R Makes static timing analysis and cycle-based simulation more difficult, and can make the automatic insertion of test structures more difficult 32

Module Hierarchy 33

What is a Module? Group circuits into meaningful building blocks Combine highly-related circuits Leave simple i/o interface Easier to reuse / maintain + - Module MUX DFF Abs 34

A Module a b rst_ nclk max D Q rst_n clk maxab module maxab(clk,rst_n,a,b,maxab); input clk; input rst_n; input [3:0] a; input [3:0] b; output [3:0] maxab; reg [3:0] maxab; wire [3:0] next_maxab; module port definition wire, reg declaration always@(posedge clk or negedge rst_n) begin end if (rst_n == 1'b0) begin end maxab <= 4'd0; else begin end sequential logics maxab <= next_maxab; assign next_maxab = (a>b)? a: b; combinational logics endmodule ending your module! 35

Connection Between Modules (1/2) Where you "cut" your design. a b c d max max D Q maxabcd clk max D Q clk D Q clk 36

Connection Between Modules (2/2) a b c d Where you "cut" your design. maxab D Q maxabcd max clk max D Q maxcd clk D Q max clk 37

Module Instantiation Build a module by smaller modules module maxabcd(clk,rst_n,a,b,c,d,maxabcd); input clk; input rst_n; input [3:0] a, b, c, d; output [3:0] maxabcd; wire [3:0] maxab, maxcd; a b c d max max D Q clk D Q clk maxab maxcd max maxabcd D Q clk maxab m1(.clk(clk),.rst_n(rst_n),.a(a),.b(b),.maxab(maxab)); maxab m2(.clk(clk),.rst_n(rst_n),.a(c),.b(d),.maxab(maxcd)); maxab m3(.clk(clk),.rst_n(rst_n),.a(maxab),.b(maxcd),.maxab(maxabcd)); endmodule 38

Write Your Design 39

Use Parameters (1/2) Build a module by smaller modules `define INST_WakeUp 0 `define INST_GoToSleep 1 `define BUS_WIDTH 64 input [`BUS_WIDTH-1:0] databus; case (instruction) `INST_WakeUp: `INST_GoToSleep: endcase 40

Use Parameters (2/2) Use parameter for reusable modules parameter [4:0] FA_BitSize = 8; reg [FA_BitSize-1:0] = datain; Use localparam for inner-module variables localparam FSM_StateSize = 5; localparam [FSM_StateSize-1:0] FSM_Idle = 5'd0; 41

Finite State Machine 42

Finite State Machine (1/2) Synchronous (i.e. clocked) finite state machines (FSMs) have widespread application in digital systems Controllers in computational units and processors. Synchronous FSMs are characterized by A finite number of states Clock-driven state transitions. 43

Finite State Machine (2/2) 44

Elements of FSM (1/2) Memory elements (ME) Memorize current state (CS) Usually consist of FF or latch N-bit FF have 2 N possible states Next-state logic (NL) Combinational logic Produce next state Based on current state (CS) and input (X) 45

Elements of FSM (2/2) Output logic (OL) Combinational logic Produce outputs (Z) Based on current state (Moore) Based on current state and input (Mealy) 46

Moore Machine Output is function of CS only Not function of inputs Input X Next-state Logic (NL) Next State (NS) Memory Element (ME) Current State (CS) Output Logic (OL) Output X 47

Mealy Machine Output is function of both Input and current state Input X Next-state Logic (NL) Next State (NS) Memory Element (ME) Current State (CS) Output Logic (OL) Output X 48

Modeling FSM in Verilog Sequential circuits Memory elements of current state (CS) Combinational circuits Next-state logic (NL) Output logic (OL) 49

The End. Any question?

Reference 1. "Verilog_Coding_Guideline_Basic" by members of DSP/IC Design Lab 2. http://inst.eecs.berkeley.edu/~cs150/docume nts/nets.pdf by Chris Fletcher, UC Berkeley 3. CIC training course: "Verilog_9807.pdf" 4. http://www.asic-world.com/ 51