+ All Categories
Home > Documents > Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370...

Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370...

Date post: 20-Mar-2020
Category:
Upload: others
View: 14 times
Download: 0 times
Share this document with a friend
62
Introduction to Digital Design using Verilog EE370 Ashish Bhatia
Transcript
Page 1: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

Introduction to Digital Design using Verilog

EE370Ashish Bhatia

Page 2: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level
Page 3: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

What is Verilog?

models digital hardwareto what extent?

models digital hardwarecombinatoricsequential

use for synthesizing digital hardwarefpgaasic

Page 4: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

modeling digital hardware

to what extent?

Page 5: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

A CMOS inverter has nMOS transistor with L = 10 units, W = 20 units, Kn = 400 and pMOS transistor with L = 10 units, W=40 units, Kp = 400

Can Verilog model this?

Page 6: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

A CS amplifier has gain = -10 and cut-off freq = 20 MHz

Can Verilog model this?

Page 7: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

A spice generated netlist of resistors and capacitors

Can Verilog model this?

Page 8: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

An inverter with Tr = 1 ns, Tf = 500 ps and Tp = 800 ps

Can Verilog model this?

Page 9: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

Can Verilog model this?

A B F

0 0 0

0 1 1

1 0 1

1 1 0

Page 10: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

Can Verilog model this?

Q(n) X Q(n+1)

0 0 0

0 1 1

1 0 1

1 1 0

Page 11: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

modeling digital hardware

combinatoricsequential

Page 12: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

consider combinatoric first

Page 13: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

NOT Gate

module Not ( input wire x, output wire y);

assign y = ~x;

endmodule

Page 14: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

NOT Gate

module Not ( input wire x, output wire y);

assign y = ~x;

endmodule

Page 15: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

NOT Gate

module Not ( input wire x, output wire y);

assign y = ~x;

endmodule

Page 16: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

NOT Gate

module Not ( input wire x, output wire y);

assign y = ~x;

endmodule

Page 17: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

NOT Gate (of parallel bus)

module Not ( input wire [7:0] x, output wire [7:0] y);

assign y = ~x;

endmodule

Page 18: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

AND Gate

module And ( input wire x, input wire y output wire z);

assign z = x&y;

endmodule

Page 19: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

do Nand, Nor, Xor, Or gate yourself

Page 20: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

Hardware Abstraction

behavioralhighest level of abstractionfarthest from hardwareclosest to ideas (thinking)

dataflowhardware described in boolean (logic)

combinatoricsequential

structuralhardware described in terms of fundamental gates

Page 21: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

Let us analyze 1-bit adder for all three cases

Page 22: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

Behavioral design (adder)

module adder_b(in1, in2, sum, carry);

input wire in1, in2;output wire sum, carry;

assign {carry, sum} = in1 + in2; endmodule

Page 23: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

Behavioral design (adder)

module adder_b(in1, in2, sum, carry);

input wire in1, in2;output wire sum, carry;

assign {carry, sum} = in1 + in2; endmodule

Addition is a high level construct Verilog compiler will generate the code for addition

Page 24: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

DataFlow Design (adder)

module adder_d(in1, in2, sum, carry);

input wire in1, in2;output wire sum, carry;

assign sum = in1 ^ in2;assign carry = in1 & in2; endmodule

Page 25: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

DataFlow Design (adder)

module adder_d(in1, in2, sum, carry);

input wire in1, in2;output wire sum, carry;

assign sum = in1 ^ in2;assign carry = in1 & in2; endmodule

Boolean logic - more fundamental construct than addition

Page 26: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

Structural Design (adder)

module adder_s(in1, in2, sum, carry);

input wire in1, in2;output wire sum, carry;

and g0(carry,in1,in2);

xor g1(sum,in1,in2);

endmodule

Page 27: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

Structural Design (adder)

module adder_s(in1, in2, sum, carry);

input wire in1, in2;output wire sum, carry;

and g0(carry,in1,in2);

xor g1(sum,in1,in2);

endmoduleAssuming and and xor gates are available

Page 28: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

Structural Design (adder)

module adder_s(in1, in2, sum, carry);//Assume only NAND gates are available

input wire in1, in2;output wire sum, carry;wire signal1, signal2, signal3;//intermediate wires

nand n0 (signal1, in1, in2);nand n1 (carry, signal1, signal1);

nand n2 (signal2, in1, signal1);nand n3 (signal3, in2, signal1);nand n4 (sum, signal2, signal3);endmodule

Assuming only nand gates are available

Page 29: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

what about sequential elements?

Page 30: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

let us consider D F/F

Page 31: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

D F/F

module D_FF ( input wire clk, input wire d, output reg q ); always @(posedge clk) begin q <= #2 d; endendmodule

Page 32: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

D F/F

