verilog hdl chapter 4

24
7/24/2019 verilog hdl chapter 4 http://slidepdf.com/reader/full/verilog-hdl-chapter-4 1/24 E&C-ENG 5535 Verilog HDL Lecture 04 Chapter 03 Language Elements

Upload: pranaysingireddy

Post on 21-Feb-2018

248 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: verilog hdl chapter 4

7/24/2019 verilog hdl chapter 4

http://slidepdf.com/reader/full/verilog-hdl-chapter-4 1/24

E&C-ENG 5535Verilog HDL

Lecture 04Chapter 03

Language Elements

Page 2: verilog hdl chapter 4

7/24/2019 verilog hdl chapter 4

http://slidepdf.com/reader/full/verilog-hdl-chapter-4 2/24

Chapter Outline

!  Language Elements

!  Comments

!  Identifiers

!  Keywords!  Bidirectional Gates

!  Charge Storage Strength

!  ……….

!  Value Set

Compiler Directives

Chaudhry-Lecture 04, Ch. 03 29/2/15

Page 3: verilog hdl chapter 4

7/24/2019 verilog hdl chapter 4

http://slidepdf.com/reader/full/verilog-hdl-chapter-4 3/24

Chaudhry-Lecture 04, Ch. 03 3

Comments

!  Two types:!

 

Single line comment

//This is a single-line comment on a dedicated line

!  Multiple lines comment

/* This is a multiple-line comment.More comments go here.

More comments. */

9/2/15

Page 4: verilog hdl chapter 4

7/24/2019 verilog hdl chapter 4

http://slidepdf.com/reader/full/verilog-hdl-chapter-4 4/24

Chaudhry-Lecture 04, Ch. 03 4

Identifiers

!  An identifier  is a name given to an object or variable so that it can be referencedelsewhere in the design.!   An identifier should be:

!  Unique

!  The first character must be a letter  or underscore ( _ )!  It is case sensitive.!  Can contain up to 1024 characters

Input  a, b, cin; //a, b, and cin are identifiers

output sum, cout; //sum and cout are identifiersreg  z1;

!  Escaped identifiers begin with a backslash ( \ ) and end with a white space (space,

tab, or new line) and provide means to include any printable ASCII character in an

identifier. For example; \assign is different than the keyword assign

\2005

\~$~\*************

9/2/15

Page 5: verilog hdl chapter 4

7/24/2019 verilog hdl chapter 4

http://slidepdf.com/reader/full/verilog-hdl-chapter-4 5/24

  Category Keywords

Bidirectional gates rtrantran

rtranif0tranif0

rtranif1tranif1

Charge Storage Strengths large medium small

CMOS Gates cmos rcmos

Combinational Logic Gates andnorxnor

bufnotxor

nandor

Continuous Assignment assign

Data Types integerregtri

triandvectored

wor

realscalaredtri0

triorwand

realtimetimetri1

triregwire

Module Declaration module endmodule

MOS Gates nmosrpmos

pmos rnmos

Multiway Branching casedefault

casexendcase

casez

Named Event event

Parameters defparam parameter specparam

Port Declaration inout input output

Procedural Constructs always initial

Procedural Continuous Assignment assignrelease

deassign force

Keywords:Verilog has alist of specialpredefined,

non-escapedidentifierscalledkeywords.

5Chaudhry-Lecture 04, Ch. 039/2/15

Page 6: verilog hdl chapter 4

7/24/2019 verilog hdl chapter 4

http://slidepdf.com/reader/full/verilog-hdl-chapter-4 6/24

  Category Keywords

Signal Strengths highz0pull1supply0weak1

highz1strong0supply1

pull0strong1weak0

Specify Block specify endspecify

Tasks & Functions function

task

endfunction

endtask

Three-State Gates bufif0notif1

bufif1 notif0

Timing Control edge negedge posedge

User-defined Primitives primitivetable

endprimitiveendtable

Procedural Flow control beginendforkrepeat

disableforifwait

elseforever

 joinwhile

Pull Gates pulldown pullup

Keywords (Cont…)

6Chaudhry-Lecture 04, Ch. 039/2/15

Page 7: verilog hdl chapter 4

7/24/2019 verilog hdl chapter 4

http://slidepdf.com/reader/full/verilog-hdl-chapter-4 7/24

Chaudhry-Lecture 04, Ch. 03 7

Keywords: Bidirectional Primitive Gates

!  The signals on either side of the gates can bespecified as inputs or inout.

!  tran (transmission) gate (switch): act as a buffer

between two signals!  tran, tranif0, tranif1, rtran, rtranif0, rtranif1

are bidirectional primitive gates

Example: tran inst1(inout1, inout2); 

9/2/15

Page 8: verilog hdl chapter 4

7/24/2019 verilog hdl chapter 4

http://slidepdf.com/reader/full/verilog-hdl-chapter-4 8/24

Chaudhry-Lecture 04, Ch. 03 8

Keywords: Bidirectional Primitive Gates

!  tranif0 and tranif1 have two bidirectional terminals

