Introduction to Digital Design with Verilog HDL

Similar documents
Verilog Tutorial (Structure, Test)

Programmable Logic Devices Verilog VII CMPE 415

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

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

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

Online Verilog Resources

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

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

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

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

Course Topics - Outline

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

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

OVERVIEW: ============================================================ REPLACE

ECEN 468 Advanced Logic Design

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

CSE140L: Components and Design Techniques for Digital Systems Lab

CSE140L: Components and Design

Under-Graduate Project Logic Design with Behavioral Models

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

EEL 4783: HDL in Digital System Design

Synthesizable Verilog

Contents. Appendix D Verilog Summary Page 1 of 16

Chapter 2a: Structural Modeling

Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

Advanced Digital Design Using FPGA. Dr. Shahrokh Abadi

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

P-1/P-105. Samir Palnitkar. Prentice-Hall, Inc. INSTRUCTOR : CHING-LUNG SU.

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

CS6710 Tool Suite. Verilog is the Key Tool

UNIT V: SPECIFICATION USING VERILOG HDL

Verilog HDL Introduction

Chap 6 Introduction to HDL (d)

EECS150 - Digital Design Lecture 10 Logic Synthesis

RIZALAFANDE CHE ISMAIL TKT. 3, BLOK A, PPK MIKRO-e KOMPLEKS PENGAJIAN KUKUM. SYNTHESIS OF COMBINATIONAL LOGIC (Chapter 8)

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

Verilog Behavioral Modeling

VERILOG QUICKSTART. James M. Lee Cadence Design Systems, Inc. SPRINGER SCIENCE+BUSINESS MEDIA, LLC

EECS150 - Digital Design Lecture 10 Logic Synthesis

Verilog Design Principles

Introduction To Verilog Design. Chun-Hung Chou

Lecture 15: System Modeling and Verilog

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

Verilog HDL. A Guide to Digital Design and Synthesis. Samir Palnitkar. SunSoft Press A Prentice Hall Title

EN2911X: Reconfigurable Computing Topic 02: Hardware Definition Languages

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

Hardware Description Language (HDL)

Brief Introduction of Cell-based Design. Ching-Da Chan CIC/DSD

Digital System Design Verilog-Part III. Amir Masoud Gharehbaghi

Graduate Institute of Electronics Engineering, NTU Basic Concept of HDL

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

Gate level or structural modeling

CS6710 Tool Suite. Verilog is the Key Tool. Verilog as HDL (AHT) Verilog has a Split Personality. Quick Review. Synthesis

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

CSE 2021 Computer Organization. The Basics of Logic Design

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

Course Topics - Outline

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

Chapter 2 Using Hardware Description Language Verilog. Overview

Introduction to Verilog/System Verilog

VLSI Design 13. 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

14. Introducton to Verilog

Veriolog Overview. CS/EE 3710 Fall 2010

Verilog Design Principles

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

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

Appendix A GATE-LEVEL DETAILS

Combinational Logic II

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

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

Advanced Digital Design with the Verilog HDL

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

Synthesis of Combinational and Sequential Circuits with Verilog

Design Using Verilog

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

A Tutorial Introduction 1

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

The Verilog Hardware Description Language

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

Digital Design (VIMIAA01) Introduction to the Verilog HDL

Digital Design with SystemVerilog

Verilog introduction. Embedded and Ambient Systems Lab

Introduction to Verilog

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

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

Actel HDL Coding. Style Guide

Chap 3. Modeling structure & basic concept of Verilog HDL

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

Verilog Fundamentals. Shubham Singh. Junior Undergrad. Electrical Engineering

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

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

ES611 FPGA Based System Design. Behavioral Model

Verilog for Synthesis Ing. Pullini Antonio

Contents of Verilog Reference Guide

ECEN 468 Advanced Logic Design

Introduction to Verilog

The Verilog Golden Reference Guide

Actel HDL Coding. Style Guide

430 Index. D flip-flop, from nands, 189, 191, 192 D flip-flop, verilog, 37

Transcription:

Introduction to Digital Design with Verilog HDL Modeling Styles 1

