1 Lecture 2: Data Types, Modeling Combinational Logic in Verilog HDL.

Slides:



Advertisements
Similar presentations
Simulation executable (simv)
Advertisements

Verilog Overview. University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
ECE 551 Digital Design And Synthesis
Synchronous Sequential Logic
Combinational Logic.
Table 7.1 Verilog Operators.
Verilog Intro: Part 1.
SYEN 3330 Digital SystemsJung H. Kim Chapter SYEN 3330 Digital Systems Chapters 4 – Part3: Verilog – Part 1.
1 Brief Introduction to Verilog Weiping Shi. 2 What is Verilog? It is a hardware description language Originally designed to model and verify a design.
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 - 1 Writing Hardware Programs in Abstract Verilog  Abstract Verilog is a language with special semantics  Allows fine-grained parallelism to.
ELEN 468 Lecture 41 ELEN 468 Advanced Logic Design Lecture 4 Data Types and Operators.
ELEN 468 Lecture 151 ELEN 468 Advanced Logic Design Lecture 15 Synthesis of Language Construct I.
Lecture 2: Hardware Modeling with Verilog HDL
1 Lecture 1: Verilog HDL Introduction. 2 What is Verilog HDL? Verilog Hardware Description Language(HDL)? –A high-level computer language can model, represent.
Variables and Logic Value Set
Reconfigurable Computing (EN2911X, Fall07) Lecture 05: Verilog (1/3) Prof. Sherief Reda Division of Engineering, Brown University
ECEN ECEN475 Introduction to VLSI System Design Verilog HDL.
Kazi Fall 2006 EEGN 4941 EEGN-494 HDL Design Principles for VLSI/FPGAs Khurram Kazi.
Digital System Design EEE344 Lecture 3 Introduction to Verilog HDL Prepared by: Engr. Qazi Zia, Assistant Professor EED, COMSATS Attock1.
Today’s Lecture Process model –initial & always statements Assignments –Continuous & procedural assignments Timing Control System tasks.
Overview Logistics Last lecture Today HW5 due today
Verilog Basics Nattha Jindapetch November Agenda Logic design review Verilog HDL basics LABs.
INTRODUCTION TO VERILOG HDL Presented by m.vinoth.
Introduction to FPGA AVI SINGH. Prerequisites Digital Circuit Design - Logic Gates, FlipFlops, Counters, Mux-Demux Familiarity with a procedural programming.
Verilog Intro: Part 2. Procedural Blocks There are two types of procedural blocks in Verilog. – initial for single-pass behavior: initial blocks execute.
ECE 2372 Modern Digital System Design
Digital System 數位系統 Verilog HDL Ping-Liang Lai (賴秉樑)  
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
1 CSE-308 Digital System Design (DSD) N-W.F.P. University of Engineering & Technology, Peshawar.
Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 7: Design Example, Modeling Flip-Flops Spring.
1 CSE-308 Digital System Design (DSD) N-W.F.P. University of Engineering & Technology, Peshawar.
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
Verilog for Synthesis Ing. Pullini Antonio
Anurag Dwivedi. Basic Block - Gates Gates -> Flip Flops.
3/4/20031 ECE 551: Digital System Design * & Synthesis Lecture Set 3 3.1: Verilog - User-Defined Primitives (UDPs) (In separate file) 3.2: Verilog – Operators,
1 Hardware description languages: introduction intellectual property (IP) introduction to VHDL and Verilog entities and architectural bodies behavioral,
Behavioral Modelling - 1. Verilog Behavioral Modelling Behavioral Models represent functionality of the digital hardware. It describes how the circuit.
1 Verilog Digital System Design Z. Navabi, 2006 Verilog Language Concepts.
ELEN 468 Lecture 131 ELEN 468 Advanced Logic Design Lecture 13 Synthesis of Combinational Logic II.
Verilog A Hardware Description Language (HDL ) is a machine readable and human readable language for describing hardware. Verilog and VHDL are HDLs.
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
Introduction to ASIC flow and Verilog HDL
Introduction to Verilog. Data Types A wire specifies a combinational signal. – Think of it as an actual wire. A reg (register) holds a value. – A reg.
Introduction to Verilog
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
Chapter 3: Dataflow Modeling Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 3-1 Chapter 3: Dataflow Modeling.
Verilog Intro: Part 1. Hardware Description Languages A Hardware Description Language (HDL) is a language used to describe a digital system, for example,
1 University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
1 Lecture 3: Modeling Sequential Logic in Verilog HDL.
1 Lecture 1: Verilog HDL Introduction. 2 What is Verilog HDL? Verilog Hardware Description Language(HDL)? –A high-level computer language can model, represent.
Exp#5 & 6 Introduction to Verilog COE203 Digital Logic Laboratory Dr. Ahmad Almulhem KFUPM Spring 2009.
Structural Description
Overview Logistics Last lecture Today HW5 due today
Hardware Description Languages: Verilog
Supplement on Verilog FF circuit examples
ELEN 468 Advanced Logic Design
Discussion 2: More to discuss
‘if-else’ & ‘case’ Statements
Basics of digital systems
Hardware Description Languages: Verilog
Introduction to DIGITAL CIRCUITS MODELING & VERIFICATION using VERILOG [Part-I]
Behavioral Modeling in Verilog
332:437 Lecture 8 Verilog and Finite State Machines
The Verilog Hardware Description Language
The Verilog Hardware Description Language
332:437 Lecture 8 Verilog and Finite State Machines
COE 202 Introduction to Verilog
Presentation transcript:

1 Lecture 2: Data Types, Modeling Combinational Logic in Verilog HDL

2 Why use an HDL? Increase digital design engineer’s productivity (from Dataquest) Behavioral HDL2K – 10K gates/week RTL HDL1K – 2K gates/week Gates100 – 200 gates/week Transistors10 – 20 gates/week

3 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 ValueInterpretation 0Logic 0, or false condition 1Logic 1, or true condition xrepresent an unknown logic value zrepresent a high impedance condition

4 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

5 Data Types: Nets Nets for connectivity: wireestablishes connectivity trisame as wire and it will be tri-stated in hardware wanda net has multiple drivers, wires and, i.e., open collector circuit wora net has multiple drivers, wired or, i.e., emitter coupled circuit trianda net that has multiple drivers. It models wired-and. It is tri-stated. triora net that has multiple drivers. It models wired-or. It is tri-stated. supply0a global net connected to the circuit ground supply1a global net connected to the power supply tri0a net connected to the ground by a resistive pulldown connection. tri1a net connected to the power supply by a resistive pullup connection. trirega net that models the charge stored on a physical net.

6 wireVariables 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 inputa, b; // declare input port of type net, actually wire wirec_out_bar; xorG1 (sum, a, b); nandG2 (c_out_bar, a, b); notG3 (c_out, c_out_bar); endmodule module Add_half (sum, c_out, a, b); output sum, c_out; inputa, b; xorG1 (sum, a, b); nandG2 (c_out_bar, a, b); notG3 (c_out, c_out_bar); endmodule These two modules are equivalent input port of type net output port of type net

7 module dff (data, clk, q); input data, clk; output q; reg q; clk) q <= data; // Tools require left-hand // side must be a register // for statements in an always block endmodule Data Types: Registers 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 More about “<=“ non-blocking, “=“ block assignment later

8 Rising Edge Flip-Flop with Asynchronous Reset module dff_async_rst (data, clk, reset, q); input data, clk, reset; output q; reg q; clk or negedge reset) if (~reset) q <= 1'b0; else q <= data; endmodule

9 Rising Edge Flip-Flop with Asynchronous Preset module dff_async_pre (data, clk, preset, q); input data, clk, preset; output q; reg q; clk or negedge preset) if (~preset) q <= 1'b1; else q <= data; endmodule

10 Rising Edge Flip-Flop with Asynchronous Reset and Preset module dff_async (reset, preset, data, q, clk); input clk; input reset, preset, data; output q; reg q; (posedge clk or negedge reset or posedge preset) if (~reset) q <= 1'b0; else if (preset) q <= 1'b1; else q <= data; endmodule

