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

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

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

Online Verilog Resources

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

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

Verilog HDL Introduction

Introduction to Verilog HDL. Verilog 1

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

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

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

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

Chapter 2 Using Hardware Description Language Verilog. Overview

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

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

Advanced Digital Design with the Verilog HDL

Design Using Verilog

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

Contents. Appendix D Verilog Summary Page 1 of 16

Lecture #2: Verilog HDL

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

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

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

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

DIGITAL SYSTEM DESIGN

Verilog Dataflow Modeling

ECEN 468 Advanced Digital System Design

CSE140L: Components and Design Techniques for Digital Systems Lab

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

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

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

Chapter 3: Dataflow Modeling

CSE140L: Components and Design

Verilog Tutorial (Structure, Test)

Introduction to Digital Design with Verilog HDL

Synthesizable Verilog

EECS150 - Digital Design Lecture 10 Logic Synthesis

ECEN 468 Advanced Logic Design

Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

Verilog Design Principles

Introduction to Verilog/System Verilog

Verilog for Synthesis Ing. Pullini Antonio

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

Advanced Digital Design Using FPGA. Dr. Shahrokh Abadi

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

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

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

Actel HDL Coding. Style Guide

Course Topics - Outline

EN2911X: Reconfigurable Computing Topic 02: Hardware Definition Languages

EEL 4783: HDL in Digital System Design

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

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

DIGITAL SYSTEM DESIGN

ECEN 468 Advanced Logic Design

Under-Graduate Project Logic Design with Behavioral Models

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

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

EECS150 - Digital Design Lecture 10 Logic Synthesis

Verilog introduction. Embedded and Ambient Systems Lab

Graduate Institute of Electronics Engineering, NTU Basic Concept of HDL

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

Verilog Design Principles

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

Actel HDL Coding. Style Guide

Digital Design with FPGAs. By Neeraj Kulkarni

Synthesis of Combinational and Sequential Circuits with Verilog

HDL for Combinational Circuits. ENEL211 Digital Technology

Chapter 2 Basic Logic Circuits and VHDL Description

VLSI Design 13. Introduction to Verilog

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

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

Verilog Fundamentals. Shubham Singh. Junior Undergrad. Electrical Engineering

Digital Design with SystemVerilog

Lecture 32: SystemVerilog

ELCT 501: Digital System Design

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

Introduction To Verilog Design. Chun-Hung Chou

Combinational Logic II

Programmable Logic Devices Verilog VII CMPE 415

Verilog Overview. The Verilog Hardware Description Language. Simulation of Digital Systems. Simulation of Digital Systems. Don Thomas, 1998, Page 1

Abi Farsoni, Department of Nuclear Engineering and Radiation Health Physics, Oregon State University

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

Hardware Description Language VHDL (1) Introduction

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

Table of Contents. Verilog. Verilog

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

Verilog Overview. The Verilog Hardware Description Language. Simulation of Digital Systems. Simulation of Digital Systems. Don Thomas, 1998, Page 1

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

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

Digital Design (VIMIAA01) Introduction to the Verilog HDL

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

Verilog HDL. Testing & Verification Dept. of Computer Science & Engg,, IIT Kharagpur

structure syntax different levels of abstraction

Here is a list of lecture objectives. They are provided for you to reflect on what you are supposed to learn, rather than an introduction to this

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

ENGN1640: Design of Computing Systems Topic 02: Lab Foundations

Lecture 15: System Modeling and Verilog

Verilog Overview. The Verilog Hardware Description Language. Simulation of Digital Systems. Simulation of Digital Systems. Don Thomas, 1998, Page 1

Microcomputers. Outline. Number Systems and Digital Logic Review

Transcription:

Why use an HDL? Lecture 2: Data Types, Modeling Combinational Logic in Verilog HDL Increase digital design engineer s productivity (from Dataquest) Behavioral HDL RTL HDL Gates Transistors 2K 10K gates/week 1K 2K gates/week 100 200 gates/week 10 20 gates/week 1 2 Variables and Logic Value Set Variables: represent the values of signals in a circuit Two kinds of variables: Nets and Registers Nets: represent the structural connectivity in a circuit Registers: represent storage elements Logic Value Set Logic Value Interpretation 0 Logic 0, or false condition 1 Logic 1, or true condition x represent an unknown logic value z represent a high impedance condition Data Types Nets Nets are physical connections between devices Nets always reflect the logic value of the driving device Many types of nets, but all we care about is wire Registers Implicit storage unless variable of this type is modified it retains previously assigned value Does not necessarily imply a hardware register Register type is denoted by reg int is also used 3 4 1

Data Types: Nets Nets for connectivity: wire establishes connectivity tri same as wire and it will be tri-stated in hardware wand a net has multiple drivers, wires and, i.e., open collector circuit wor a net has multiple drivers, wired or, i.e., emitter coupled circuit triand a net that has multiple drivers. It models wired-and. It is tri-stated. trior a net that has multiple drivers. It models wired-or. It is tri-stated. supply0 a global net connected to the circuit ground supply1 a global net connected to the power supply tri0 a net connected to the ground by a resistive pulldown connection. tri1 a net connected to the power supply by a resistive pullup connection. trireg a net that models the charge stored on a physical net. 5 wire Variables referenced, but undeclared are implicit wires Gates drive nets. The output of a gate by default is a wire module Add_half (sum, c_out, a, b); output sum, c_out; // declare output port of type net, actually wire input a, b; // declare input port of type net, actually wire wire c_out_bar; xor G1 (sum, a, b); nand G2 (c_out_bar, a, b); not G3 (c_out, c_out_bar); module Add_half (sum, c_out, a, b); output sum, c_out; input a, b; xor G1 (sum, a, b); nand G2 (c_out_bar, a, b); not G3 (c_out, c_out_bar); These two modules are equivalent input port of type net output port of type net 6 Data Types: Registers Rising Edge Flip-Flop with Asynchronous Reset Registers for storage A register variable is an abstraction of a hardware storage element. Rising Edge Flip-Flop <= is non-blocking assignment for flip flops module dff (data, clk, q); input data, clk; always @(posedge clk) q <= data; // Tools require left-hand // side must be a register // for statements in an always block module dff_async_rst (data, clk, reset, q); input data, clk, reset; always @(posedge clk or negedge reset) if (~reset) q <= 1'b0; q <= data; More about <= non-blocking, = block assignment later 7 8 2

Rising Edge Flip-Flop with Asynchronous Preset module dff_async_pre (data, clk, preset, q); input data, clk, preset; always @(posedge clk or negedge preset) if (~preset) q <= 1'b1; q <= data; Rising Edge Flip-Flop with Asynchronous Reset and Preset module dff_async (reset, preset, data, q, clk); input clk; input reset, preset, data; always @ (posedge clk or negedge reset or posedge preset) if (~reset) q <= 1'b0; if (preset) q <= 1'b1; q <= data; 9 10 Rising Edge Flip-Flop with Synchronous Reset Rising Edge Filp-Flop with Synchronous Preset module dff_sync_rst (data, clk, reset, q); input data, clk, reset; always @ (posedge clk) if (~reset) q <= 1'b0; q <= data; module dff_sync_pre (data, clk, preset, q); input data, clk, preset; always @ (posedge clk) if (~preset) q <= 1'b1; q <= data; 11 12 3

D-Latch with Data and Enable module d_latch (enable, data, y); input enable, data; output y; reg y; always @(enable or data) if (enable) y <= data; D-Latch with Gated Asynchronous Data module d_latch_e(enable, gate, data, q); input enable, gate, data; always @ (enable or data or gate) if (enable) q <= (data & gate); 13 14 D-Latch with Gated Enable module d_latch_en(enable, gate, d, q); input enable, gate, d; always @ (enable or d or gate) if (enable & gate) q <= d; wire [7:0] wire [0:3] Net Declaration data_bus; // 8 bit bus, data_bus[7] is MSB control_bus; // control_bus[0] is MSB //access bus examples data_bus[3] // access data_bus bit 3 data_bus[3:0] // access bit 3 to bit 0 of data_bus data_bus[k+2] // access a bit of the data_bus, // deping on k+2 wire y, x, z; // y, x, z are three wires wand A, B,C; // A, B, C wired and nets Undeclared nets will default implicitly to type wire. 15 16 4