Levels of Abstraction n Behavioral The highest level of abstraction provided by Verilog HDL. A module is implemented in terms of the desired design algorithm n Data Flow At this level the module is designed by specifying the data flow n Gate Level The module is implemented in terms of logic gates and interconnections between these gates n Switch Level This is the lowest level of abstraction provided by Verilog. A module can be implemented in terms of switches, storage nodes and the interconnections between them 2

Behavioral Modeling n Behavioral modeling n Data flow modeling n Gate level modeling n Switch level modeling n Others 3

Behavioral Modeling n Blocks always Event-based timing control Branch case, casex, casez 4

Behavioral Modeling: always Block Syntax always operation_name module pulse; reg clock; Example // start the clock at 0 initial clock = 1'b0; /* toggle every 10 time units*/ always #10 clock = ~clock; endmodule 5

Behavioral Modeling: Event-based Timing Control Syntax Example @(event) op_name @ (clock) a = b; when the clock changes value, execute a = b @ (negedge clock) a = b; when the clock change to a 0, execute a=b a = @(posedge clock) b; evaluate b immediately and assign to a on a po sitive clock edge. 6

Behavioral Modeling: Branch Statements Syntax if (conditional_expression) statement1 else statement2 Example if (x!=1) a=2; else a=5; 7

Behavioral Modeling: Case Syntax case(op) op1:operation1 op2:operation2 op3:operation3 op4:operation4 default:operation5 endcase Example case(s3) 00:A=00 01:A=01 10:A=10 11:A=11 default:operation5 endcase 8

Behavioral Modeling: casex, casez n Two variations of the case statement casez Treats all z values in the case alternatives or the case expression as don't cares, all bit positions with z can also be represented by? in that position casex Treats all x and z values in the case item or the case expression as don't cares reg [3:0] encoding; integer state; casex (encoding) 4'b1xxx : next_state = 3; 4'bx1xx : next_state = 2; 4'bxx1x : next_state = 1; 4'bxxx1 : next_state = 0; default : next_state = 0; endcase An input encoding = 4'b10xz would cause next_state = 3 to be executed 9

Behavioral Modeling n Definition of blocking and non-blocking procedural assignments n Delay-based timing control mechanism in behavioral modeling n The significance of structured procedures always and initial in behavioral modeling n Event-based timing control mechanism in behavioral modeling n Level-sensitive timing control mechanism in behavioral modeling n Conditional statements using if and else n Multiway branching, using case, casex, and casez statements n Looping statements while, for, repeat, and forever n Sequential and parallel blocks 10

Procedural Assignments n Update values of reg, integer, real, or time variables Blocking Non-blocking 11

Procedural Assignments: Blocking n Blocking assignment statements are executed in the order they are specified in a sequential block n A blocking assignment will not block execution of statements that follow in a parallel block n The = operator is used to specify blocking assignments reg x, y, z; reg [15:0] reg_a, reg_b; integer count; initial begin end x = 0; y = 1; z = 1; // time 0 count = 0; // time 0 reg_a = 16'b0; // time 0 reg_b = reg_a; // time 0 #15 reg_a[2] = 1'b1; // time 15 #10 reg_b[15:13] = {x, y, z}; // time 25 count = count + 1; // time 25 12

Procedural Assignments: Non-Blocking n Non-blocking assignments allow scheduling of assignments without blocking execution of the statements that follow in a sequential block n A <= operator is used to specify non-blocking assignments reg x, y, z; reg [15:0] reg_a, reg_b; integer count; initial begin x = 0; y = 1; z = 1; // time 0 count = 0; // time 0 reg_a = 16'b0; // time 0 reg_b = reg_a; // time 0 reg_a[2] <= #15 1'b1; // time 0, but assigned at time 15 reg_b[15:13] <= #10 {x, y, z}; // time 0, but assigned at time 10 count <= count + 1; // time 0, assigned at time 0 end 13

Blocking vs. Nonblocking Assignments 14

Assignment Styles for Sequential Logic 15

Use Nonblocking for Sequential Logic 16

Simulation 17

Use Blocking for Combinational Logic 18

The Sequential always Block 19

Importance of the Sensitivity List 20

Simulation 21

Design a 4 to 1 MUX Using if Statement module multiplexor4_1 (out, in1, in2, in3,in4, cntrl1, cntrl2); output out; input in1, in2, in3, in4, cntrl1, cntrl2; reg out; // Note that this is now a register always @(in1 or in2 or in3 or in4 or cntrl1 or cntrl2) if (cntrl1==1) if (cntrl2==1) out = in4; else out = in3; else if (cntrl2==1) out = in2; else out = in1; endmodule 22

