1 verilog gate

Upload: enzuek

Post on 02-Apr-2018

229 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/27/2019 1 Verilog Gate

    1/32

    VERILOG HDL

    Gate Level Modeling

  • 7/27/2019 1 Verilog Gate

    2/32

    What is Verilog ?

    Verilog is a Hardware Description Language (HDL).

    Design and document electronic systems.

    Supports different levels of abstraction.

    Structural or Gate Level Re ister Transfer Level (RTL)

    ECE301 VLSI System Desig n2

    Behavioral

    Higher Level of abstraction improves productivity

    Technology independent specification.

    Syntax is similar to C

  • 7/27/2019 1 Verilog Gate

    3/32

    History of Verilog

    Gateway Design Automation. Proprietary language developed in 1985

    Developed to SIMULATE only

    Product was VERILOG-XL

    Synthesis capabilities were added latter on

    Became ver o ular

    ECE301 VLSI System Desig n3

    Cadence Design Automation

    Acquired it in 1989.

    Open Verilog International (OVI) Cadence makes it public in 1990

    IEEE Verilog standard 1364 in 1995

  • 7/27/2019 1 Verilog Gate

    4/32

    Verilog Basic

    Verilog

    case sensitive language

    temp, Temp, TEMP are different names

    keywords are lower case

    Comments are specified as

    ECE301 VLSI System Desig n4

    // This is a single line comment

    /* This is how a multiple-line

    comment is specified in Verilog.. */

    Multiple line comments cant be nested

    Semicolon(;) are line terminators

    Notice the similarity to C

  • 7/27/2019 1 Verilog Gate

    5/32

    Four Valued Logic

    Verilogs bit can take 4 values

    Logic high (1)

    Logic low (0)

    High Impedance (z)

    ECE301 VLSI System Desig n5

    g mpe ance s a e o r s a e.

    Unknown (x)

    Model conflict or un-initialized state

    is only a debugging aid

  • 7/27/2019 1 Verilog Gate

    6/32

    Structural Model

    Specify the structure of design gate primitives

    connecting wires

    //Example of 2:1 mux

    module mux (y, a, b, sel );

    Single Line Comment

    Component Interface

    ECE301 VLSI System Desig n6

    input a, b, sel ;

    wire y1, y2, sel_n ;

    not A1 (sel_n, sel);

    and A2 (y1, a, sel_n);

    and A3 (y2,b, sel);

    or A4 (y,y1,y2);

    endmodule

    Gate & Connections

  • 7/27/2019 1 Verilog Gate

    7/32

    Module

    Basic unit used to specify a hardware entity. Nesting of modules is not allowed.

    Defines interface

    module mux (y, a, b, sel );

    module_name

    ECE301 VLSI System Desig n7

    input a, b, sel ;

    wire y1, y2, sel_n ;

    not A1 (sel_n, sel);

    and A2 (y1, a, sel_n);

    and A3 (y2,b, sel);

    or A4 (y,y1,y2);

    endmodule

    Interface list

    Denotes end of module description

    MUX y

    sel

    a

    b

  • 7/27/2019 1 Verilog Gate

    8/32

    Identifiers

    Name given to objects for referencing example mux, y, a, b, sel

    Identifier naming rules

    can be 1023 characters long

    cannot be a VERILOG reserved keyword

    ECE301 VLSI System Desig n8

    module, endmodule, input etc.

    First character must be a alphabet or underscore

    Can contain alphanumeric, underscore (_), or $.

    Names must be sensible and improve readability. ASH is also a legal module name

  • 7/27/2019 1 Verilog Gate

    9/32

    Port Declaration

    Used to specify the port direction. input Input port

    output Output port

    inout Bi-directional port

    module mux ( y, a, b, sel );

    ECE301 VLSI System Desig n9

    input a, b, sel ;

    wire y1, y2, sel_n ;

    not A1 (sel_n, sel);

    and A2 (y1, a, sel_n);

    and A3 (y2,b, sel);

    or A4 (y,y1,y2);

    endmodule

    Interface listPort

    Decla-

    ration MUX y

    sel

    a

    b

  • 7/27/2019 1 Verilog Gate

    10/32

    Port Connection Rules

    net and reg are data types in Verilog will explain them

    output port

    MODULE

    input port

    ECE301 VLSI System Desig n10

    nereg

    or netnetreg

    or net

    inout port

    net

    net

  • 7/27/2019 1 Verilog Gate

    11/32

    Data types

    Net : is not a keyword but represents a class wire, wand, wor, tri, triand, trior, trireg

    Used for connection.

    Values should be continuously driven

    module mux (y, a, b, sel );

    ECE301 VLSI System Desig n11

    output y ;

    input a, b, sel ;

    wire y1, y2, sel_n ;

    not A1 (sel_n, sel);

    and A2 (y1, a, sel_n);

    and A3 (y2,b, sel);

    or A4 (y,y1,y2);

    endmodule

    wire is the default data type

    wire and tri are exactly identical

    separate names indicate purpose.

    Net value is x for multiple driversNet value is z without any drivers

  • 7/27/2019 1 Verilog Gate

    12/32

    Data types contd

    reg represent data storage element need not be continuously driven

    Retain value until driven again

    Default value is x

    Dont confuse them with Hardware

    ECE301 VLSI System Desig n12

    need not infer a register, latch or flip-flop !!!

  • 7/27/2019 1 Verilog Gate

    13/32

    Logic Gate Primitives

    Verilog has predefined primitives for logic gates Pins of primitive gates are expandable

    module mux (y, a, b, sel );

    output y ;

    Supported Gates are

    AND : and (out, in1, in2,inN) ;

    OR : or (out, in1, in2,inN);

    ECE301 VLSI System Desig n13

    , ,

    wire y1, y2, sel_n ;

    not A1 (sel_n, sel);

    and A2 (y1, a, sel_n);

    and A3 (y2,b, sel);or A4 (y,y1,y2);

    endmodule

    , 1, 2, N

    NAND : nand (out, in1, in2,inN);

    NOR : nor (out, in1, in2,inN);

    XNOR : xnor (out, in1, in2,inN);

    BUFFER : buf (out1, ., outN, in);Inverter : not (out1,.. , outN, in);

  • 7/27/2019 1 Verilog Gate

    14/32

    Instance

    Instantiation is the process of calling a module 4 gates are instantiated in our mux example

    The referred module are called instances

    2 instance of AND and 1 instance each of OR & NOT

    module mux (y, a, b, sel );

    ECE301 VLSI System Desig n14

    output y ;

    input a, b, sel ;

    wire y1, y2, sel_n ;

    not A1 (sel_n, sel);

    and A2 (y1, a, sel_n);

    and A3 (y2,b, sel);

    or A4 (y,y1,y2);

    endmodule

    instance_name

    A1, A2, A3 & A4

    Positional Instantiation

    not (out, in)

    not (sel_n, sel)

    outinsel sel_n

  • 7/27/2019 1 Verilog Gate

    15/32

    Question

    Design a 4-to-1 mux using 2-to-1 mux

    Write the verilog code for the same

    Hint : instantiate the 2-to-1 mux from our example

    mux4_1

    a

    ECE301 VLSI System Desig n15

    sel1 sel0 -> y

    0 0 -> a

    0 1 -> b

    1 0 -> c

    1 1 -> d

    c

    d

    y

    sel0 sel1

  • 7/27/2019 1 Verilog Gate

    16/32

    Answer

    module mux4_1 (y, a, b, c, d, sel0, sel1 );

    output y ;

    input a, b, c, d, sel ;

    wire y1, y2 ;

    Named Instantiationis RECOMMENDED

    Predefined Primitives can use

    only positional instantiation

    ECE301 VLSI System Desig n16

    mux M1 (.y(y1), .a(a), .b(b), .sel(sel0));

    mux M2 (.y(y2), .a(c), .b(d), .sel(sel0));

    mux M3 (.y(y), .a(y1), .b(y2), .sel(sel1));

    endmodule

    mux M1 (y1, a, b, sel0);

    mux M2 (y2, c, d, sel0);

    mux M3 (y, y1, y2, sel1);

  • 7/27/2019 1 Verilog Gate

    17/32

    Vector

    module mux4_1 (y, in, sel );

    output y ;

    input [3:0] in ;

    input [1:0] sel

    Also known as BUS in hardware Group of signals

    Syntax [MSB:LSB]

    2-bit wide bus

    ECE301 VLSI System Desig n17

    wire y1, y2 ;

    wire [1:0] sel;

    wire [3:0] in

    mux M1 (.y(y1), .a(in[0]), .b(in[1]), .sel(sel[0]) );mux M2 (.y(y2), .a(in[2]), .b(in[3]), .sel(sel[0]) );

    mux M3 (.y(y), .a(y1), .b(y2), .sel(sel[1]) );

    endmodule

    Bit Select of a bus

  • 7/27/2019 1 Verilog Gate

    18/32

    Unconnected Ports

    Unused input port Always connect to either 1 or 0

    Value such that functionality is not effected

    Unused output port

    Leave it floating

    ECE301 VLSI System Desig n18

    Example

    module parity_gen(even_pty, odd_pty, datain) ;

    parity_gen P1 (parity, ,datain) ;

    parity_gen P1 (.datain(datain), .even_pty(parity));

  • 7/27/2019 1 Verilog Gate

    19/32

    Assignment 1

    Write Verilog Gate or Structural code for 16 to 1 mux

    using mux4_1

    3 line to 8 line decoder

    ECE301 VLSI System Desig n19

    - -

    Half Adder

    Full Adder

    using logic gates

    using the above defined Half Adder

    http://www.angelfire.com/electronic/AnandVenkat/verilog.html

  • 7/27/2019 1 Verilog Gate

    20/32

    Tristate Gate Primitive

    Tristate Gate Primitives bufif1(out,in,ctl); : Tristate buffer with active high enable

    bufif0 (out,in,ctl); : Tristate buffer with active low enable

    notif1(out,in,ctl); : Tristate inverter with active high enable

    notif0 (out,in,ctl); : Tristate inverter with active low enable

    ECE301 VLSI System Desig n20

    module guess_me ( y, a, b, sel ) ;

    input a, b, sel ;

    output y ;

    bufif0 B2 (y,a,sel) ;bufif1 B1 (y,b,sel) ;

    endmodule

    What logic function

    does this module perform ?

  • 7/27/2019 1 Verilog Gate

    21/32

    Advanced Nets

    wor and trior models wired OR connection supports multiple drivers to be active at the same time

    the net value is 1 if any driver value is 1

    wand and triand models wired AND connection

    supports multiple drivers to be active at the same time

    ECE301 VLSI System Desig n21

    the net value is 0 if any driver value is 0

    &

    &

    a

    b

    c

    d

    wor

    y

    y = ( a ? b ) ? ( c ? d)

    |

    |

    b

    c

    d

    wand

    y = ( a ? b ) ? ( c ? d)

  • 7/27/2019 1 Verilog Gate

    22/32

    Example Code

    &

    &

    a

    b

    c

    d

    wor

    y

    |

    |

    b

    c

    d

    wand

    module and_or (y, a, b, c, d );

    module or_and (y, a, b, c, d );

    a

    ECE301 VLSI System Desig n22

    output y ;

    input a, b, c, d ;

    wor y ;

    and A1 (y, a, b);

    and A2 (y, c, d);

    endmodule

    output y ;

    input a, b, c, d ;

    wand y ;

    or A1 (y, a, b);

    or A2 (y, c, d);

    endmodule

  • 7/27/2019 1 Verilog Gate

    23/32

    Advanced Nets

    supply1 models power supply connection the value of these net is always 1

    synthesizer treats this net as logic 1.

    supply0 models power ground connection

    the value of these net is always 0

    ECE301 VLSI System Desig n23

    synthesizer treats this net as logic 0.

  • 7/27/2019 1 Verilog Gate

    24/32

    Advanced Nets

    tri0 models resistive pulldown similar to tri expect that the net value is 0 if no drivers tri1 models resistive pullup

    the net value is 1 if no drivers

    No synthesis support

    ECE301 VLSI System Desig n24

    , ,

    output y ;

    input a, b ;

    tri0 y ;

    supply1 vdd;bufif1 B1 (y, vdd, a);

    bufif1 B2 (y, vdd, b);

    endmodule

    , ,

    output y ;

    input a, b ;

    tri1 y ;

    supply0 gnd;bufif1 B1 (y, gnd, a);

    bufif1 B2 (y, gnd, b);

    endmodule

  • 7/27/2019 1 Verilog Gate

    25/32

    Advanced Nets

    trireg model net with capacitance the net holds (remembers) the last driven value if no drivers

    models bus-keeper circuit

    No synthesis support

    in

    trireg

    out

    ECE301 VLSI System Desig n25

    sel

    insel

  • 7/27/2019 1 Verilog Gate

    26/32

    MOS Gate Primitive

    Transistor level primitves (Non-Synthesizable) Model MOS transistor as switches

    nmos(out,in,ctl);

    pmos(out,in,ctl);

    ECE301 VLSI System Desig n26

    nmos

    ctl

    in

    out

    ctl

    in

    outpmos

    Active high enable switch Active low enable switch

  • 7/27/2019 1 Verilog Gate

    27/32

    MOS example

    CMOS NOT GATE

    module not_mos ( out, in ) ;

    input in ;

    output out ;

    out

    Vdd

    in

    ECE301 VLSI System Desig n27

    supply1 vdd ;

    supply0 gnd ;

    nmos N1 (out,gnd,in) ;

    pmos P1 (out,vdd,in) ;

    endmodule

  • 7/27/2019 1 Verilog Gate

    28/32

    Assignment 2

    Write Verilog code using MOS primitives for

    2 input CMOS AND gate

    2 input CMOS XOR gate

    3 in ut CMOS OR ate

    ECE301 VLSI System Desig n28

    3 input CMOS gate with boolean expression

    Y = A . B + C

    CMOS Tristate inverter with active high enable

  • 7/27/2019 1 Verilog Gate

    29/32

    CMOS Gate Primitive

    CMOS switch model cmos(out, in, nctl, pctl) ;

    Preferred over nmos or pmos switch. Why ?

    Examplemodule cmos_mux ( y, a, b, sel ) ;

    sel_n

    ECE301 VLSI System Desig n29

    input a, b, sel ;

    output y ;

    wire sel_n;

    not_mos (sel_n, sel) ;

    cmos C1 (y,a,sel_n, sel) ;

    cmos C2 (y,b,sel, sel_n) ;

    endmodule

    y

    b

    sel

    sel_n

  • 7/27/2019 1 Verilog Gate

    30/32

    Transmission Gate Primitive

    Transmission gate (Bi-directional) Buffer : tran ( inout, inout ) ;

    Tristate Buffer with active high enable :

    tranif1(inout,inout,ctl)

    Tristate Buffer with active low enable :

    ECE301 VLSI System Desig n30

    , ,

    module guess_me ( y, d, en ) ;input d, en ;output y ;wire y1, y2;

    not_mos N1 (y, y1) ;not_mos N2 (y2, y);tranif1 C1 (y1, d, en) ;tranif0 C2 (y1,y2, en) ;

    endmodule

    What logic function

    does this module perform ?

  • 7/27/2019 1 Verilog Gate

    31/32

    Misc Gate Primitive

    Pullup pullup(out)

    Net out is high if no drivers are active

    Else the net has the driven value

    Pulldown

    ECE301 VLSI System Desig n31

    pulldown(out)

    Net out is LOW if no drivers are active

    Else the net has the driven value

  • 7/27/2019 1 Verilog Gate

    32/32

    Assignment 3

    Design and Write a Verilog structural code usingtransistor primitives for :

    Design AND and OR gate using 1 tristate buffer and

    pullup/pulldown primitive

    Design a rising edge D FF using transmission gate

    ECE301 VLSI System Desig n32

    es gn a a ng e ge w async ronous ac ve ow

    reset using cmos gates

    Design a falling edge J-K Flip Flop with active high reset

    using the cmos D FF defined above

    Design a falling edge J-K Flip Flop with active high

    preset using the JK FF defined above