plus a control input.tranif0 inst1(inout1, inout2, control);

 As, tranif0 gate connects the two signals only if thecontrol input is a logical 0, otherwise the output of the

gate is a high impendence.

!  rtran, rtranif0, rtranif1 are called resistive gates. Theyoperate the same way as previous gates but have highersource-to-drain impedance.

9/2/15

Page 9: verilog hdl chapter 4

7/24/2019 verilog hdl chapter 4

http://slidepdf.com/reader/full/verilog-hdl-chapter-4 9/24

Chaudhry-Lecture 04, Ch. 03 9

Keywords: CMOS Gates

!   A cmos gate can be modeled with nmos and pmos 

device to implement cmos transmission gate.

!  The rmos gate is high resistive version of the cmos 

gate.

cmos inst1 (output, data_input, n_enable, p_enable);

nmos inst2 (output, input, control);

pmos inst3 (output, input, control);

9/2/15

Page 10: verilog hdl chapter 4

7/24/2019 verilog hdl chapter 4

http://slidepdf.com/reader/full/verilog-hdl-chapter-4 10/24

Chaudhry-Lecture 04, Ch. 03 10

Keywords: Value Set

!  Sometimes {0,1} binary set is not enough torepresent the state of a switch.

!  See the following case:

a

 b

0

1

cIf a = b = 0, c = ?

If a = b = 1, c = ?

9/2/15

Page 11: verilog hdl chapter 4

7/24/2019 verilog hdl chapter 4

http://slidepdf.com/reader/full/verilog-hdl-chapter-4 11/24

Chaudhry-Lecture 04, Ch. 03 11

Keywords: Value Set ….

!  a = b = 0, c = Z

!  a = b = 1, c = X

!  Initially, every line is X

!  X is used in simulation.

In real circuit, the value is determined by thecircuit

a

 b

0

1

c

9/2/15

Page 12: verilog hdl chapter 4

7/24/2019 verilog hdl chapter 4

http://slidepdf.com/reader/full/verilog-hdl-chapter-4 12/24

Chaudhry-Lecture 04, Ch. 03 12

Keywords: Value Set…

!  0: Logical 0; // false condition

1: Logical 1; // true condition

!  X: Unknown logic value

Z: High impedance; // floating state

and 0 1 Z X

0 0 0 0 0

1 0 1 X X

Z 0 X X X

X 0 X X X

9/2/15

Page 13: verilog hdl chapter 4

7/24/2019 verilog hdl chapter 4

http://slidepdf.com/reader/full/verilog-hdl-chapter-4 13/24

Chaudhry-Lecture 04, Ch. 03 13

Keywords: Value Set…

!  b = X-bar

But in Verilog, there is no such thing as “X-bar ”!

  If  b = X, and therefore a = X, which should be 0

X a = ? b

X and X-bar  Problem

9/2/15

Page 14: verilog hdl chapter 4

7/24/2019 verilog hdl chapter 4

http://slidepdf.com/reader/full/verilog-hdl-chapter-4 14/24

Chaudhry-Lecture 04, Ch. 03 14

Keywords:Combinational LogicGates

and, nand, or, nor,xor, xnor, buf, not are all called

combinational logicgates

gate_type inst1(output,

input_1, input_2, …);

and

Truth table for ANDGate Built-In-

Primitive

Inputsx1 x2

Outputz

0 0 0

0 1 0

1 0 0

1 1 1

0 x 0

0 z 0

1 x x

1 z x

Inputsx1 x2

Outputz

x 0 0

x 1 x

x x x

x z x

z 0 0z 1 x

z x x

z z x

9/2/15

Page 15: verilog hdl chapter 4

7/24/2019 verilog hdl chapter 4

http://slidepdf.com/reader/full/verilog-hdl-chapter-4 15/24

Chaudhry-Lecture 04, Ch. 03 15

Keywords:Combinationa

l LogicGates…

or

Truth table for ORGate Built-In-

Primitive

Inputsx1 x2

Outputz

0 0 0

0 1 1

1 0 11 1 1

0 x x

0 z x

1 x 1

1 z 1

Truth table for ORGate Built-In-

Primitive

Inputsx1 x2

Outputz

x 0 xx 1 1

x x x

x z x

z 0 xz 1 1

z x x

z z x

9/2/15

Page 16: verilog hdl chapter 4

7/24/2019 verilog hdl chapter 4

http://slidepdf.com/reader/full/verilog-hdl-chapter-4 16/24

Chaudhry-Lecture 04, Ch. 03 16

Keywords: Combinational LogicGates…

Truth table for bufGate

Input Output

0 0

1 1

x x

z x

buf  a non-inverting primitive with

one scalar input and one or

more scalar outputs.

buf  inst1(output, input); //one output

buf  inst2(output_1, output_2, …, output_n, input);//multiple outputs

9/2/15

Page 17: verilog hdl chapter 4

7/24/2019 verilog hdl chapter 4

http://slidepdf.com/reader/full/verilog-hdl-chapter-4 17/24