Design a 4 to 1 MUX using case Statement module multiplexor4_1 (out, in1, in2, in3, in4, cntrl1, cntrl2); output out; input in1, in2, in3, in4, cntrl1, cntrl2; reg out; // note must be a register always @(in1 in2 in3 in4 cntrl1 cntrl2) case ({cntrl2, cntrl1}) // concatenation 2'b00 : out = in1; 2'b01 : out = in2; 2'b10 : out = in3; 2'b11 : out = in4; default : $display("please check control bits"); endcase endmodule 23

Data Flow Modeling n Behavioral modeling n Data flow modeling n Gate level modeling n Switch level modeling n Others 24

Data Flow Modeling n Describe the continuous assignment (assign) statement n Assignment delay, implicit assignment delay, net declaration delay n Expressions, operators, operands (already mentioned) n Examples of digital circuits modeling in Verilog 25

assign Statement n assign out = in1 & in2; Continuous assign Out is a net i1 and i2 are nets n assign addit[15:0] = addit1[15:0] ^ addit2[15:0]; Continuous assign for vector nets, addr is a 16 bit vector net Addi1 and addit2 are 16-bit vector registers n assign {cout, sum[3:0]} = a[3:0] + b[3:0] + cin; Concatenation Left-hand side is a concatenation of a scalar net and a vector net 26

Delays n Delay values control the time between the change in a right-hand-side operand and when the new value is assigned to the left-hand side. Regular assignment delay Implicit continuous assignment delay Net declaration delay 27

Implicit Net Declaration n If a signal name is used to the left of the continuous assignment, an implicit net declaration will be inferred for that signal name. n If the net is connected to a module port, the width of the inferred net is equal to the width of the module port. // Continuous assign. out is a net. wire i1, i2; assign out = i1 & i2; Out was not declared as a wire, but an implicit wire declaration for out is done by the simulator 28

Regular Assignment Delay 1. When signals in1 and in2 go high at time 20, out goes to a high 10 time units later (time = 30). 2. When in1 goes low at 60, out changes to low at 70. 3. However, in1 changes to high at 80 but it goes down to low before 10 time units have elapsed. 4. Hence at the time of recomputation, 10 units after time 80, in1 is 0. Thus, out gets the value 0. A pulse of width less than the specified assignment delay is not propagated to the output. in1 in2 out xxxxx time 10 20 30 60 70 80 85 29

Implicit Continuous Assignment Delay n An equivalent method is to use an implicit continuous assignment to specify both a delay and an assignment on the net //implicit continuous assignment delay wire #10 out = in1 & in2; //same as wire out; assign #10 out = in1 & in2 30

Net Declaration Delay n A delay can be specified on a net when it is declared without putting a continuous assignment on the net. n If a delay is specified on a net out, then any value change applied to the net out is delayed accordingly. Net declaration delays can also be used in gate-level modeling. //Net Delays wire # 10 out; assign out = in1 & in2; //The above statement has the same effect as the following. wire out; assign #10 out = in1 & in2; 31

Logic Statement Implementation module multiplexor4_1 (out, in1, in2, in3,in4, cntrl1, cntrl2); output out; input in1, in2, in3, in4, cntrl1, cntrl2; assign out = (in1 & ~cntrl1 & ~cntrl2) (in2 & ~cntrl1 & cntrl2) (in3 & cntrl1 & ~cntrl2) (in4 & cntrl1 & cntrl2); endmodule 32

The Conditional Operator Syntax conditional_expression? true_expression : false_expression; Example module multiplexor4_1 (out, in1, in2, in3, in4, cntrl1, cntrl2); output out; input in1, in2, in3, in4, cntrl1, cntrl2; assign out = cntrl1? (cntrl2? in4 : in3) :(cntrl2? in2 : in1); endmodule 33

Gate Level Modeling n Behavioral modeling n Data flow modeling n Gate level modeling n Switch level modeling n Others 34

Gate Level Modeling n Identify logic gate primitives provided in Verilog n Truth tables for and/or, buf/not and bufif/notif type gates n Examples of gate-level designs n Rise, fall and turn-off delays in the gate-level design 35

