Introduction To Verilog-HDL

Slides:



Advertisements
Similar presentations
//HDL Example 4-10 // //Gate-level description of circuit of Fig. 4-2 module analysis (A,B,C,F1,F2); input.
Advertisements

Verilog.
The Verilog Hardware Description Language
Supplement on Verilog adder examples
Verilog Modules for Common Digital Functions
CPEN Digital System Design
Verilog Intro: Part 1.
Combinational Logic with Verilog Materials taken from: Digital Design and Computer Architecture by David and Sarah Harris & The Essentials of Computer.
SYEN 3330 Digital SystemsJung H. Kim Chapter SYEN 3330 Digital Systems Chapters 4 – Part3: Verilog – Part 1.
CSE 341 Verilog HDL An Introduction. Hardware Specification Languages Verilog  Similar syntax to C  Commonly used in  Industry (USA & Japan) VHDL 
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
 HDLs – Verilog and Very High Speed Integrated Circuit (VHSIC) HDL  „ Widely used in logic design  „ Describe hardware  „ Document logic functions.
Verilog and VeriWell Bo Cheng.
Combinational Logic1 DIGITAL LOGIC DESIGN by Dr. Fenghui Yao Tennessee State University Department of Computer Science Nashville, TN.
Digital System Design Verilog ® HDL Tasks and Functions Maziar Goudarzi.
Spring 2002EECS150 - Lec0-intro Page 1 EECS150 - Digital Design Lecture 8 - Hardware Description Languages February 14, 2002 John Wawrzynek.
Tasks and Functions Programmable Logic Design (40-493) Fall 2001 Computer Engineering Department Sharif University of Technology Maziar Gudarzi.
Module : TASKS, Functions and UDPs in Verilog. Functions Functions are declared with the keywords function and endfunction. Functions are used if all.
ECE 2372 Modern Digital System Design
Combinational Logic. Digital Circuits Introduction Logic circuits for digital systems may be combinational or sequential. A combinational circuit.
CS 61C L4.2.2 Verilog II (1) K. Meinz, Summer 2004 © UCB CS61C : Machine Structures Lecture Verilog II Kurt Meinz inst.eecs.berkeley.edu/~cs61c.
Module 1.2 Introduction to Verilog
Anurag Dwivedi. Basic Block - Gates Gates -> Flip Flops.
Chap. 4 Modules and Ports. 2 Modules and Ports Modules Ports Hierarchical Names Summary.
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Multiplexers Section Topics Multiplexers – Definition – Examples – Verilog Modeling.
Chapter1: Introduction Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 1-1 Chapter 1: Introduction Prof. Ming-Bo.
Verilog Intro: Part 1. Hardware Description Languages A Hardware Description Language (HDL) is a language used to describe a digital system, for example,
Dept of CSE, IIT Kharagpur 1 1 The Verilog Week Debdeep Mukhopadhyay Associate Professor Dept of Computer Science and Engineering NYU Shanghai and IIT.
Examples of Basic Combinational
Structural Description
Overview Logistics Last lecture Today HW5 due today
Hardware Description Languages: Verilog
Hardware Description Language
Introduction to Verilog
Discussion 2: More to discuss
KARTHIK.S Lecturer/ECE S.N.G.C.E
Lecture 2 Supplement Verilog-01
Verilog-HDL-3 by Dr. Amin Danial Asham.
Hardware Description Languages: Verilog
1 Chapter 4 Combinational Logic Logic circuits for digital systems may be combinational or sequential. A combinational circuit consists of input variables,
Digital IC Design Flow: A quick look
Introduction to DIGITAL CIRCUITS MODELING & VERIFICATION using VERILOG [Part-I]
Chapter 4 Combinational Logic
Introduction to Verilog
Hardware Description Language
Behavioral Modeling in Verilog
Chapter 3: Dataflow Modeling
Combinatorial Logic Design Practices
Hardware Description Language
Levels in computer design
Verilog HDL Tutorial Winter 2003
Lecture 2: Continuation of SystemVerilog
Hardware Description Language
Chapter 8: Combinational Logic Modules
Introduction to Verilog
Hardware Description Language
Supplement on Verilog adder examples
Introduction to Verilog
The Verilog Hardware Description Language
CS 153 Logic Design Lab Professor Ian G. Harris
Hardware Description Language
The Verilog Hardware Description Language
Introduction to Verilog
Test Fixture Template module testfixture ; // data type declaration
EEE2243 Digital System Design Chapter 1: Verilog HDL (Combinational) by Muhazam Mustapha, February 2012.
Introduction to Digital IC Design
Introduction to Verilog – Part-2 Procedural Statements
Lecture 7: Verilog Part II
Presentation transcript:

Introduction To Verilog-HDL 16 November 2018 Department of Computer Science & Engg IIT Kharagpur

Department of Computer Science & Engg Parameterized Design module vector_and(z, a, b); parameter cardinality = 1; input [cardinality-1:0] a, b; output [cardinality-1:0] z; wire [cardinality-1:0] z = a & b; endmodule We override these parameters when we instantiate the module as: module Four_and_gates(OutBus, InBusA, InBusB); input [3:0] InBusA, InBusB; output[3:0] OutBus; Vector_And #(4) My_And(OutBus, InBusA, InBusB); 16 November 2018 Department of Computer Science & Engg IIT Kharagpur

Department of Computer Science & Engg Parameterized Design module vector_and(z, a, b); parameter cardinality = 1; input [cardinality-1:0] a, b; output [cardinality-1:0] z; wire [cardinality-1:0] z = a & b; endmodule We override these parameters when we instantiate the module as: module Four_and_gates(OutBus, InBusA, InBusB); input [3:0] InBusA, InBusB; output[3:0] OutBus; Vector_And #(4) My_And(OutBus, InBusA, InBusB); 16 November 2018 Department of Computer Science & Engg IIT Kharagpur

Department of Computer Science & Engg Functions (cont’d) Function Declaration and Invocation Declaration syntax: function <range_or_type> <func_name>; <input declaration(s)> <variable_declaration(s)> begin // if more than one statement needed <statements> end // if begin used endfunction 16 November 2018 Department of Computer Science & Engg IIT Kharagpur

Function Examples Controllable Shifter module shifter; `define LEFT_SHIFT 1'b0 `define RIGHT_SHIFT 1'b1 reg [31:0] addr, left_addr, right_addr; reg control; initial begin … end always @(addr)begin left_addr =shift(addr, `LEFT_SHIFT); right_addr =shift(addr,`RIGHT_SHIFT); function [31:0]shift; input [31:0] address; input control; begin shift = (control==`LEFT_SHIFT) ?(address<<1) : (address>>1); end endfunction endmodule 16 November 2018 Department of Computer Science & Engg IIT Kharagpur

How Are Simulators Used? Testbench generates stimulus and checks response Coupled to model of the system Pair is run simultaneously Testbench System Model Stimulus Response Result checker 16 November 2018 Department of Computer Science & Engg IIT Kharagpur

Structure of Testbench module <module name> <reg and wire declarations> <Instantiate the Verilog design> <generate stimulus using initial and always keywords> <produce the outputs using $monitor for verification> endmodule 16 November 2018 Department of Computer Science & Engg IIT Kharagpur

Looking back at our multiplexer “Dataflow” Descriptions of Logic //Dataflow description of mux module mux2 (in0, in1, select, out); input in0,in1,select; output out; assign out = (~select & in0) | (select & in1); endmodule // mux2 Alternative: assign out = select ? in1 : in0; 16 November 2018 Department of Computer Science & Engg IIT Kharagpur

TestBench of the Multiplexer module testmux; reg a, b, s; wire f; reg expected; mux2 myMux (.select(s), .in0(a), .in1(b), .out(f)); initial begin s=0; a=0; b=1; expected=0; #10 a=1; b=0; expected=1; #10 s=1; a=0; b=1; expected=1; end $monitor( "select=%b in0=%b in1=%b out=%b, expected out=%b time=%d", s, a, b, f, expected, $time); endmodule // testmux 16 November 2018 Department of Computer Science & Engg IIT Kharagpur

How to write synthesizable codes The following cannot be translated into hardware( non - synthesizable): Initial blocks Used to set up initial state or describe finite testbench stimuli Don’t have obvious hardware component Delays May be in the Verilog source, but are simply ignored In short, write codes with a hardware in your mind. In other words do not depend too much upon the tool to decide upon the resultant hardware. Finally, remember that you are a better designer than the tool. 16 November 2018 Department of Computer Science & Engg IIT Kharagpur

