Lecture 15: System Modeling and Verilog

Similar documents
Synthesizable Verilog

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

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

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

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

Introduction to Verilog HDL. Verilog 1

Digital Design with FPGAs. By Neeraj Kulkarni

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

Verilog Tutorial (Structure, Test)

Contents. Appendix D Verilog Summary Page 1 of 16

A Brief Introduction to Verilog Hardware Definition Language (HDL)

Lecture 32: SystemVerilog

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

EEL 4783: HDL in Digital System Design

Chap 6 Introduction to HDL (d)

Writing Circuit Descriptions 8

Verilog introduction. Embedded and Ambient Systems Lab

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

CSE140L: Components and Design Techniques for Digital Systems Lab

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

Verilog 1 - Fundamentals

CSE140L: Components and Design

EECS150 - Digital Design Lecture 10 Logic Synthesis

VLSI Design 13. Introduction to Verilog

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

Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

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

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

Online Verilog Resources

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

TOPIC : Verilog Synthesis examples. Module 4.3 : Verilog synthesis

Introduction to Verilog

Digital Design with SystemVerilog

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

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

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

Verilog Fundamentals. Shubham Singh. Junior Undergrad. Electrical Engineering

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

EN2911X: Reconfigurable Computing Topic 02: Hardware Definition Languages

Lecture #2: Verilog HDL

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

EECS150 - Digital Design Lecture 10 Logic Synthesis

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

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

Chapter 2a: Structural Modeling

Verilog for Synthesis Ing. Pullini Antonio

Introduction to Digital Design with Verilog HDL

VHDL: RTL Synthesis Basics. 1 of 59

EECS150 - Digital Design Lecture 5 - Verilog Logic Synthesis

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

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

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

Verilog 1 - Fundamentals

Introduction To HDL. Verilog HDL. Debdeep Mukhopadhyay Dept of CSE, IIT Madras 1

Quick Introduction to SystemVerilog: Sequental Logic

Hardware Description Language (HDL)

HDL. Hardware Description Languages extensively used for:

Hardware description languages

Introduction to Verilog/System Verilog

Advanced Digital Design Using FPGA. Dr. Shahrokh Abadi

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

VERILOG QUICKSTART. Second Edition. A Practical Guide to Simulation and Synthesis in Verilog

CSE 2021 Computer Organization. The Basics of Logic Design

Modeling Sequential Circuits in Verilog

CS6710 Tool Suite. Verilog is the Key Tool

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

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

Synthesis of Combinational and Sequential Circuits with Verilog

ECE 551: Digital System *

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

101-1 Under-Graduate Project Digital IC Design Flow

MLR Institute of Technology

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

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

Sequential Logic Design

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

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

Introduction To Verilog Design. Chun-Hung Chou

Concepts of Digital Design Introduction to Verilog

VHDL VS VERILOG.

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

Register Transfer Level in Verilog: Part I

ECEN 468 Advanced Logic Design

14. Introducton to Verilog

ECE 4514 Digital Design II. Spring Lecture 15: FSM-based Control

Combinational Logic II

Verilog Design Principles

CAD for VLSI Design - I. Lecture 21 V. Kamakoti and Shankar Balachandran

HDLs and SystemVerilog. Digital Computer Design

Blocking(=) vs Nonblocking (<=) Assignment. Lecture 3: Modeling Sequential Logic in Verilog HDL. Procedural assignments

Sunburst Design - Verilog-2001 Design & Best Coding Practices by Recognized Verilog & SystemVerilog Guru, Cliff Cummings of Sunburst Design, Inc.

Verilog for High Performance

Recommended Design Techniques for ECE241 Project Franjo Plavec Department of Electrical and Computer Engineering University of Toronto

INSTITUTE OF AERONAUTICAL ENGINEERING Dundigal, Hyderabad ELECTRONICS AND COMMUNICATIONS ENGINEERING

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

DIGITAL SYSTEM DESIGN

14. Introducton to Verilog

ECE 4514 Digital Design II. Spring Lecture 2: Hierarchical Design

CS429: Computer Organization and Architecture

Two HDLs used today VHDL. Why VHDL? Introduction to Structured VLSI Design

Transcription:

Lecture 15: System Modeling and Verilog Slides courtesy of Deming Chen Intro. VLSI System Design

Outline Outline Modeling Digital Systems Introduction to Verilog HDL Use of Verilog HDL in Synthesis Reading Appendix A Slide 2