What if a wire or tri type net is driven by multiple drivers? What is the initial value of a net? Verilog issues a warning and determines the value by pairwise application of the following table wire/tri 0 1 x z 0 0 x x 0 1 x 1 x 1 x x x x x z 0 1 x z A net driven by a primitive, module, or continuous assignment has a value "x" at the start of simulation. A net without any drivers is default to "z". wire a, b, c; assign a = b+ c; // initial value by default b = z, c = z, a = x The initial value for a register variable is by default also "x". Design engineers don't want to drive a wire with more than one signals. 17 18 Register Data Types Register Data Types: reg, integer, time, realtime module adder_4_rtl (a, b, c_in, sum, c_out); output [3:0] sum; output c_out; input [3:0] a, b; input c_in; Register type reg integer time real realtime Usage Stores a logic value Supports computation Supports time as a 64-bit unsigned number Stores values (e.g., delay) as real numbers Stores time values as real numbers assign {c_out, sum} = a + b + c_in; // continuous assignment, any change of a, b, c_in // Verilog re-evaluates the output A register may never be the output of a primitive gate, or the target of a continuous assignment (an example of a continuous assignment in next slide) Continuous assignment allows you to specify combinational logic in equation form. Anytime an input (value on the right-hand side) changes, the simulator re-evaluates the output 19 No gate structure is implied logic synthesis can design it. 20 5

