averilogtutorial

Upload: shashank-pandey

Post on 09-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 AVerilogTutorial

    1/42

    Verilog & ModelSim XE Tutorial

    Yeh-Juin Lin ()

    [email protected]

    4/23 2007

  • 8/7/2019 AVerilogTutorial

    2/42

    Verilog Tutorial

  • 8/7/2019 AVerilogTutorial

    3/42

    IC Design FlowRTL Model

    Logic Synthesis

    Gate Level Netlist

    Physical Design CellLibrary

  • 8/7/2019 AVerilogTutorial

    4/42

    Full Adder for Example

  • 8/7/2019 AVerilogTutorial

    5/42

    Gate Level Verilog Description

    // assign sum = a ^ b ^ ci;

    // assign net1 = a & b;

    // assign net2 = b & ci;

    // assign net3 = ci & a;

    // assign cout = net1 | net2 | net3;

  • 8/7/2019 AVerilogTutorial

    6/42

    Behavior Level Verilog Description

  • 8/7/2019 AVerilogTutorial

    7/42

    Integer & Real Numbers

  • 8/7/2019 AVerilogTutorial

    8/42

    Major Data Type Nets

    Registers

    Parameters

  • 8/7/2019 AVerilogTutorial

    9/42

    Nets Netdata type represent physical connections

    between structural entities.

    A netmust be driven by a driver, such as a gateor a continuous assignment.

    Verilog automatically propagates new valuesonto a net when the drivers change value.

  • 8/7/2019 AVerilogTutorial

    10/42

    Registers Registers represent abstract storage elements.

    A register holds its value until a new value isassigned to it.

    Registers are used extensively in behaviormodeling.

  • 8/7/2019 AVerilogTutorial

    11/42

    Common Mistake in Choosing Data Type An input port can be driven by a net or a register,

    but it can only drive a net.

  • 8/7/2019 AVerilogTutorial

    12/42

    Common Mistake in Choosing Data Type An output port can be driven by a net or a

    register, but it can only drive a net.

  • 8/7/2019 AVerilogTutorial

    13/42

    Parameters Parameters are not variables, they are constants.

    Typically parameters are used to specify delaysand width of variables.

  • 8/7/2019 AVerilogTutorial

    14/42

    Structure Modeling In structural modeling, you connect components

    with each other to create a more complex

    component.

  • 8/7/2019 AVerilogTutorial

    15/42

    Structure Modeling

    module HA(a,b,sum,co);

    input a, b;

    output sum, co;

    assign sum = a ^ b;

    assign co = a & b;

    endmodule

    module FA(A,B,CarryIn,Sum,CarryOut);

    input A, B, CarryIn;

    output Cum, CarryOut;

    wire sum0, sum1, co0

    HA ha0(A,B,sum0,co0);

    HA ha1(co0,CarryIn,sum1,CarryOut);

    assign Sum = sum0 ^ sum1;endmoduleHA.v FA.v

  • 8/7/2019 AVerilogTutorial

    16/42

    Delay Specification Delay specification defines the propagation

    delay of that primitive gate.

  • 8/7/2019 AVerilogTutorial

    17/42

    Continuous Assignments Any changes in the RHS of the continuous

    assignment are evaluated and the LHS is

    updates.

    RHS can be

    Expression

    assign and_out = i1 & i2; Value

    assign net_1 = 1;

    Other net

    assign net_a = net_b;

    Example

  • 8/7/2019 AVerilogTutorial

    18/42

    Operations

  • 8/7/2019 AVerilogTutorial

    19/42

    Shift Operator

  • 8/7/2019 AVerilogTutorial

    20/42

    Equality & Identity Operator

  • 8/7/2019 AVerilogTutorial

    21/42

    Conditional Operator

  • 8/7/2019 AVerilogTutorial

    22/42

    Concatenation & Replication Operator

  • 8/7/2019 AVerilogTutorial

    23/42

    Procedural Assignments Procedural assignments drives values onto

    register.

  • 8/7/2019 AVerilogTutorial

    24/42

    Procedural Assignments A continuous assignment statement cannont be

    inside procedural blocks.

    A procedural assignment statement must beinside procedural blocks.

  • 8/7/2019 AVerilogTutorial

    25/42

    Behavior Modeling At system level, systems functional view is more

    important than implementation.

    You do not have any idea about how to implementyour netlist.

    The data flow of this system is analyzed,

    You may need to explore different design options.

    Behavior modeling enables you to describe thesystem at a high-level of abstraction.

    All you need to do is to describe the behavior ofyour design.

  • 8/7/2019 AVerilogTutorial

    26/42

    Behavior Modeling

  • 8/7/2019 AVerilogTutorial

    27/42

    Behavior Modeling In behavior modeling, you must describe your circuits Action

    How do you model your circuits behaviors? Timing control

    At what time do what thing.

    At what condition do what thing.

    Verilog supports the following constructs to modelcircuits behavior

    Procedural block

    Procedural assignment

    Timing control

    Control statement

  • 8/7/2019 AVerilogTutorial

    28/42

    Procedural Blocks

    In Verilog, procedural blocks are the basic of behaviormodeling.

    You can describe one behavior in one procedural block Procedural blocks are of two types

    Initial procedural block Which execute only once

    Always procedural block Which execute in a loop

  • 8/7/2019 AVerilogTutorial

    29/42

    Procedural Blocks (Cont.)

    All procedural blocks are activated at simulation time 0 With enabling condition, the block will not ne execute until the enabling

    condition evaluates to TRUE

    Without enabling condition, the block will be executed immediately.

  • 8/7/2019 AVerilogTutorial

    30/42

    Procedural Blocks (Cont.)

  • 8/7/2019 AVerilogTutorial

    31/42

    Procedural Assignment

    Procedural assignments drive values or expressionsonto registers.

  • 8/7/2019 AVerilogTutorial

    32/42

    Non-blocking Procedural Assignment

    Blocking procedural assignment

    Non-blocking procedural assignment

    always@(posedge clock) begin

    x = a;y = x;z = y;

    end

    always@(posedge clock) beginx

  • 8/7/2019 AVerilogTutorial

    33/42

    Conditional Statements

    If and If-Else Statement

    Example

  • 8/7/2019 AVerilogTutorial

    34/42

    Conditional Statements

    Case Statement

  • 8/7/2019 AVerilogTutorial

    35/42

    ModelSim XE Tutorial

  • 8/7/2019 AVerilogTutorial

    36/42

    Install ModelSim XE Download the file

    http://www.xilinx.com/ise/mxe3/mxe_3_6.2c.zipand save it on your machine.

    Unzip the file.

    Click on the setup.exeprogram.

    Select MXE III Starter (Free)

    Select Full Verilog

    Setup license

  • 8/7/2019 AVerilogTutorial

    37/42

    Create a Project File New Project

    Add Existing File Browse

  • 8/7/2019 AVerilogTutorial

    38/42

    Compile All Files

    Compile All

  • 8/7/2019 AVerilogTutorial

    39/42

    Compile All Files

    No errors

  • 8/7/2019 AVerilogTutorial

    40/42

    Simulation

    1. Select your TestBench file2. Click the right button of mouse3. Simulate

  • 8/7/2019 AVerilogTutorial

    41/42

    Simulation

    Add signals to wave to see the waveform

  • 8/7/2019 AVerilogTutorial

    42/42

    Run

    1. Click Run All

    2. Check the waveform to debug3. Simulation result output