xilinx tutorial for testbench

Upload: vinit-patel

Post on 08-Aug-2018

240 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/22/2019 Xilinx Tutorial for Testbench

    1/11

    IIITB

    2012

    XILINX SHORT TUTORIAL

    Pooja MG

  • 8/22/2019 Xilinx Tutorial for Testbench

    2/11

    2 | P a g e

    Let's learn making simple verilog simulation.

    Let's design a simple logic gates :

    Steps:

    1. Create a new project.File -> NewProject.

    New Project Wizard opens as below

    2. Enter the name of the project (say logic_gate) and choose Top-level source for the project as 'HDL', as shown in above fig .Next you will be asked to make project settings as below. Don't bother much about it as of now, just check the simulator

    and preferred language as shown below.

  • 8/22/2019 Xilinx Tutorial for Testbench

    3/11

    3 | P a g e

    3. After clicking next you'll see the project summary, like below.

    4. Click finish, your project is created successfully.5. Next, create a new source file (verilog).

    For this, right click on the device, as below figure, and follow the screen shots.

  • 8/22/2019 Xilinx Tutorial for Testbench

    4/11

    4 | P a g e

    6. Choose Verilog Module and enter filename, and check add to project box

    7. Now define the inputs and outputs to the logic gates.See the below and enter the same.

  • 8/22/2019 Xilinx Tutorial for Testbench

    5/11

    5 | P a g e

    8. Press next and this generates Summary of the file, check the generated port definitions.

    9. Press Finish to generate the verilog module.Complete the verilog code for logic_gates.v as below :

    module logic_gate

    (input a, input b,output out_not, output out_and, output out_or);

    assign out_not = ~a;

    assign out_and = a&b;assign out_or = a|b;

    endmodule

  • 8/22/2019 Xilinx Tutorial for Testbench

    6/11

    6 | P a g e

    10.Next save and synthesize the verilog code, by selecting the .v file in Hierarchy, and clicking on Synthesis in Design box asabove figure.

    Now you are done with your verilog code, Now to make test bench for verilog code follow the below procedure :

    1. Right click on the device, to open New source Wizard, now choose Verilog Test Fixture, as below,Enter the name of testbench (say logic_gates_testbench) and check the add to project box.

    2. Now click next and Associate your testbench file to the logic_gate project as below.

  • 8/22/2019 Xilinx Tutorial for Testbench

    7/11

    7 | P a g e

    3. click next and view the summary as below.

    4. Finish to create the testbench file.Now in the template, edit verilog code to look like below .v code :

    logic_gates_testbench.v

  • 8/22/2019 Xilinx Tutorial for Testbench

    8/11

    8 | P a g e

    module logic_test;

    // Inputs

    reg a;

    reg b;

    // Outputs

    wire out_not;

    wire out_and;

    wire out_or;

    wire out_nand;

    wire out_nor;

    wire out_xor;

    wire out_xnor;

    // Instantiate the Unit Under Test (UUT)

    logic_gate uut (

    .a(a),

    .b(b),

    .out_not(out_not),

    .out_and(out_and),

    .out_or(out_or),

    .out_nand(out_nand),

    .out_nor(out_nor),

    .out_xor(out_xor),

    .out_xnor(out_xnor)

    );

    initial begin

    // Initialize Inputs

    #100

    a = 1'b0;

    b = 1'b0;

    // Wait 100 ns for global reset to finish

    #100;// Add stimulus here

    b = 1'b1;

    #100;

    a = 1'b1;

    b = 1'b0;

    #100;

    b = 1'b1;

    end

    endmodule

  • 8/22/2019 Xilinx Tutorial for Testbench

    9/11

    9 | P a g e

    5. Save the code and enter to simulation mode as below.6. now select your verilog code7. And run the Isim simulator as below. ( first run Behavioural Check syntax , on success simulate Behavioural Model).

  • 8/22/2019 Xilinx Tutorial for Testbench

    10/11

    10 | P a g e

    8. on success Isim opens as below, with the required output,

    9. Zoom in/out and set the time scale to 100ns to view better and click run as below.

  • 8/22/2019 Xilinx Tutorial for Testbench

    11/11

    11 | P a g e

    That's it