Verilog has the following operators for continuous assignments and register manipulations Arithmetic Operators: +, -, *, /, % (modulus) Bitwise/Logical Operators Bitwise operators operate on the bits of the operand or operands. For example, the result of A & B is the AND of each corresponding bit of A with B. Operator Name ~ Bitwise negation & Bitwise AND Bitwise OR ^ Bitwise XOR ~& Bitwise NAND ~ Bitwise NOR ~^ or ^~ Equivalence (Bitwise NOT XOR) Bitwise/Logical Operators Bitwise operators operate on the bits of the operand or operands. For example, the result of A & B is the AND of each corresponding bit of A with B. Operator Name ~ Bitwise negation & Bitwise AND Bitwise OR ^ Bitwise XOR ~& Bitwise NAND ~ Bitwise NOR ~^ or ^~ Equivalence (Bitwise NOT XOR) {, } concatenation 21 22 Reduction Operators Verilog Example Reduction Operators: producing a single bit value by operating on a single data word. & reduction and reduction or ~& reduction nand ~ reduction nor ^ reduction exclusive or ~^ reduction xnor module syntristate (bus, in, driveenable); input in, driveenable; output bus; reg bus; always if @(in or driveenable) (driveenable) bus = in; bus = 1`bz; Wait for any change on in, driveenable then execute the - block containing the if. Then wait for another change. 23 24 6

Initial Value of a Register Variable Passing Variables Through Ports reg A, B; initial A = 0; // assign an initial value to A B = 1; // assign an initial value to B // All registers have an initial value of "x" by default. Port Mode Variable Type Input Output InOut net variable yes yes yes register variable no yes no input port of a module is of type net. output port of a module is of type net, or reg. inout port of a module is of type net. 25 26 Hierarchical De-referencing Memory Declaration Memory Declaration reg [31:0] m [0:8191]; // 8192 x 32 bit memory reg [15:0] pc; // 16 bit program counter reg [31:0] acc; // 32 bit accumulator reg [15:0] ir; // 16 bit instruction register reg ck; // a clock signal module test_add_rca_4(); reg [3:0] a,b; reg c_in; wire [3:0] sum; wire c_out; initial $monitor ($time,, "c_out= %b c_in4=%b c_in3=%b c_in2=%b c_in=%b ", c_out, M1.c_in4, M1.c_in3, M1.c_in2, c_in); initial // stimus patterns generated here Add_rca_4 M1 (sum, c_out, a, b, c_in); // Add_rca_4 in next slide 27 28 7

Verilog model: 4 bit RCA module Add_rca_4 (sum, c_out, a, b, c_in); output [3:0] sum; output c_out; input [3:0] a, b; input c_in; wire c_out, c_in4, c_in3, c_in2; Add_full G1 (sum[0], c_in2, a[0], b[0], c_in); Add_full G2 (sum[1], c_in3, a[1], b[1], c_in2); Add_full G3 (sum[2], c_in4, a[2], b[2], c_in3); Add_full G2 (sum[3], c_out, a[3], b[3], c_in4); module Add_full(sum, cout, ain, bin, cin); output sum, cout; input ain, bin, cin; nand (x2, ain, bin), (cout, x2, x8); xnor (x9, x5, x6); nor (x5, x1, x3), (x1, ain, bin); or (x8, x1, x7); not (sum, x9), (x3, x2), (x6, x4), (x4, cin), (x7, x6); A full adder usesverilog primitive logic gates. Anytime the input to a gate changes, its output is evaluated, via its output wire to other inputs A default gate delay is 0 29 30 Parameters Substitution module modxnor (y_out, a, b); parameter size=8, delay=15; output [size-1:0] y_out; input [size-1:0] a, b; wire [size-1:0] #delay y_out=a~^b; module Param; wire [7:0] y1_out; wire [3:0] y2_out; reg [7:0] b1, c1; reg [3:0] b2, c2; modxnor G1 (y1_out, b1, c1); modxnor #(4, 5) G2 (y2_out, b2, c2); // size = 4, delay =5 31 Indirect Parameters Substitution module modxnor (y_out, a, b); parameter size=8, delay=15; output [size-1:0] y_out; input [size-1:0] a, b; wire [size-1:0] #delay y_out=a~^b; module hdref_param; wire [7:0] y1_out; wire [3:0] y2_out; reg [7:0] b1, c1; reg [3:0] b2, c2; modxnor G1 (y1_out, b1, c1); modxnor G2 (y2_out, b2, c2); module annotate; defparam hdref_param.g2.size = 4, hdref_param.g2.delay = 5; 32 8

Verilog Model Example Design a 4-to-1 mux by cascading 2-to-1 muxes. module mux2to1 (f, a, b, sel); input a, b, sel; and g1 (f1, a, nsel), g2 (f2, b, sel); or g3 (f, f1, f2); not g4 (nsel, sel); module mux4to1 (f, a, b, c, d, sel0, sel1); input a, b, c, d, sel0, sel1; wire w1, w2; mux2to1 m1 (w1, a, b, sel0), m2 (w2, c, d, sel0), m3 (f, w1, w2, sel1); 33 module test_mux4to1 (a, b, c, d, sel0, sel1, f); // generating all inputs to the mux4to1, // receiving f from the mux4to1 output input f; output a, b, c, d, sel0, sel1; reg a, b, c, d, sel0. sel1; initial $monitor ($time,, "a = %b, b = %b, c = %b, d = %b, sel1 = %b, sel0 = %b, f = %b", a, b, c, d, sel1, sel0, f); a = 1; b =0; c =1; d =0; sel1 = 0; sel0 = 0; #10 sel1= 0; sel0 = 1; #10 sel1 = 1; sel0 = 0; #10 sel1 = 1; sel0 = 1; #10 a = 0; b =0; c= 1; d = 1; sel1 = 0; sel0 = 0; #10 sel1= 0; sel0 = 1; #10 sel1 = 1; sel0 = 0; #10 sel1 = 1; sel0 = 1; #10 $finish; 34 module testbench; wire a, b, c, d, sel0, sel1, f; test_mux4to1 mux4to1 my_tester (a, b, c, d, sel0, sel1, f); my_design (f, a, b, c, d, sel0, sel1); the simulation output should look similar to the following 0 a =1, b = 0, c= 1, d= 0, sel1= 0, sel0=0. f = 1 10 a =1, b = 0, c= 1, d=0, sel1=0, sel0=1, f = 0 20 30 40 50 60 70 Ready: sim 10 a = 1, b = 0, c = 1, d = 0, sel1 = 0, sel0 = 1, f = 0 20 a = 1, b = 0, c = 1, d = 0, sel1 = 1, sel0 = 0, f = 1 30 a = 1, b = 0, c = 1, d = 0, sel1 = 1, sel0 = 1, f = 0 40 a = 0, b = 0, c = 1, d = 1, sel1 = 0, sel0 = 0, f = 0 50 a = 0, b = 0, c = 1, d = 1, sel1 = 0, sel0 = 1, f = 0 60 a = 0, b = 0, c = 1, d = 1, sel1 = 1, sel0 = 0, f = 1 70 a = 0, b = 0, c = 1, d = 1, sel1 = 1, sel0 = 1, f = 1 75 State changes on observable nets. Simulation stopped at the of time 80. copied from Silos output window 35 36 9

module mux (f, sel, b, c); input sel, b, c; reg f; always @ (sel or b or c) if (sel == 1) f = b; f = c; A Behavioral Model for MUX This is a combinational circuit No register needed Behavioral model uses Always, Initial construct. The register is there as an artifact of the descriptions. The left-hand side of statements used in an always block must be registers. module test_mux4to1 (a, b, c, d, sel0, sel1, f); // generating all inputs to the mux4to1, // receiving f from the mux4to1 output input f; output a, b, c, d, sel0, sel1; reg a, b, c, d, sel0, sel1; initial $monitor ($time,, "a = %b, b = %b, c = %b, d = %b, sel1 = %b, sel0 = %b, f = %b", a, b, c, d, sel1, sel0, f); a = 1; b =0; c =1; d =0; sel1 = 0; sel0 = 0; #10 sel1= 0; sel0 = 1; #10 sel1 = 1; sel0 = 0; #10 sel1 = 1; sel0 = 1; #10 a = 0; b =0; c= 1; d = 1; sel1 = 0; sel0 = 0; #10 sel1= 0; sel0 = 1; #10 sel1 = 1; sel0 = 0; #10 sel1 = 1; sel0 = 1; #10 $finish; Behavioral construct Initial is used in this module The left-hand side must be a register for all statements used in an Initial block 37 38 Behavioral Model for Combinational Logic Each always statement turns into Boolean functions module example (f, a, b, c); input a, b, c; reg f; always @ (a or b or c) logic... logic... logic... Declare the combinational output f as register. Make tool think you are putting these computed outputs somewhere. List all the block s inputs here in the sensitivity list Do logic here. In Verilog, always statement is considered as procedural statement Initial is another procedural statement 39 The rules for specifying combinational logic using procedural statements 1. Every element of the input set must be in the sensitivity list 2. The combinational output must be assigned in every control path module exam1 (f, sel, b, c); input sel, b, c; reg f; always @ (sel or b or c) if (sel == 1) f = b; f = c; correct model module exam2 (f, g, sel, b, c); output f, g; input sel, b, c; reg f, g; always @ (sel or b or c) if (sel == 1) f = b; g = c; wrong model 40 10

Behavioral Model for Combinational Logic: Case statement Generate a truth table, assign output f in each case item module logic1 (f, a, b, c); input a, b, c; reg f; always @ (a or b or c) case ({a, b, c}) 3 b000: f = 1 b0; 3 b001: f = 1 b1; 3 b010: f = 1 b1; 3 b011: f = 1 b1; 3 b100: f = 1 b1; 3 b101: f = 1 b0; 3 b110: f = 1 b0; 3 b111: f = 1 b1; case {a, b, c} concatenates a, b, and c together, considering them as a single item 41 module mux4x1_bh (i0,i1,i2,i3,select,y); input i0,i1,i2,i3; input [1:0] select; output y; reg y; always @ (i0 or i1 or i2 or i3 or select) case (select) 2'b00: y = i0; 2'b01: y = i1; 2'b10: y = i2; 2'b11: y = i3; case module mux2x1_df (A,B,select,OUT); input A,B,select; output OUT; assign OUT = select? A : B; OUT = A if select = 1, OUT = B if select =0 42 Verilog behavioral model for combinational logic module name (<output names>, <input names>); output <output names>; input <input names>; reg <output names>; always @ (<names of all input vars>) < LHS = RHS assignments> < if... statements> < case statements > 43 11