Last modified: 2020-06-04 14:15:06

Before we start

In the lab class we need to luckyladyschoose the configuration for the environment jack and the beanstalk slot machine which allows
us to use ModelSim. The command for the environment choices is cad. The command must
be entered twice.
To select ModelSim choose option 2 (Mentor Graphics 2018 EDA version).

Another important note to remember is that ModelSim
doesn’t support CTRL+s shortcut.

Starting ModelSim

To start the program you must insert command

vsim &

The & in the end of the command shows that the program is run in the backround and the
promt is returned immediately. It means that to run another process you don’t have
to open a new command line window. You can use & behind every process command.

ModelSim

Figure 1. ModelSim main view.

Specifying the simulation directory

You need to tell the simulator where to find the lab directory containing your design files. For that:

  • File->Change Directory
  • Navigate to the directory containing your design files
  • Ok

Compiling the design

To compile your design you can either create a new project and compile the files
in the project or just compile every file without creating a project. Somewhat
easier is to create a new project. This gives you the chance to open the project
later without any need to specify the files in there or the library used.

Option1: Compilation without project creation

Creating a compilation library

A compilation library is a directory on your disk into which all HDL designs are compiled.
You can specify this library through the ModelSim or it can be created using operation system
commands. Usual library name is work. Now lets create a directory called work
and map the directory to the logical library named work.

  • File->New->Library
  • Select Create a new library and a logical mapping to it (Figure 2).
  • Type work into the library form. Note that it’s duplicated.
  • Select Ok.
  • Verify that the directory with the name work has been created in your lab directory.

ModelSim

Figure 2. Creating a new library.

Compiling your design

Now lets compile the design. For example we’ll take the lab1 mux.vhd VHDL file.

  • Compile->Compile…
  • The following dialog box appears (Figure 3).
  • Make sure that Library is set to work.
  • Select the design file you want to compile, for example mux.vhd and then click Compile.
  • Check the main ModelSim window for the results of compilation.

ModelSim

Figure 3. Compiling source files.

Option2: Compiling with project creation

Creating a new project:

  • File->New->Project
  • Create Project dialog box appers (Figure 4).
  • Type the name of the project in the Project Name field.
  • Specify the directory on your disk, where the project would be located in the
    Project Location field.
  • Specify the compilation library name. A compilation library is a directory on your disk
    into which all HDL designs are compiled. The default library name is work. It is better to
    leave it with a default name.

After a new project creation a new tab Project appears in the Workspace window.
This shows the list of the files of the current project.

ModelSim

Figure 4. Creating a project.

Adding an existing design file to the project

  • File->Add to Project->Existing File…
  • Browse the file, for example mux.vhd. (Figure 5).
  • You can either reference from current location or copy to project directory
    choosing appropriate radio button.
  • Select Ok. The chosen file will appear in the Workspace window with the question mark in the column of status,
    this means thtat the file is not yet compiled.

ModelSim

Figure 5. Adding files to project.

Adding a new design file to the project

  • File->Add to Project->New File…
  • Specify the name of the file in File Name field.
  • Select VHDL in the Add file as type.
  • Select Ok. A new file will appear in the Workspace window with the question mark in
    the column of the status,
    this means that the file is not yet compiled.

With double click on the design file in Workspace window you open the content of this file in the Source Code Editor.

Compiling your design

You can compile either all files together or every file separately.

Compiling separately:

  • Select design file you wish to compile from the list of the project files in Workspace window.
  • Compile->Compile Selected

Compiling together:

  • Compile->Compile All (remember that files should be in the proper order in the list)
  • Compile->Compile Order (order your design files according to dependencies)

If your design contains errors, you’ll see the message [file name] failed with n error(s).
With double click on this line the exact message of errors appears in the following format:

# ERROR: file_name(line_number): description…

With double click on the error message ModelSim will open the source file in its Source Code Editor at the error line.

Simulation

Starting the simulator

To invoke the simulator:

  • Simulator->Start Simulation
  • In the design tab find work library.
  • In the work library find the topmost design’s testbench you wish to simulate.
  • Be aware to uncheck the Enable optimization box.
  • Select it and click Ok.

Another way is according to Figure 6.

ModelSim

Figure 6. Simulation starting.

The “loading…” message will appear in the main window to confirm that the files
have loaded correctly. If you receive an error message asking to re-compile the testbench design, then you
have compiled the files in the wrong order.

Organizing the display

Usually windows Workspace, Objects and Wave are used during simulation (Figure 7).

  • Open Objects Window by View->Debug Windows->Objects
  • Open Wave Window by View->Debug Windows->Wave

You can also open other individual windows under View menu.

ModelSim

Figure 7. Simulation view.

Viewing your design

Travesing the design hierarchy

The design’s hierarchy can be traversed in the workspace window under tab sim.

Displaying signals and waveform window

For debugging purposes you can view signals within your design in the objects window. The waveform window displays the signals’ current value as well as any history.

To add the signals into the Wave window:

  • Add->To Wave->Signals in Regionor
  • Select signals in Object window. Then drag and drop selected signals to the Wave window.

Controlling the simulation

Running simulation

You can run the simulation for a set amount of time by typing run X in the command
line of Main window, where X is the number of nanoseconds that you wish to run for.
In example run for 100 ns:VSIM > run 100 ns

Command run without specifying the time will execute simulation for the
default amount of time. You can set the default run period:

  • Simulate->Runtime Options…
  • Enter amount of time into the Default Run box.
  • Select Ok.
  • Simulate->Run->Run “default time” ns.

Using the waveform display

Observe the behaviour of the design in the waveform display. You can zoom in and zoom out of
the view of waveforms by clicking right mouse button and choosing the appropriate option. Also you can see the waveforms on the whole screen:

  • Do a right click and choose Zoom Full.
  • Highlight a signal, do a right click and choose Radix to change the display format.

Restart the Simulation

The simulation can be restarted to time 0 using the restart command. When this happens,
the simulator reloads any re-compiled design files in the libraries. In this case,
as you have just re-compiled your edited source code into the work library, the simulator
will restart using the modified code.

  • Click in the main window to make it active.
  • Simulate->Run->Restart
  • Leave all of the options in set and click on the Restart button.

The simulation time will be set back to zero. Note that the signals are still listed in the waveform display, but the
previous waveforms are no longer displayed.

Quitting the simulator

When you have finished simulating:

  • Simulate->End Simulation

Command line operation

The command line can be used as an alternative to the pull-down menus of the
Graphical User Interface for scripting and batch-mode operation. Only simple
command syntax is shown here. The Command Reference guide in the docs directory of the ModelSim
installation contains full details.

Commands

Creating a compilation library

Create a physical compilation directory with vlib:

  • vlib ./workCreate a logical name for the physical directory with vmap:
  • vmap work ./work

Compiling your design

To compile VHDL design files you vcom:

  • vcom mux.vhd

Starting the simulator

Start the simulator with vsim on the topmost design unit:

  • vsim work.T_mux

Simulator User Interface

Use view to open all or selected window of the simulator interface:

  • view *
  • view wave

Add signals in the waveform window

Use add wave to add selected signals, or all the signals in the selected region
to the waveform viewer.

  • add wave /t_mux/uut/*

Running the simulation

The simulation is started by typing run X in the main window, where X is the
number of nanoseconds that you wish to run for:

  • run 100 ns

Restart simulation

Restart keeping all the current display formats:

  • restart -f

Quitting the simulator

When you have finished simulating quit the simulator:

  • quit -sim