Chaudhry-Lecture 04, Ch. 03 17

Keywords:

CombinationalLogic Gates …

nand

Truth table for NANDGate for the AND

function

Inputsx1 x2

Outputz

0 0 1

0 1 1

1 0 1

1 1 0

0 x 1

0 z 1

1 x x

1 z x

Truth table for NANDGate for the OR

function

Inputsx1 x2

Outputz

x 0 1x 1 x

x x x

x z x

z 0 1z 1 x

z x x

z z x

9/2/15

Page 18: verilog hdl chapter 4

7/24/2019 verilog hdl chapter 4

http://slidepdf.com/reader/full/verilog-hdl-chapter-4 18/24

Chaudhry-Lecture 04, Ch. 03 18

Keywords

(Cont…)CombinationalLogic Gates…

nor

Truth table for NORGate for the OR

function

Inputsx1 x2

Outputz

x 0 x

x 1 0

x x x

x z x

z 0 xz 1 0

z x x

z z x

Truth table for NORGate for the AND

function

Inputsx1 x2

Outputz

0 0 1

0 1 0

1 0 0

1 1 0

0 x x

0 z x

1 x 0

1 z 0

9/2/15

Page 19: verilog hdl chapter 4

7/24/2019 verilog hdl chapter 4

http://slidepdf.com/reader/full/verilog-hdl-chapter-4 19/24

Chaudhry-Lecture 04, Ch. 03 19

Keywords: Combinational LogicGates…

notTruth table for the

logical NOT built-In-Primitive

Input Output

0 1

1 0

x xz x

9/2/15

Page 20: verilog hdl chapter 4

7/24/2019 verilog hdl chapter 4

http://slidepdf.com/reader/full/verilog-hdl-chapter-4 20/24

Chaudhry-Lecture 04, Ch. 03 20

Keywords: Combinational LogicGates…

xorTruth table for LogicalExclusive-OR Built-In-

Primitive

Inputsx1 x2

Outputz1

x 0 x

x 1 x

x x x

x z x

z 0 xz 1 x

z x x

z z x

Truth table for LogicalExclusive-OR Built-In-

Primitive

Inputsx1 x2

Outputz1

0 0 0

0 1 1

1 0 1

1 1 0

0 x x

0 z x

1 x x1 z x

9/2/15

Page 21: verilog hdl chapter 4

7/24/2019 verilog hdl chapter 4

http://slidepdf.com/reader/full/verilog-hdl-chapter-4 21/24

Chaudhry-Lecture 04, Ch. 03 21

Keywords: Combinational LogicGates…

xnor

Truth table for LogicalExclusive-NOR Built-

In-Primitive

Inputsx1 x2

Outputz1

0 0 1

0 1 0

1 0 01 1 1

0 x x

0 z x

1 x x

1 z x

Truth table for LogicalExclusive-NOR Built-

In-Primitive

Inputsx1 x2

Outputz1

x 0 x

x 1 x

x x x

x z x

z 0 xz 1 x

z x x

z z x

9/2/15

Page 22: verilog hdl chapter 4

7/24/2019 verilog hdl chapter 4

http://slidepdf.com/reader/full/verilog-hdl-chapter-4 22/24

Chaudhry-Lecture 04, Ch. 03 22

Keywords :Three-State

Gates…  

Truth table for buff0

Input Control Output0 0 0

0 1 z

0 x 0/z

0 z 0/z

1 0 11 1 z

1 x 1/z

1 z 1/z

x 0 x

x 1 z

x x x

x z x

z 0 x

z 1 z

z x x

z z x

Truth table for buff1

Input Control Output0 0 z

0 1 0

0 x 0/z

0 z 0/z

1 0 z

1 1 1

1 x 1/z

1 z 1/z

x 0 z

x 1 x

x x x

x z x

z 0 z

z 1 x

z x x

z z x9/2/15

Page 23: verilog hdl chapter 4

7/24/2019 verilog hdl chapter 4

http://slidepdf.com/reader/full/verilog-hdl-chapter-4 23/24

Chaudhry-Lecture 04, Ch. 03 23

Keywords:

Three-StateGates…

Truth table for notif0

Input Control Output0 0 1

0 1 z

0 x 1/z

0 z 1/z

1 0 01 1 z

1 x 0/z

1 z 0/z

x 0 x

x 1 z

x x x

x z x

z 0 x

z 1 z

z x x

z z x

Truth table for notif1

Input Control Output0 0 z

0 1 1

0 x 1/z

0 z 1/z

1 0 z

1 1 0

1 x 0/z

1 z 0/z

x 0 z

x 1 x

x x x

x z x

z 0 z

z 1 x

z x x

z z x9/2/15

Page 24: verilog hdl chapter 4

7/24/2019 verilog hdl chapter 4

http://slidepdf.com/reader/full/verilog-hdl-chapter-4 24/24

Summary

!  Language Elements

!  Comments

Identifiers!

  Keywords: Bidirectional Gates

Chaudhry-Lecture 04, Ch. 03 249/2/15