11 Rising Edge Flip-Flop with Synchronous Reset module dff_sync_rst (data, clk, reset, q); input data, clk, reset; output q; reg q; (posedge clk) if (~reset) q <= 1'b0; else q <= data; endmodule

12 Rising Edge Filp-Flop with Synchronous Preset module dff_sync_pre (data, clk, preset, q); input data, clk, preset; output q; reg q; (posedge clk) if (~preset) q <= 1'b1; else q <= data; endmodule

13 D-Latch with Data and Enable module d_latch (enable, data, y); input enable, data; output y; reg y; or data) if (enable) y <= data; endmodule

14 D-Latch with Gated Asynchronous Data module d_latch_e(enable, gate, data, q); input enable, gate, data; output q; reg q; (enable or data or gate) if (enable) q <= (data & gate); endmodule

15 D-Latch with Gated Enable module d_latch_en(enable, gate, d, q); input enable, gate, d; output q; reg q; (enable or d or gate) if (enable & gate) q <= d; endmodule

16 Net Declaration wire [7:0]data_bus; // 8 bit bus, data_bus[7] is MSB wire [0:3]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, // depending on k+2 wirey, x, z;// y, x, z are three wires wandA, B,C;// A, B, C wired and nets Undeclared nets will default implicitly to type wire.

17 What if a wire or tri type net is driven by multiple drivers? Verilog issues a warning and determines the value by pairwise application of the following table wire/tri01xz 00xx0 1x1x1 xxxxx z01xz Design engineers don't want to drive a wire with more than one signals.

18 What is the initial value of a net? 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".

19 Register Data Types Register Data Types: reg, integer, time, realtime Register typeUsage regStores a logic value integerSupports computation timeSupports time as a 64-bit unsigned number realStores values (e.g., delay) as real numbers realtimeStores time values as real numbers 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)

20 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; assign {c_out, sum} = a + b + c_in; // continuous assignment, any change of a, b, c_in // Verilog re-evaluates the output endmodule 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 No gate structure is implied — logic synthesis can design it.

21 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) {, }concatenation

22 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)

23 Reduction Operators 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

