Você está na página 1de 6

Introduction to ModelSim VHDL Simulator

Table of contents Page


I. Basic Unix commands 1
II. Getting Started – Setting the Work Library 1
III. ModelSim basics 1
A. Creating a new project 2
B. Creating and adding files into project 3
C. Compiling project 3
IV. Simulating with ModelSim 3
A. Creating test files for the simulator 3
B. Displaying the waveform and running the simulator 4
V. The Waveform 5
A. 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.
mkdir dirname 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 directories
f -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 work directory where compiled data files will be stored and
referenced as a library. For organizational purposes, the work library can be set

1
separately and placed for different directories. This is done when creating new projects
discussed in the next section.

[optional - A central directory can be set as the work directory]:


Once inside the vhdl directory, create a work directory:
• vlib work
In addition to the work directory, it will also create an _info file about the library.
Now, begin the ModelSim simulator by typing:
• vsim &
(The ‘&’ tells Unix to run the process in the background leaving the terminal reusable)

III. ModelSim Basics

On the left side of the interface, under the project tab is the frame listing of the
files that pertain to the opened project. The Library frame lists the entities of the project
(that have been compiled). To the right is the ModelSim shell frame. It is an extension
of the Unix shell, so both ModelSim and Unix commands can be executed.

A. Creating a new project.


From the menu choose:
File > New > Project.
A window will pop up with three fields. First enter the project name. The project
location and the default project name can be left as it is, since the work library has been
initialized, or it can be set to another directory. For now leave the setting as is and click
“OK” to create the project.

B. Creating and adding new files to the project.


From the menu choose:

2
File > New > Source > VHDL
This will open up an empty text editor configured to highlight VHDL syntax. After
writing 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 add
this 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 is
well 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 by
selecting from the menu:
Design > Load Design...
A new window will appear listing all the entities (not filenames) that are in the work
library. Select the entity to be simulated and click Load.
Often times it will be necessary to create entities with
multiple architectures, such as shown in the figure on the
left. The decoder entity here has four different
architectures within it. In this case, the architecture has to
be specified for the simulation. Expand the tree for the
entity, select the architecture to be simulated, and then click
Load.

A. Creating test files for the simulator


After the design is loaded, clear up any previous data and restart the timer by
typing in the prompt:
• restart
Leave the boxes unchecked to clear all, and click Restart.
Now, before simulating, the input signals or forces for the design under test must
first 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 the
given 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

3
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. For
example, 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 radix
“1234” - Character literal sequence (remember the quotes)
When all the input forces have been initialized, save the file (any filename will do) and
quit the text editor.
Next, the forces data has to be loaded into the simulator by typing:
• do forces_filename
This 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 entity’s signals and their initial value
(shown below). Items in waveform and listing are ordered in the same order in which
they 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 signal
list window menu select:
View > Wave > Selected signals
The other options are: “Signals in region”
which displays all the signals listed in the
signals window, and “Signals in design”
displays all the signals and variables in
the project (which can be numerous when
the design is dealing with other libraries).
The waveform window is now
displayed, and the project can now be
run. Run the program by typing in the
ModelSim prompt:
• run duration
where 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 your
machine, and require a reboot.
Waveforms, however do not display the delta delays. This information can be
observed through the listing file by selecting from the signals list menu:
View > list > signals in region

4
V. The Waveform

Signal names Signal value @ cursor cursor@time

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

A. Changing the radix


The 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.).

5
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 the
delta delay. The right column is the value at the given time and delta delay.

Você também pode gostar