Model Digital Systems Digital system: Any digital circuit that processes or stores information in digital form: gates to functional units. Model represents only relevant information and abstracts away irrelevant data. Model needed to Specify requirements Communicate understanding of a system to a user Allow testing of design through simulation Allow formal verification Allow automated synthesis Slide 3

Level of Modeling Slide 4

Introduction to Verilog Invented around 1983 84 by Gateway Design Automation Gateway was bought by Cadence in 1989, and Verilog HDL became a public language Standard is Open Verilog International (OVI) IEEE 1364 Verilog-based synthesis tool introduced by Synopsys in 1987 Verilog HDL is NOT a programming language, although it looks like a mixture of C, PASCAL, and ADA constructs In contrast to these languages, Verilog HDL models, represents, and simulates the functional behavior and timing of hardware Supported logic levels are 0, 1, x (undefined), and z (floating, i.e.: not driven by 0 or 1) Slide 5

Verilog HDL Modeling Structural models Any hierarchy based on modules containing gates, primitives, or instances of other modules Modules are the basic unit of hardware description Modules can not be defined within other modules Behavioral models Behavioral description on all levels from the Algorithmic level and Register-Transfer level (RTL), down to Boolean Equations Widely used for RTL synthesis (Verilog RTL Verilog gate netlist) Verilog supports all design steps down to gate level simulations using layout-extracted timing information Slide 6

Built-in Logic Gates (Verilog Primitives) and, or, xor, xnor, nand, nor, not, buf and and1 (out1, in1, in2, in3); xor xor1 (out2, in4, in5); not not1 (out3, in6); bufif1, bufif0, notif1, notif0 (tristate buffers and inverters) bufif1 b1 (out, in, ctrl) Slide 7

Basic Gates Syntax GATE (drive_strength) # (delays) instance_name1 (output, input_1, input_2,..., input_n) Delays is # (rise, fall) or # rise_and_fall or # (rise_and_fall) Slide 8

Module Example Typically inputs are wire since their data is latched outside the module. Outputs are type reg if their signals were stored inside an always or initial block Slide 9

Modeling Combinational Logic Example: Half-Adder Structural model Behavioral model module halfadder (sum, cout, a, b); module halfadder (sum, cout, a, b); output sum, cout; output sum, cout; input a, b; input a, b; wire cbar; assign cout = a & b; xor I1(sum, a, b); assign sum = a^b; nand I2(cbar, a, b); endmodule not I3(cout, cbar); endmodule Slide 10

Modeling Circuit Timing Example: NAND-Gate using Gate-Propagation Delay timescale 1ns/100ps; module nand2 (y, a, b); output y; input a, b; nand #1 I1 (y, a, b); endmodule timescale is read by simulator and applied to all following modules until next timescale directive occurs 1ns: Unit used for delay specifications delay for nand I1 is 1 ns 100ps: Timestep for the simulator (i.e., timing precision of simulator) Slide 11

Modeling Wire Delays Example: Long wire connected to gate output module some_function (out, in1, in2); parameter wire_delay = 2; parameter gate_delay = 1; output out; input in1, in2; wire #wire_delay out; some_gate #gate_delay I1 (out, in1, in2); Endmodule Wire delays can be modeled independently from gate delays A wire does not store its value but must be driven by a continuous assignment statement or by connecting it to the output of a gate or module. A parameter defines a constant that can be set when you instantiate a module. Slide 12

Constants Slide 13

Blocking vs. Nonblocking Assignments Verilog simulators work sequentially, while hardware is inherently parallel To model closer to hardware, nonblocking assignments can be used that work similar to fork join in C language Blocking assignments (=) are done sequentially in the order the statements are written. A second assignment is not started until the preceding one is complete. Nonblocking assignments (<=), which follow each other in the code, are done in parallel. Blocking /* grab inputs now, deliver ans. later. */ a=1; b=2; c=3; #5 a = b + c; // wait for 5 units, and execute a = b + c = 5. d = a; // time continues from last line, d = 5 = b+c at t = 5. Non-Blocking #3 b <= a; /* grab a at t = 0; Deliver b at t = 3. #6 x <= b + c; // grab b+c at t = 0, wait and assign x at t = 6. /* x is unaffected by b s change. */ Slide 14

<= and = For synthesis One must not mix <= or = in the same procedure. <= best mimics what physical flip-flops do; use it for always @ (posedge clk..) type procedures. = best corresponds to what c/c++ code would do; use it for combinational procedures. For simulation, no such constraints. Slide 15