24 Verilog Example module synTriState (bus, in, driveEnable); inputin, driveEnable; output bus; regbus; or driveEnable) begin if (driveEnable) bus = in; else bus = 1`bz; end endmodule Wait for any change on in, driveEnable then execute the begin-end block containing the if. Then wait for another change.

25 Initial Value of a Register Variable regA, B; initial begin A = 0; // assign an initial value to A B = 1; // assign an initial value to B end // All registers have an initial value of "x" by default.

26 Passing Variables Through Ports Port Mode Variable TypeInputOutput InOut net variableyesyes yes register variablenoyes 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.

27 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 regck;// a clock signal

28 Hierarchical De-referencing module test_Add_rca_4(); reg [3:0]a,b; regc_in; wire[3:0]sum; wirec_out; initial begin $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); end initial begin // stimus patterns generated here end Add_rca_4 M1 (sum, c_out, a, b, c_in); // Add_rca_4 in next slide endmodule

29 Verilog model: 4 bit RCA module Add_rca_4 (sum, c_out, a, b, c_in); output [3:0]sum; outputc_out; input [3:0]a, b; inputc_in; wirec_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); endmodule

30 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); endmodule 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

31 Parameters Substitution module modXnor (y_out, a, b); parametersize=8, delay=15; output[size-1:0]y_out; input [size-1:0]a, b; wire[size-1:0]#delay y_out=a~^b; endmodule 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 endmodule

32 Indirect Parameters Substitution module modXnor (y_out, a, b); parametersize=8, delay=15; output[size-1:0]y_out; input [size-1:0]a, b; wire[size-1:0]#delay y_out=a~^b; endmodule 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); endmodule module annotate; defparam hdref_Param.G2.size = 4, hdref_Param.G2.delay = 5; endmodule

33 Verilog Model Example Design a 4-to-1 mux by cascading 2-to-1 muxes. module mux2to1 (f, a, b, sel); outputf; inputa, b, sel; and g1 (f1, a, nsel), g2 (f2, b, sel); org3 (f, f1, f2); notg4 (nsel, sel); endmodule module mux4to1 (f, a, b, c, d, sel0, sel1); output f; inputa, b, c, d, sel0, sel1; wirew1, w2; mux2to1m1 (w1, a, b, sel0), m2 (w2, c, d, sel0), m3 (f, w1, w2, sel1); endmodule

34 module test_mux4to1 (a, b, c, d, sel0, sel1, f); // generating all inputs to the mux4to1, // receiving f from the mux4to1 output inputf; outputa, b, c, d, sel0, sel1; rega, b, c, d, sel0. sel1; initial begin $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; #10sel1= 0; sel0 = 1; #10sel1 = 1; sel0 = 0; #10sel1 = 1; sel0 = 1; #10a = 0; b =0; c= 1; d = 1; sel1 = 0; sel0 = 0; #10sel1= 0; sel0 = 1; #10sel1 = 1; sel0 = 0; #10sel1 = 1; sel0 = 1; #10$finish; end endmodule

35 module testbench; wire a, b, c, d, sel0, sel1, f; test_mux4to1my_tester (a, b, c, d, sel0, sel1, f); mux4to1my_design (f, a, b, c, d, sel0, sel1); endmodule the simulation output should look similar to the following 0a =1, b = 0, c= 1, d= 0, sel1= 0, sel0=0. f = 1 10a =1, b = 0, c= 1, d=0, sel1=0, sel0=1, f =

36 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 end of time 80. copied from Silos output window

37 A Behavioral Model for MUX module mux (f, sel, b, c); output f; input sel, b, c; regf; (sel or b or c) if (sel == 1) f = b; else f = c; endmodule 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. This is a combinational circuit No register needed

38 module test_mux4to1 (a, b, c, d, sel0, sel1, f); // generating all inputs to the mux4to1, // receiving f from the mux4to1 output inputf; outputa, b, c, d, sel0, sel1; rega, b, c, d, sel0, sel1; initial begin $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; #10sel1= 0; sel0 = 1; #10sel1 = 1; sel0 = 0; #10sel1 = 1; sel0 = 1; #10a = 0; b =0; c= 1; d = 1; sel1 = 0; sel0 = 0; #10sel1= 0; sel0 = 1; #10sel1 = 1; sel0 = 0; #10sel1 = 1; sel0 = 1; #10$finish; end endmodule Behavioral construct Initial is used in this module The left-hand side must be a register for all statements used in an Initial block

39 Behavioral Model for Combinational Logic Each “always” statement turns into Boolean functions module example (f, a, b, c); output f; input a, b, c; regf; (a or b or c) begin logic... end endmodule Declare the combinational output f as register. Make tool think you are putting these computed outputs somewhere. Do logic here. List all the block’s inputs here in the “sensitivity list” In Verilog, always statement is considered as procedural statement Initial is another procedural statement

40 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); output f; input sel, b, c; regf; (sel or b or c) if (sel == 1) f = b; else f = c; endmodule module exam2 (f, g, sel, b, c); output f, g; input sel, b, c; regf, g; (sel or b or c) if (sel == 1) f = b; else g = c; endmodule wrong model correct model

41 module logic1 (f, a, b, c); output f; input a, b, c; regf; (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; endcase endmodule Behavioral Model for Combinational Logic: Case statement Generate a truth table, assign output f in each case item {a, b, c} concatenates a, b, and c together, considering them as a single item

42 module mux2x1_df (A,B,select,OUT); input A,B,select; output OUT; assign OUT = select ? A : B; endmodule module mux4x1_bh (i0,i1,i2,i3,select,y); input i0,i1,i2,i3; input [1:0] select; output y; reg y; (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; endcase endmodule OUT = A if select = 1, else OUT = B if select =0

43 module name (, ); output ; input ; reg ; ( ) begin end endmodule Verilog behavioral model for combinational logic