Gate Types n and/or n buf/not n bufif/notif n User-Defined Primitive (UDP) 36

Gate Types: and/or, buf/not Gates and/or gates buf/not gates 37

Gate Types: Examples wire OUT, IN1, IN2, IN3; // Basic gate instantiations and gate1(out, IN1, IN2); nand gate2(out, IN1, IN2); or gate3(out, IN1, IN2); nor gate4(out, IN1, IN2); xor gate5(out, IN1, IN2); xnor gate6(out, IN1, IN2); // More than 2 inputs: 3 input and gate and gate7(out, IN1, IN2, IN3); // Gate instantiation without instance name nand(out, IN1, IN2); // This is also a legal instantiation 38

Gate Types: bufif, notif in out in out bufif1 control notif1 control in out out bufif0 control notif0 control 39

Gate Types: Examples (2) n Examples of gate instantiations wire OUT, IN, CONTROL; // Basic instantiations of bufif gates bufif1 b_1(out, IN, CONTROL); bufif0 b_0(out, IN, CONTROL); // Basic instantiations of notif gates notif1 n_1(out, IN, CONTROL); notif0 n_0(out, IN, CONTROL); 40

Truth Tables for bufif/notif Gates control control BUFIF1 0 1 x z BUFIF0 0 1 x z 0 z 0 L L 0 0 z L L in 1 z 1 H H in 1 1 z H H x z x x x x x z x x z z x x x z x z x x control control NOTIF1 0 1 x z NOTIF0 0 1 x z 0 z 1 H H 0 1 z H H in 1 z 0 L L in 1 0 z L L x z x x x x x z x x z z x x x z x z x x 41

Gate Delays n Rise delay is associated with a gate output transition to 1 from another value. n Fall delay is associated with a gate output transition to 0 from another value. n Turn-off delay is associated with a gate output transition to the high impedance value (z) from another value. t_rise t_fall 42

Gate Delays (2) n Delay specifications One delay is specified its value is used for all transitions Two delays are specified they refer to rise and fall delay values respectively Three delays are specified they refer to rise, fall and turn-off delay values respectively Default value is zero 43

Gate Delays (3): Example // Delay is equal to trans_delay for all transitions nand #(trans_delay) g1(out, in1, in2); // Rise and Fall delays are specified and #(rise_delay, fall_delay) g2(out, in1, in2); // Rise, Fall and Turn-off delays are specified bufif0 #(5,7,9) b1(out, in, control); 44

User-Defined Primitives (UDPs) Symbol Interpretation Comments 0 Logic 0 1 Logic 1 x Unknown value Not permitted in output field. b Substitute for 0 and 1 Not permitted in output field.? Substitute for 0, 1, and x Not permitted in output field. - No change Permitted only in output field of sequential UDPs. (vw) * Transition from v to w value Same as (??) All transitions r Same as (01) f Same as (10) p n Same as (01), (0x), (x1) Same as (10), (1x), (x0) Permitted only in input field of sequential UDPs. v and w can be 0, 1, x, b, and? Any value change on input. Permitted only in input field of se quential UDPs. Rising edge on input. Permitted only in input field of sequenti al UDPs. Falling edge on input. Permitted only in input field of sequent ial UDPs. Positive edge on input. Permitted only in input field of seque ntial UDPs. Negative edge on input. Permitted only in input field of seque ntial UDPs. 45

User-Defined Primitives (UDPs) (2) n Latch with asyncronous reset primitive latch (q, clock, reset, data); input clock, reset, data; output q; reg q; initial q=1 b1; //initialization table // clock reset data q q+? 1? :? : 1 ; 0 0 0 :? : 0 ; 1 0? :? : - ; 0 0 1 :? : 1 ; endtable endprimitive 46

User-Defined Primitives (UDPs) (3) primitive mux (o, i3, i2, i1, i0, a1, a0); output o; input i3, i2, i1, i0, a1, a0; table // i3 i2 i1 i0 a1 a0 : o; 0??? 1 1 : 0; 1??? 1 1 : 1;? 0?? 1 0 : 0;? 1?? 1 0 : 1;?? 0? 0 1 : 0;?? 1? 0 1 : 1;??? 0 0 0 : 0;??? 1 0 0 : 1; endtable endprimitive 47

