Do an Ngon Ngu Mo Ta Phan Cung

Embed Size (px)

Citation preview

  • Verilog HDL Simulation Labs

    Overview

    The Verilog simulation labs in this course are designed to maximize your hands-on introduction to Verilog coding. Therefore, you are asked to create all hardware modules and testbenches from scratch. After finishing these labs, you will gain the level of coding skill, syntax proficiency, and understanding that can only be achieved through meaningful practice and effort. Most of the early lab exercises are standalone tasks that reinforce and illustrate language concepts that are fundamental to all Verilog coding.

    Objectives

    After completing these labs, you will be able to: Write RTL descriptions for simple circuits Create a structural Verilog description for simple circuits Build hierarchy by using Verilog Create a Verilog testbench to verify the hierarchical structure created in the

    previous steps Use the simulation software Create basic input stimulus Run a simulation

    Labs Outline

    Lab 1: Building Hierarchy Lab 2: Simulation/Verification Lab 3: Memory Lab 4: n-bit Binary Counter Lab 5: Comparator Lab 6: Arithmetic Logic Unit (ALU)

  • 3

    Lab 1: Building Hierarchy

    In this lab, you will write a complete RTL description for the modules MY_AND2 and MY_OR2 and build the circuit shown below (Figure 1) in a structural Verilog description of the top-level module AND_OR.

    Figure 1

    This lab comprises three primary steps: You will create a software project; write RTL descriptions; and check the syntax of your RTL code.

    Lab 2: Simulation/Verification

    In this lab, you will write a Verilog testbench for the AND_OR module completed in the previous exercise. As part of the testbench, you will create a simple input stimulus by using both concurrent and sequential statements. Examine the circuit below (Figure 2). In this lab, you will write a complete Verilog testbench description for the module AND_OR.

    Figure 2

    OUT1

    INP[2]

    INP[0] INP[1]

    INP[3]

    Top level: AND_OR MY_AND2

    U0

    MY_AND2

    U1

    MY_OR2

    U2

    SIG1

    SIG2

  • 4

    This lab comprises four primary steps: You will create a new project and import Verilog source files; create a testbench with the Verilog testbench wizard in the simulation software; create initial and always input stimulus statements; and, finally, verify the logic structure and functionality by running a simulation and examining the resulting waveforms.

    Lab 3: Memory (ROM)

    In this lab, you will write a complete RTL description for a ROM module by using a one-dimensional array and a Verilog reg data type and a case statement.

    The memory was modeled as a ROM, which is a constant; therefore, you were required to assign values at the time of declaration. This lab comprises three primary steps: You will create a one dimensional memory array using case statement; create a testbench with the Verilog testbench wizard in the simulation software; finally, verify the logic structure and functionality by running a simulation and examining the resulting waveforms.

    Lab 4: n-bit Binary Counter

    In this lab, you will write a complete RTL description for the module CNTR by using parameter statements to specify the bit width. This is an n-bit binary, up/down, loadable counter, with active-Low asynchronous reset. You will then build a Verilog HDL testbench to verify the functionality of the RTL code as well as the hardware it models.

  • 5

    Examine the circuit below (Figure 3). In this exercise, you will create a fully functional binary counter that can be dynamically scaled to any length. The use of parameter statements is an important tool for module reuse and source code readability. The circuit is an n-bit binary, up/down loadable counter, with active-Low asynchronous reset.

    Figure 3

    This lab comprises three primary steps: You will create a software project; declare the parameter statements; and, finally, create a testbench to verify the design.

    Create the input stimulus:

    1. Set the CLOCK input to toggle at a rate of 100 MHz

    2. Assert the RESET input at time 15 ns, hold for 25 ns, then de-assert

    3. Set the CE input initially High, de-assert (set Low) at time 300, hold for 100 ns, reassert

    4. Set the LOAD input initially Low, toggle High at time 500 ns, for one full clock cycle

    5. Set UPDN to initially High, then Low at time 750 ns

    7. Set the D_IN input value to 8h0F or 8b00001111

    D_IN Q_OUT

    RST

    CE LOAD UpDn CLK

    CNTR

  • 6

    Lab 5: Comparator In this lab, you will write description for the module COMP (Synchronous Comparator) using an if/else statement.

    Examine the circuit below (Figure 4):

    Figure 4

    This lab comprises four primary steps: You will create a software project; create an RTL version of COMP; and, finally, create a testbench to verify that the behavioral model functions correctly.

    If the expected result and the data are equal, the result is TRUE; otherwise, the result is FALSE.

    Declarations of input and output are shown in the following table:

    Port Label Length Description enable 1bit Input; enable the comparator expected 4 bit Input; expected output data 4 bit Input; actual output; result 1 bit Output; result of comparison clk 1 bit Clock input

  • 7

    Lab 6: Arithmetic Logic Unit (ALU) In this lab, you will write a complete RTL description for the module ALU. The op-codes and functionality of the synchronous ALU is described below.

    Inputs Outputs A_IN (4 bit ) OUTPUT (4 bit) B_IN (4 bit ) OPCODE (4 bit ) CLK ENABLE

    Use a case statement to describe the functionality for the ALU as shown in the following table, which shows the SELECTION OPCODE and the operation/function for each. Do not forget the ENABLE input.

    OPCODE S3 S2 S1 S0 Operation Function

    0 0 0 0 Y = A Transfer 0 0 0 1 Y = A + 1 Increment 0 0 1 0 Y = A + B Addition 0 0 1 1 Y = A + B + 1 Addition and Increment 0 1 0 0 Y = A + (~B ) Add + 1s comp 0 1 0 1 Y = A + (~ B ) + 1 Subtraction 0 1 1 0 Y = A 1 Decrement

    0 1 1 1 Y = A and B AND 1 0 0 0 Y = A or B OR 1 0 0 1 Y = A xor B XOR 1 0 1 0 Y = ~ A Compliment 1 0 1 1 Y = 0 Transfer 0s

    Table: SELECTION OPCODE