module D_FF ( input wire clk, //every sequential circuit element has a trigger input wire d, output reg q ); always @(posedge clk) begin q <= #2 d; endendmodule

Page 33: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

D F/F

module D_FF ( input wire clk, //every sequential circuit element has a trigger input wire d, output reg q //output need to be a register to hold the value ); always @(posedge clk) begin q <= #2 d;

endendmodule

Page 34: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

D F/F

module D_FF ( input wire clk, //every sequential circuit element has a trigger input wire d, output reg q //output need to be a register to hold the value ); always @(posedge clk) begin //posedge triggered q <= #2 d;

endendmodule

Page 35: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

D F/F

module D_FF ( input wire clk, //every sequential circuit element has a trigger input wire d, output reg q //output need to be a register to hold the value ); always @(posedge clk) begin //posedge triggered q <= #2 d; //2 units (propagation delay)

endendmodule

Page 36: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

D F/F

module D_FF ( input wire clk, //every sequential circuit element has a trigger input wire d, output reg q //output need to be a register to hold the value ); always @(posedge clk) begin //posedge triggered q <= #2 d; //2 units (propagation delay) //non-blocking assignment

endendmodule

Page 37: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

D F/F

module D_FF ( input wire clk, //every sequential circuit element has a trigger input wire d, output reg q //output need to be a register to hold the value ); always @(posedge clk) begin //posedge triggered q <= #2 d; //2 units (propagation delay) //non-blocking assignment //assuming setup and hold are not //violated endendmodule

Page 38: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

D F/F (with reset)module D_FF ( input wire clk, //every sequential circuit element has a trigger input wire d, input wire rst, output reg q ); always @(posedge clk or posedge rst) begin //posedge triggered if(rst == 1) q <= #2 1'b0; else q <= #2 d; //2 units (propagation delay) //non-blocking assignment //assuming setup and hold are not //violated endendmodule

Page 39: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

Will "reg" always correspond to reg in hardware?

Page 40: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

Consider 2x1 MUX

Page 41: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

2x1 MUX

module MUX_2_1 ( input wire a, input wire b, input wire sel output reg op);

always @(sel or a or b) begin if(sel) op = b; else op = a;end endmodule

Page 42: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

2x1 MUX

module MUX_2_1 ( input wire a, input wire b, input wire sel output reg op);

always @(sel or a or b) begin if(sel) op = b; else op = a;end endmodule

op will be implemented as wire only if 1) a and b both are in sensitivity list of always block 2) all possible cases are covered in if-else or switch

Page 43: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

2x1 MUX

module MUX_2_1 ( input wire a, input wire b, input wire sel output reg op);

always @(sel or a or b) begin if(sel) op = b; else op = a;end endmodule

op will be implemented as wire only if 1) a and b both are in sensitivity list of always block 2) all possible cases are covered in if-else or switch

This is behavioral model of 2-1 MUXwhat will be dataflow model?

Page 44: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

2x1 MUX (data flow model)

module MUX_2_1 ( input wire a, input wire b, input wire sel output wire op);

assign op = sel?b:a; endmodule

Page 45: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

4x1 MUX (data flow model)

module MUX_2_1 ( input wire a, input wire b, input wire c, input wire d, input wire sel[1:0], output wire op);

assign op = (sel[1]==1)?(sel[0]==1?d:c):(sel[0]==1?b:a); endmodule

A 32 operation ALU is like 32-1 MUX, try writing ternary operations for that :)

Page 46: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

4x1 MUX - behavioral model

module MUX_2_1 ( input wire a, input wire b, input wire c, input wire d, input wire sel[1:0], output reg op);

always @(sel or a or b or c or d) begin case(sel) 2'b00: op = a; 2'b01: op = b; 2'b10: op = c; 2'b11: op = d; endendmodule

Page 47: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

is wire (in verilog) always synthesized as wire?

Page 48: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

yes

Page 49: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

is reg (in verilog) always synthesized as reg?

Page 50: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

most of the times yes, but in some case if design permits,

optimization occurs

Page 51: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

Designing Test Benches

why?

Page 52: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

Consider XOR Gate

module XOR(input wire A, input wire B, output wire X); assign X = A^B; endmodule

Page 53: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

XOR Test Bench

module TB_XOR(); reg A, B; reg clk; wire X; XOR xor1(.A(A), .B(B), .X(X)); initial begin clk = 0; end initial begin forever clk = #5 ~clk; //clk with period = 10 end

always @(posedge clk) begin A<=0; B<=0; #5; A<=0; B<=1; #5; A<=1; B<=0; #5; A<=1; B<=1; end

endmodule

Page 54: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

Unsynthesizable Constructs

reg clk;

intial begin clk <= 0; forever clk = #10 ~clk; end

Page 55: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

Unsynthesizable Constructs

reg a = 1'bx;reg b = 1'bz;

x or X (uninitialized state)z or Z (high impedance state) - can be synthesized using tri-state buffers but not directly

Page 56: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

If they cannot be synthesizd why do we need them?

Page 57: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

Remember verilog is for1) Simulation2) FPGA based design3) ASIC based design

Page 58: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

Simulationunsynthesizable constructs are needed for simulation

Page 59: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

FPGA vs ASIC

Some constructs are synthesizable on FPGA but not ASIClike initial block requires explicit hardware implementation on ASIC

Timing failures In case of FPGA, compiler ensures proper floorplan to minimize such failuresIn ASIC, floorplan is manual, timing faliures are more probable

Page 60: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

Preprocessors

`define DELAY 2 //macro definition just like in C`include mylib.v //include just like in C`ifdef ENABLE_MY_CODE//my code goes here`endif

b <= `DELAY a;

Page 61: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

Misc

Open Drain Configall inputs low => output is highotherwise output is lowwor is use to model not of open drain config similarly wand models not of open collector config

Page 62: Introduction to Digital Design using VerilogIntroduction to Digital Design using Verilog EE370 Ashish Bhatia. What is Verilog? models digital hardware to what extent? ... highest level

Good Reference Book: Verilog HDL by Palnitkar


Recommended