modelsim_intro2

Upload: kalscrib

Post on 09-Apr-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/8/2019 ModelSim_intro2

    1/6

    1

    Introduction to ModelSim VHDL Simulator

    Table of contents Page

    I. Basic Unix commands 1II. Getting Started Setting the Work Library 1III. ModelSim basics 1

    A. Creating a new project 2B. Creating and adding files into project 3C. Compiling project 3

    IV. Simulating with ModelSim 3A. Creating test files for the simulator 3B. Displaying the waveform and running the simulator 4

    V. The Waveform 5A. Changing the radix 5

    VI The Listing Form 6

    I. Basic Unix Commands

    These are some basic commands that will be used in this manual.mkdirdirname Creates the directory

    ls -options dirname Lists the contents of the directory

    options: l -long listing

    a -all files (including hidden)rm options file/dir Remove directory or files

    options: r -recursively remove directoriesf -force a yes answer to all the prompts

    cd dirname change into the directory

    nedit filename Edit the file in a text editor

    For further information of Unix commands, in the shell type: man command_name.

    II. Getting Started Setting the Work Library

    First, create a new directory for the vhdl project files: mkdir vhdl cd vhdl

    ModelSim requires a workdirectory where compiled data files will be stored andreferenced as a library. For organizational purposes, the work library can be set

  • 8/8/2019 ModelSim_intro2

    2/6

  • 8/8/2019 ModelSim_intro2

    3/6

    3

    File > New > Source > VHDL

    This will open up an empty text editor configured to highlight VHDL syntax. Afterwriting the code for the entity and its architecture, save the file with a .vhd extension (it

    is suggested to make the filename same with its entity name to avoid confusion). To addthis file into the project select from the top menu:

    Project > Add File to Project

    A new file icon should appear in the file frame box on the left.

    C. Compiling projects.Select the file from the project files list frame and right click on it. Select compile to just

    compile this file or compile all for all the files in the current project. If there are errors

    within the code or the project, a red failure message will be displayed. Otherwise, all iswell and no red warning or error messages are displayed.

    IV. Simulating with Modelsim

    To simulate, first the entity design has to be loaded into the simulator. Do this byselecting from the menu:

    Design > Load Design...

    A new window will appear listing all the entities (not filenames) that are in the worklibrary. Select the entity to be simulated and clickLoad.

    Often times it will be necessary to create entities withmultiple architectures, such as shown in the figure on the

    left. The decoder entity here has four differentarchitectures within it. In this case, the architecture has tobe specified for the simulation. Expand the tree for the

    entity, select the architecture to be simulated, and then clickLoad.

    A. Creating test files for the simulatorAfter the design is loaded, clear up any previous data and restart the timer by

    typing in the prompt:

    restartLeave the boxes unchecked to clear all, and clickRestart .

    Now, before simulating, the input signals or forces for the design under test mustfirst be initialized. To do this, first go to the prompt and open up a text editor (type nedit)

    and create the force data file using the following format:

    force force_name value1 time1, value2 time2, ... repeat duration

    The force is defined in value-time pairs, where the signal will changed to the value at thegiven time in nanoseconds. The repeat part is optional, and is commonly used to

    generate a clock. So, for example:force clk 0 0, 1 50 -repeat 100

  • 8/8/2019 ModelSim_intro2

    4/6

    4

    This creates a clock force with a 50% duty cycle and a period of 100ns (10Mhz clock).

    Also, the values have to be set according to the input type required by the entity. Forexample, if the input required a hexadecimal input, the value can be set as hexadecimal:

    force inA 16#0 0, 16#C 600, 16#8 1100

    The 16 denotes the radix for hexadecimal, and the # separates the base and the value.Other examples:

    10#9 - Decimal radix

    2#111 - Binary radix1234 - Character literal sequence (remember the quotes)

    When all the input forces have been initialized, save the file (any filename will do) andquit the text editor.

    Next, the forces data has to be loaded into the simulator by typing:

    do forces_filenameThis executes the force commands stored in the filename. The forces can also be entered

    at the prompt, instead of from a file, for quick changes in the time-value pairs.

    B. Displaying the waveform and running the simulation

    Select from the menu:View > Signals

    A new window will be displayed listing the design entitys signals and their initial value

    (shown below). Items in waveform and listing are ordered in the same order in whichthey are declared in the code. To display the waveform, select the signals for the

    waveform to display (hold CTRL and click to select multiple signals) and from the signallist window menu select: View > Wave > Selected signals

    The other options are: Signals in region

    which displays all the signals listed in thesignals window, and Signals in design

    displays all the signals and variables inthe project (which can be numerous whenthe design is dealing with other libraries).

    The waveform window is nowdisplayed, and the project can now be

    run. Run the program by typing in theModelSim prompt: run durationwhere duration is a numerical value

    denoting time in nanoseconds. The waveform window now displays the signal results of

    the run for the duration. Warning: Running a program for 1ns with code that has a

    process containing a wait for 0 ns and no other wait statements can be fatal to yourmachine, and require a reboot.

    Waveforms, however do not display the delta delays. This information can beobserved through the listing file by selecting from the signals list menu:

    View > list > signals in region

  • 8/8/2019 ModelSim_intro2

    5/6

    5

    V. The Waveform

    Signal names Signal value @ cursor cursor@time

    Be familiar with the top toolbar, they are very helpful in results analysis and debuggingthe code.

    A. Changing the radixThe signal values are displayed based on their type in the entity. However, for

    readability when debugging a design, it would be convenient to change the radix.

    Highlight the target signal, and right click on it to bring up the menu. Select radix >then the radix of choice (decimal, hexadecimal, etc.).

  • 8/8/2019 ModelSim_intro2

    6/6

    6

    VI. The Listing Form

    time delta delay values

    Listing form is used to see the events of the simulation or to see changes occurring to a

    value at what time. The left column is the time column time elapsed, along with thedelta delay. The right column is the value at the given time and delta delay.