verilog module new

Upload: ardser

Post on 03-Jun-2018

229 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 Verilog Module New

    1/35

    Jim Duckworth, WPI Verilog Module1

    Verilog

    Verilog for Synthesis

  • 8/13/2019 Verilog Module New

    2/35

    Verilog background

    Jim Duckworth, WPI Verilog Module2

    1983: Gateway Design Automation released Verilog HDL

    Verilog and simulator

    1985: Verilog enhanced version Verilog-XL

    1987: Verilog-XL becoming more popular (same year

    VHDL released as IEEE standard)

    1989: Cadence bought Gateway

    1995: Verilog adopted by IEEE as standard 1364

    Verilog HDL, Verilog 1995

    2001: First major revision (cleanup and enhancements) Standard 1364-2001 (or Verilog 2001)

  • 8/13/2019 Verilog Module New

    3/35

    Books

    Jim Duckworth, WPI Verilog Module3

    Starters Guide to Verilog 2001 by Ciletti, 2004, PrenticeHall 0-13-141556-5

    Fundamentals of Digital Logic with Verilog Design by

    Brown and Vranesic, 2003, McGraw-Hill, 0-07-282878-7 Modeling, Synthesis, and Rapid Prototyping with the

    Verilog HDL, by Ciletti, 1999, Prentice-Hall, 0-13-

    977398-3 Advanced Digital Design with the Verilog HDL, byCiletti, 2003, Prentice-Hall, 0-13-089161-4

    HDL Chip Design by Smith, 1996, Doone Publications,0-9651934-8

    Verilog Digital Design by Arnold, 1999, Prentice Hall,0-13-639253-9

  • 8/13/2019 Verilog Module New

    4/35

    Create Verilog Module

    Jim Duckworth, WPI Verilog Module4

  • 8/13/2019 Verilog Module New

    5/35

    Module Created

    Jim Duckworth, WPI Verilog Module5

    No separate entity and arch

    just module

    Ports can be input, output, or

    inout Note: Verilog 2001 has

    alternative port style: (input a, b, sel, output y);

  • 8/13/2019 Verilog Module New

    6/35

    Add assign statement

    Jim Duckworth, WPI Verilog Module6

    Similar to VHDL conditional signal assignment continuous assignment

    Same hardware produced as with VHDL

  • 8/13/2019 Verilog Module New

    7/35

    Verilog - general comments

    Jim Duckworth, WPI Verilog Module7

    VHDL is like ADA and Pascal in style Strongly typed more robust than Verilog

    In Verilog it is easier to make mistakes

    Watch for signals of different widths No default required for case statement, etc

    Verilog is more like the c language

    Verilog IS case sensitive

    White space is OK

    Statements terminated with semicolon (;)

    Verilog statements between module and endmodule

    Comments // single line and /* and */

  • 8/13/2019 Verilog Module New

    8/35

    Verilog

    Jim Duckworth, WPI Verilog Module8

    Four-value logic system

    0 logic zero, or false condition

    1 logic 1, or true condition

    x, X unknown logic value

    z, Z - high-impedance state

    Number formats

    b, Bbinary

    d, D decimal (default)

    h, H hexadecimal

    o, O octal 16H789A 16-bit number in hex format

    1b0 1-bit

  • 8/13/2019 Verilog Module New

    9/35

    Verilog types

    Jim Duckworth, WPI Verilog Module9

    Constants parameter DIME = 10;

    parameter width = 32, nickel = 5;

    parameter quarter = 8b0010_0101;

    Nets wire clock, reset_n;

    wire[7:0] a_bus;

    Registers reg clock, reset_n;

    reg[7:0] a_bus;

    Integer only for use as general purpose variables in loops integer n;

  • 8/13/2019 Verilog Module New

    10/35

    Operators

    Jim Duckworth, WPI Verilog Module10

    Bitwise ~ negat i on Ver i l og VHDL

    & and y = a & b; y = a AND b;

    | i ncl usi ve or y = a | b; y = A OR b;

    ^ excl usi ve or y = a b; y = a XOR b;

    y = ~( a & b) ; y = A NAND b;

    y = ~ a; y = NOT a;

    Reduction (no direct equivalent in VHDL) Accept single bus and return single bit result

    & and y = & a_bus;

    ~& nand

    | or y = | a_bus; ^ excl usi ve or

  • 8/13/2019 Verilog Module New

    11/35

    Operators (contd)

    Jim Duckworth, WPI Verilog Module11

    Relational (return 1 for true, 0 for false) < l ess t han, gr eat er t han >=

    Equality == l ogi cal equal i t y

    != l ogi cal i nequal i t y

    Logical Comparison Operators ! l ogi cal negat i on

    && l ogi cal and

    || l ogi cal or

    Arithemetic Operators + -

    *

  • 8/13/2019 Verilog Module New

    12/35

    Operators (contd)

    Jim Duckworth, WPI Verilog Module12

    Shift >> ar i t hmet i c)

    Conditional Only in Verilog - selects one of pair expressions ? :

    Logical expression before ? is evaluated

    If true, the expression before : is assigned to output

    If false, expression after : is assigned to output

    Y = (A > B) ? 1 : 0

    Y = (A == B) ? A + B : A B

  • 8/13/2019 Verilog Module New

    13/35

    Tri-state example

    Jim Duckworth, WPI Verilog Module13

    Using conditional operator in continuous assignment

  • 8/13/2019 Verilog Module New

    14/35

    Concurrent statements

    Jim Duckworth, WPI Verilog Module14

    VHDL

    Process

    Signal assignments

    Verilog

    always statement

    Continuous assignment - assign

  • 8/13/2019 Verilog Module New

    15/35

    Sequential Statements

    Jim Duckworth, WPI Verilog Module15

    VHDL

    reside in process statement

    Verilog

    reside in an always statement

    ifstatements

    case statements

    Note: usebegin and endto block sequential statements

  • 8/13/2019 Verilog Module New

    16/35

    Verilog wire and register data objects

    Jim Duckworth, WPI Verilog Module16

    Wire net, connects two signals together

    wire clk, en;

    wire [15:0] a_bus;

    Reg register, holds its value from one proceduralassignment statement to the next

    Does not imply a physical register depends on use

    reg [7:0] b_bus;

  • 8/13/2019 Verilog Module New

    17/35

    Index and Slice

    Jim Duckworth, WPI Verilog Module17

    VHDL

    Use to and downto to specify slice

    Concatenation & c_bus(3 downto 0)

  • 8/13/2019 Verilog Module New

    18/35

  • 8/13/2019 Verilog Module New

    19/35

    Decoder

    Jim Duckworth, WPI Verilog Module19

    2 to 4 decoder with enable

    Combinational logic using always statement with sensitivity list

    similar to VHDLprocess for cyclic behavior

    (@) event control operator begin .. endblock statement

    note reg for y

  • 8/13/2019 Verilog Module New

    20/35

    Decoder (contd)

    Jim Duckworth, WPI Verilog Module20

    Combinational logic using always statement with

    sensitivity list

    similar to VHDLprocess for cyclic behavior

    (@) event control operator

    begin .. endblock statement

    Statements execute sequentially

    ifstatement case statement

    Note: case expression can concatenate signals ({,})

    Sensitivity list

    (a orb orc)

    Verilog 2001 allows comma-separated list (a, b, c)

  • 8/13/2019 Verilog Module New

    21/35

    Flip-flops in Verilog

    Jim Duckworth, WPI Verilog Module21

    Always inferred using edge-triggered always statement

  • 8/13/2019 Verilog Module New

    22/35

    Flip-flops in Verilog (with async)

    Jim Duckworth, WPI Verilog Module22

    Add async signals to sensitivity list

  • 8/13/2019 Verilog Module New

    23/35

    Counters in Verilog

    Jim Duckworth, WPI Verilog Module23

    Just extension of D type

    This example has async clear

  • 8/13/2019 Verilog Module New

    24/35

    Counters in Verilog (contd)

    Jim Duckworth, WPI Verilog Module24

    With terminal count

  • 8/13/2019 Verilog Module New

    25/35

    State Machine

    Jim Duckworth, WPI Verilog Module25

    SM1 4 states

    Two always statements

  • 8/13/2019 Verilog Module New

    26/35

    State Machine hardware

    Jim Duckworth, WPI Verilog Module26

    four flip-flops (can be changed through synthesis options)

    Combinational logic for next state and outputs

  • 8/13/2019 Verilog Module New

    27/35

    Blocking and non-blocking assignment

    Jim Duckworth, WPI Verilog Module27

    To ensure correct synthesis and simulation results:

    Combinational logic

    Use blocking assignment = statements in alwaysblock

    Sequential logic

    Use non blocking assignment

  • 8/13/2019 Verilog Module New

    28/35

    Top-Down Design Hierarchy

    Jim Duckworth, WPI Verilog Module28

    Instantiate module (counter example with decoder)modul e decoder ( count , seven_seg) ;

    i nput [ 3: 0] count ;

    out put [ 6: 0] seven_seg;

    / / i nst ant i at e decoder modul e i n count er

    / / usi ng posi t i on of por t s

    decoder d1 ( count _val , seven_seg_val ) ;

    / / or usi ng f or mal and act ual names

    decoder d1 ( . count ( count _val ) , . seven_seg( seven_seg_val ) ) ;

    d i l l

  • 8/13/2019 Verilog Module New

    29/35

    Decoder Tutorial Example

    Jim Duckworth, WPI Verilog Module29

    C T Fi f W f

  • 8/13/2019 Verilog Module New

    30/35

    Create Test Fixture from Waveform

    Jim Duckworth, WPI Verilog Module30

    T Fi f W f

  • 8/13/2019 Verilog Module New

    31/35

    Test Fixture from Waveform

    Jim Duckworth, WPI Verilog Module31

    T t Fi t f W f ( ti d)

  • 8/13/2019 Verilog Module New

    32/35

    Test Fixture from Waveform (continued)

    Jim Duckworth, WPI Verilog Module32

    Si l ti R lt

  • 8/13/2019 Verilog Module New

    33/35

    Simulation Results

    Jim Duckworth, WPI Verilog Module33

    Si l ti N t

  • 8/13/2019 Verilog Module New

    34/35

    Simulation Notes

    Jim Duckworth, WPI Verilog Module34

    Initialblock declares a single-pass behavior Executes once when simulator is activated

    Delay control operator (#) and delay value - #10

    Timescale compiler directive

    timescale /

    `timescale 10ns/1ns

    Inputs are declared as reg values retains value untilupdated

    Outputs are just monitored as wires

    Generating clocks

  • 8/13/2019 Verilog Module New

    35/35

    Generating clocks

    Jim Duckworth, WPI Verilog Module35

    Generating repetitive signalsi ni t i al begi n

    cl k = 0;

    endal ways begi n

    #5 cl k = ~cl k;

    end

    Oral ways begi n

    #5 cl k = 0;#5 cl k = 1;

    end