Modeling Sequential Logic Example: Behavioral description of D-Flip-Flop module dff_rs (q, qbar, d, clk, set, reset); output q, qbar; reg q; input d, clk, set, reset; wire qbar; assign qbar =!q; always @(posedge clk) begin if (reset == 1 b1) q <= 1 b0; // i.e., q = 0 else if (set == 1 b1) q <= 1 b1; else q <= d; end endmodule Slide 16

Translation of Verilog Constructs always blocks are re-evaluated only when signals in the header (called a sensitivity list) change. always statement can infer sequential and combinational logic Positive edge-triggered flip-flop inferred always @(posedge clk) q <= d; Level-sensitive latch inferred always @(clk or d) if (clk) q <= d; Combinational logic inferred always @(a or b or c_in) {c_out, sum} <= a + b + c_in; Slide 17

Translation of Verilog Constructs assign statements are translated to equivalent combinational logic assign out = (a & b) c; translated to a 2-input and gate feeding a 2-input or gate if-else statement translated to a mux case statement translated to a mux for loops used to build cascaded combinational logic c = c_in; for (i = 0; i <= 7; i = i + 1) {c, sum[i]} = a[i] + b[i] + c; // 8-bit ripple adder c_out = c; Slide 18

Example: Generic Parameterized Adder module adder (cout, sum, a, b, cin); parameter width=4; output[width-1:0] sum; output cout; reg[width-1:0] sum; reg[width-1:0] c; input[width-1:0] a, b; input cin; wire cout; integer n; assign cout = c[width-1]; always @(a or b or cin) for (n = 0; n <= (width-1); n = n+1) if (n == 0) {c[0], sum[0]} = a[0] + b[0] + cin; else {c[n], sum[n]} = a[n] + b[n] + c[n-1]; endmodule Slide 19

