Guide for ModelSim simulator
Open ModelSim program
Figure 1
ModelSim program
Specifying the simulation Directory
You need to tell the simulator where to find the lab directory containing your design files:
·
File -> Change Directory
·
Navigate to the directory containing your design files
·
Click open
The compilation of your design you can do either by creating the project and compiling the files of this project or just by compilation every file without creation the project.
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 in the library form. Note this is duplicated.
· Select OK
· Verify that the directory with name work has been created in your labs directory
Figure 2 Dialog box “Create a New Library”
Compiling your design
Now lets compile yours VHDL files in correct order. Compile mux.vhdl.
·
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.vhdl and then click compile
·
Check the main ModelSim window for the results of
compilation
Figure 3 Dialog box “Compile Source Files”
Creating a new project
·
File -> New -> Project
· Create Project dialog box appears (Figure 4)
· Type the name of the project in Project Name field
· Specify the directory in 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 default name.
After a new project creation new tab Project appears in the Workspace window. This window shows the list of files of this project.
Figure 4 Dialog box “Create project”
Adding a design file to the project
There are 2 options to add the file to the project: either to create a new design file or to add the existing one.
Adding existing file:
Figure 5 Dialog box “Add file to Project”
Adding new design file:
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:
Compiling together:
If your design contains errors, you will see the message [file name] failed with n error, with double click on this line the more concrete message of errors appears in 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.
Invoking the Simulator
To invoke the simulator:
·
Simulate -> Simulate
The following Simulate
·
In the design tab find the work library and find in it
the topmost design you wish to simulate, select it and click the OK
button
The “loading…” message will appear in the main window to
confirm that the files have loaded correctly. If you receive the error message
asking to re-compile the testbench design, then you have compiled the files in
the wrong order.
Organizing the Display
Usually windows Main, Structure, Wave, Source and Signals are used during simulation (Figure 7, Figure 9, Figure 8):
· Open all the windows with View -> All Windows
· Close or minimize not required windows
Another option is to open individual windows under View menu
Figure 7 Structure window
Figure 8 Signals window
Figure 9 Wave window
Viewing your design
Traversing the design hierarchy
The design’s hierarchy can be traversed and inspected with the Structure window. The same information is contained in the workspace window under tab sim.
Displaying signals and waveform window
For debugging purposes, you can view signals within your design. The waveform window displays the signals’ current value as well as any history.
You can activate the signals window by
To add the signals into the Wave window:
or
Controlling the simulation
Running the simulation
You can run the simulation for a set amount of time by typing run X in the Main window, where X is the number of nanoseconds that you wish to run for, for 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 a default run period:
·
Simulate -> Simulation 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 the view of waveforms by clicking with right mouse button and choosing appropriate option. Also you can see the waveforms on the whole screen:
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 the libraries. In this case, as you have just re-compiled your edited source code into the work library, the simulator will restart using your modified code.
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, quit the simulator:
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:
Create a logical name for the physical directory with vmap:
Compiling your design
To compile VHDL design files you vcom:
Invoking the simulator
Invoke the simulator with vsim on the topmost design unit:
Simulator User Unterface
Use view to open all or selected window of the simulator interface:
Add signals in the waveform window
Use add wave to add selected signals, or all the signals in a 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 the simulation
Restart keeping all the current display formats:
·
restart –f
Quitting the simulator
When you have finished simulating, quit the simulator:
·
quit -sim