Ports n Descriptions ports provide the interface by which a module can communicate with its environment n Types input, output or inout (implicitly all are declared as wire in Verilog) n Port Data Types input or inout ports cannot be of type reg, because reg variables store values input ports should only reflect the changes of external signals they are connected to module DFF (dout,din,clk,resetn); output dout; input din,clk,resetn; reg dout; // As the output of D FF holds value it is declared as reg always @(posedge clk or negedge resetn) if (~resetn) dout<=0; else dout<=din; endmodule 48

Port Connection Rules n Ports Inputs Internally, input ports must always be of the type net Externally, the inputs can be connected to a variable which is reg or net Outputs Internally, output ports can be of the type reg or net Externally, the outputs must always be connected to a net Inouts Internally, inout ports must always be of the type net Externally, inout ports must always be connected to a net 49

Port Connection Rules (3) n Connections By order By name 50

Port Connection Rules: By Order Example module TOP; reg data_in,clock,resetn; wire data_out; // In the following block DFF module is instantiated // and is called DFF_TEST // Signals are connected to ports in order DFF DFF_TEST (data_out,data_in,clock,resetn); <Stimulus> endmodule 51

Port Connection Rules: By Name n Connecting ports by name In large designs where the number of ports is great it may seem hard to use the ordered method of port connection Verilog provides the capability to connect external signals to ports by the port names As long as the port name is not changed the order of ports in the port list of a module can be rearranged without changing the port connections in module instantiations DFF DFF_TEST(.din(data_in),.dout(data_out),.resetn(resetn),.clk(clock)); 52

Gate Level Implementation of a 4 to 1 MUX in1 w in2 x out in3 y in4 z cntrl1 cntrl2 53

Gate Level Implementation of a 4 to 1 MUX : Verilog Description module multiplexor4_1(out, in1, in2, in3, in4, cntrl1, cntrl2); output out; input in1, in2, in3, in4, cntrl1, cntrl2; wire notcntlr1, notcntrl2, w, x, y, z; not (notcntrl1, cntrl1); not (notcntrl2, cntrl2); and (w, in1, notcntrl1, notcntrl2); and (x, in2, notcntrl1, cntrl2); and (y, in3, cntrl1, notcntrl2); and (z, in4, cntrl1, cntrl2); or (out, w, x, y, z); endmodule 54

Switch Level Modeling n Behavioral modeling n Data flow modeling n Gate level modeling n Switch level modeling n Others 55

Switch-level Primitives n MOS switch nmos, rnmos, pmos, rpmos, cmos, rcmos n Bidirectional pass switch tran, rtran, tranif1, rtranif1, tranif0, rtranif0 n Switch-level net trireg n Power sources pullup, pulldown 56

Use of trireg: Example pullup(vdd); trireg (small) #(3,3,10) TriS; trireg (medium) #(6,7,30) TriM; trireg (large) #(15,16,50) TriL; // pass transistor network: tran (TriM, TriS); // left always wins tran (TriM, TriL); // right always wins // NMOS network: rnmos #1 (TriM, TriS, vdd); // input has no effect rnmos #1 (TriS, TriL, vdd); // input controls output rnmos #1 (TriM, TriL, vdd); // connection on output 57

Others n The Power of Verilog n Dangers of Verilog n Interconnecting Modules 58

The Power of Verilog: n-bit Signals 59

The Power of Verilog: Integer Arithmetic 60

Dangers of Verilog: Incomplete Specification 61

Incomplete Specification Infers Latches 62

Avoiding Incomplete Specification Undefined in RHS is not good style, in fact. 63

Sensitivity List in Verilog 2001 Style always @ (a or b or c) case({a, b}) 2 b00: d = c; 2 b01: d = ~c; 2 b10: d = {c[0], c[1]}; 2 b11: d = {~c[0], c[1]}; endcase always @ * case({a, b}) 2 b00: d = c; 2 b01: d = ~c; 2 b10: d = {c[0], c[1]}; 2 b11: d = {~c[0], c[1]}; endcase 64

Dangers of Verilog : Priority Logic 65

Priority Logic 66

Avoiding (Unintended) Priority Logic 67

Interconnecting Modules 68

Module Definitions 69

Top-Level ALU Declaration 70

Simulation 71

More on Module Interconnection 72