Typical Combinational Circuits Write a Verilog description for a 2 to 4 decoder (a) Using behavioral modeling module decoder ( Y3, Y2, Y1, Y0, A, B, en); // define inputs and outputs output Y3, Y2, Y1, Y0; input A, B; input en; reg Y3, Y2, Y1, Y0; always @ (A or B or en) begin if (en == 1) case ( {A,B} ) 16 November 2018 Department of Computer Science & Engg IIT Kharagpur

Department of Computer Science & Engg 2 to 4 decoder contd. 2’b00: {Y3, Y2, Y1, Y0} = 4’b0001; 2’b01: {Y3, Y2, Y1, Y0} = 4’b0010; 2’b10: {Y3, Y2, Y1, Y0} = 4’b0100; 2’b11: {Y3, Y2, Y1, Y0} = 4’b0001; default : {Y3, Y2, Y1, Y0} = 4’b1xxxx; endcase end if (en == 0) {Y3, Y2, Y1, Y0} = 4’b0000; endmodule 16 November 2018 Department of Computer Science & Engg IIT Kharagpur

Department of Computer Science & Engg 2 to 4 decoder contd. (b) Using dataflow modeling // file name : decoder.v module decoder (E, X, Y, Z0, Z1, Z2, Z3); output Z0, Z1, Z2, Z3; input E, X, Y; assign Z0 = E & ~X & ~Y; assign Z1 = E & ~X & Y; assign Z2 = E & X & ~Y; assign Z3 = E & X & Y; endmodule 16 November 2018 Department of Computer Science & Engg IIT Kharagpur

Department of Computer Science & Engg 2 to 4 decoder contd. (b) Using structural modeling modeling // file name : decoder.v module decoder (D, E, X, Y); output [0:3] D; input E, X, Y; wire [0:3] D; // output D must be declared as wire wire X1, Y1; not (X1, X); not (Y1, Y); and (D[0], X1, Y1, E); and (D[1], X1, Y, E); and (D[2], X, Y1, E); and (D[3], X, Y, E); endmodule 16 November 2018 Department of Computer Science & Engg IIT Kharagpur

Department of Computer Science & Engg Verilog for Full Adder // Full Adder using 3 to 8 decoder 74138 and 2 four input AND gates module fulladder (C, S, X, Y, Z); output C, S; input X, Y, Z; wire [7:0] decoder_out; // 3 to 8 decoder enabled with bits to be added as inputs decoder 74138 decoder 74138_0 (decoder_out [7:0], 1’b1, 1’b0, 1’b0, X, Y, Z); // use 4 input AND gates to find Sum and Carry AND4_0 (S, decoder_out[0], decoder_out[3], decoder_out[5], decoder_out[6]); AND4_0 (S, decoder_out[0], decoder_out[1], decoder_out[2], decoder_out[4]); endmodule 16 November 2018 Department of Computer Science & Engg IIT Kharagpur

Testbench for Full Adder // Full Adder using 3 to 8 decoder 74138 and 2 four input AND gates module fulladdertest (C, S, X, Y, Z); wire C, S; reg X, Y, Z; wire [7:0] decoder_out; fulladder fulladder_0 (C, S, X, Y, Z); initial $monitor(“Time = %d, X=%b, Y=%b, Z=%b, S=%b, C=%b”, $time, X, Y, Z, S, C); 16 November 2018 Department of Computer Science & Engg IIT Kharagpur

Testbench for Full Adder initial begin #0 X = 1’b0; Y = 1’b0; Z = 1’b0; #0 X = 1’b0; Y = 1’b0; Z = 1’b1; #0 X = 1’b0; Y = 1’b1; Z = 1’b0; #0 X = 1’b0; Y = 1’b1; Z = 1’b1; #0 X = 1’b1; Y = 1’b0; Z = 1’b0; #0 X = 1’b1; Y = 1’b0; Z = 1’b1; #0 X = 1’b1; Y = 1’b1; Z = 1’b0; #0 X = 1’b1; Y = 1’b1; Z = 1’b1; end endmodule 16 November 2018 Department of Computer Science & Engg IIT Kharagpur

Department of Computer Science & Engg Verilog Assignments 1. Write Verilog code for a 4 to 1 multiplexer using (a) using structural modeling (b) conditional operator 2. Write Verilog code for 1 2-bit unsigned comparator 3. Write Verilog code for a 4-bit ripple carry adder using (a) behavioral modeling (b) hierarchical modeling 4. Write Verilog code fro BCD to seven-segment code converter for driving a common –cathode display for displaying the decimal digits 0 to 9. 16 November 2018 Department of Computer Science & Engg IIT Kharagpur