Example: Decoder module decoder ( input [2:0] a, // how does it look like? output reg [7:0] y); // a 3:8 decoder always @(*) case (a) 3 b000: y <= 8 b00000001 3 b001: y <= 8 b00000010; 3 b010: y <= 8 b00000100; 3 b011: y <= 8 b00001000; 3 b100: y <= 8 b00010000; 3 b101: y <= 8 b00100000; 3 b110: y <= 8 b01000000; 3 b111: y <= 8 b10000000; endcase endmodule Slide 20

Initial Block Build a test sequence for verification Sequential evaluation LHS use register/integer Delays initial begin #1 reset = 0; # 4 reset = 1; # 5 reset = 0; end // draw the timing graph Slide 21

Verifying a Verilog Model Through Simulation Verilog Stimulus for the instance toplevel module timescale 1ns/100ps reg in1, in2, clk; wire out; toplevel_module I1 (clk, in1, in2, out); initial // Define clk begin clk = 1 b0; forever #50 clk = ~clk; end initial begin $monitor ($time, clk, in1, in2, out); in1 = 1 b0; in2 = 1 b0; #125 in1 = 1 b1; @(negedge clk) in2 = 1 b1; #200 $finish; end Slide 22

Continue from previous slide If toplevel module represents always @(posedge clk) out =!(a&b), the generated output is: Slide 23

Use of Verilog HDL in Synthesis Synthesis usually refers to RTL synthesis, i.e., the transformation from RTL to gate level While Verilog HDL is a powerful language (even with object- oriented constructs as in C++), only a mostly structural subset of Verilog HDL is synthesizable. If you can t imagine hardware behind your code, you can t synthesize it Parentheses should be used to group logic Need to provide cycle-by-cycle RTL description Delays are ignored by synthesis tools Slide 24

Verilog Modeling Tips for Logic Synthesis RTL specification should be as close as possible to desired structure Meaningful names should be used for signals and variables Mixing of positive and negative edge-triggered flipflops should be avoided Result in buffers and inverters in clock tree, which contribute to clock skew Avoid multiple assignments to the same variable Define if-else and case statements explicitly Latches may be inferred if all conditions are not specified. Slide 25

Inferring Latches in Combinational Logic module wrong (out, in1, in2); module right (out, in1, in2); output out; output out; reg out; reg out; input in1, in2; input in1, in2; always @(in1 or in2) always @(in1 or in2) case ({in1,in2}) case ({in1,in2}) 2 b00 : out = 0; 2 b00 : out=0; 2 b01 : out = 1; 2 b01 : out=1; 2 b10 : out = 1; 2 b10 : out=1; default: out=x; endcase endcase endmodule endmodule Module wrong infers one latch Slide 26

Finite State Machine Design Finite-state machines (FSMs) are either Moore- or Mealy- machines FSMs can be described using a separate combinational part for output decoding and generation of next state logic and a sequential part to generate present state logic Consider the following Mealy machine (input/output): Mealy machine: output depends on present state and input Slide 27

Example of Synthesizable Mealy Machine It is always important to verify equivalence between different levels of the design. module fsm (clk, reset, in, out); input clk, reset, in; output out; reg out; reg[1:0] present_state, next_state; parameter[1:0] S0=2 b00, S1=2 b01, S2=2 b10, S3=2 b11; always @(posedge clk) begin if (reset == 1) present_state = S0; else present_state = next_state; end Slide 28

Continued always @(present_state or in) begin case(present_state) S0: if (in == 1) next_state = S1; else next_state = S0; S1: if (in == 1) next_state = S2; else next_state = S1; S2: if (in == 1) next_state = S3; else next_state = S2; S3: if (in == 1) next_state = S0; else next_state = S3; default: next_state = S0; endcase end Slide 29

Continued: output decoding always @(present_state or next_state) begin if ((present_state == S3) && (next_state == S0)) out=1; else out=0; end endmodule Slide 30

MP2. Controller controller.v: complete your logic module controller( ); i, // opcode // add your decoded signals a,b,select_a_hi,select_b_hi, f,c,p,g_lo,p_lo,ovr,z, y_tri,y_data,oe, ram0,ram3, q0,q3,q0_data,q3_data //,reg_wr // add additional signals for your design here // decoding of register addresses // generation of ALU outputs // tristate control of y bus // tristate control of RAM shifter // tristate control of Q shifter Slide 31

Continued: MP2. Controller Controller.v: complete your logic // define I/O for synthesized control input [8:0] i; input [3:0] a, b; output [15:0] select_a_hi, select_b_hi; input [3:0] f, c, p; output g_lo, p_lo, ovr, z; inout [3:0] y_tri; input [3:0] y_data; input oe; inout ram0, ram3, q0, q3; input q0_data, q3_data; //output reg_wr // define additional I/Os for your design Slide 32

Continued: MP2. Controller // named internal wires carry reusable subexpressions wire shift_left, shift_right; // "assign" statements give us algebraic expressions assign select_a_hi = 16'h0001 << a; assign select_b_hi = 16'h0001 << b; assign shift_left = i[8] & i[7]; assign shift_right = i[8] & ~ i[7]; Slide 33

Continued: MP2. Controller // simpler functionality is better implemented directly in logic gates buf calcg( g_lo, matter for us :v) ~c[3] ); // glitchy with lookahead carry propagation, but shouldn't nand calcp( p_lo, p[3], p[2], p[1], p[0] ); xor calcovr( ovr, c[3], c[2] ); nor calczero( z, f[3], f[2], f[1], f[0] ); bufif1 drvy3( y_tri[3],y_data[3], oe ); bufif1 drvy2( y_tri[2],y_data[2], oe ); bufif1 drvy1( y_tri[1],y_data[1], oe ); bufif1 drvy0( y_tri[0],y_data[0], oe ); bufif1 drvraml( ram3, f[3], shift_left ); bufif1 drvramr( ram0, f[0], shift_right ); bufif1 drvqshl( q3, q3_data, shift_left ); bufif1 drvqshr( q0, q0_data, shift_right ); Slide 34

Continued: MP2. Controller Controller.v: complete your logic // add your control signals here... //assign reg_wr = ; //end endmodule Slide 35

MP2. AM2901 Am2901.v module Am2901(cp,i,cin,cout,g_lo,p_lo,ovr,z,f3,d, y,a,b,ram0,ram3,q0,q3,oe); // define chip pins input cp; input [8:0] i;... Am2901.v: Connect controller + datapath // clock // opcode // define signals between control and datapath wire [15:0] select_a_hi, select_b_hi; // add your signals (wires) module controller( ); controller.v i, // opcode // added signals // define I/O for synthesized control input [8:0] i; // defined additional I/Os for your design endmodule Slide 36

Continued: MP2. AM2901 module Am2901( ); Am2901.v controller control ( // instantiate either RTL (MP2) or synthesized logic (MP3) ); Am2901.v: Connect controller + datapath.i(i), // opcode // add your decoded signals module controller( ); controller.v i, // opcode // added signals // define I/O for synthesized control input [8:0] i; // defined additional I/Os for your design endmodule Slide 37

Continued: MP2. AM2901 module Am2901( ); Am2901.v datapath data ( // instantiate your design schematics from Virtuoso ); Am2901.v: Connect controller + datapath.cp(cp), // clock // add your decoded signals endmodule module controller( ); controller.v i, // opcode // added signals // define I/O for synthesized control input [8:0] i; // defined additional I/Os for your // design endmodule Slide 38