55:132/22C:160,
Spring 2011
Using
the ModelSim Verilog
Environment
Note: For information on how to activate your Engineering CSS account
(assuming that you do not already have an active account) and how to access the
ModelSim Verilog tools, see
the Class News link of this web site.
Once you have your account activated, follow the instructions on this
page.
This page will give you a quick help to set up your CSS Linux environment to
work with the ModelSim Verilog
tools that are a part of the Mentor Graphics tool suite.
The tool used is named ModelSim6.5b_1 and it works with either VHDL
or Verilog codes.
Using Verilog will be very similar to classical
programming languages (such as C). You will perform the following steps:
- write your Verilog code using
any text editor (a usual convention gives the extension .v
to Verilog source files), for example my_test.v
- compile your my_test.v file
using the ModelSim compiler to check if the
syntax is correct (if not, some debugging messages will appear to help you
change your code and get it to compile properly)
- run the ModelSim
simulation tool which will allow you to exercise your compiled code and
look at its behavior, timing characteristics, etc.
Before
starting to write Verilog code you need to do a few
easy operations:
- Go to your home directory
$cd
- First, you have to source the Mentor setup file by
typing the line below at your prompt (assuming you are using the bash shell):
$. /usr/css/etc/mentor_setup.sh (Note: there is a space between the dot and
the slash)
. To avoid having to source this file every time you start a
session on your workstation, you can add the source command line in your .bashrc
file (which is in your home directory):
- open your .bashrc file with a text editor
- add the following two lines at the end of
the file (the first line is only comment):
- #source of setup file for Mentor Tools
. /usr/css/etc/mentor_setup.sh
Make sure you type the file's path correctly!
Once again, note that there is a space between the dot and the slash.
- Now, in the future, when you start a
session you will not need to type the source command
Important note: if you do not want to add this information to
your .bashrc file, you have to type the source
command every time you start a session!
- Next, you will create a directory that will contain all
your Verilog files, simulation results, etc.
(you do not have to create this directory, but it will organize your
work). Type:
$mkdir verilog_dir
- Then go to that directory by typing:
$cd verilog_dir
- Now we have to create the working library. This
step creates a sub-directory contained in the verilog_dir
directory:
$vlib work
You can now write Verilog modules using
a text editor. Once you have saved a Verilog file
(e.g. my_test.v) into your verilog_dir
directory, you should do the following steps, with verilog_dir
as your working directory:
- Compile your file by typing:
$vlog my_test.v
If the compilation is successful, you will
have a result that will look similar to this:
Model
Technology ModelSim SE vlog
6.5b_1 Compiler 2009.07 Jul 14, 2009
--
Compiling module your_module_name
...
Top
level modules: your_top_level_module_name(s)
If compilation failed, appropriate error messages will be displayed.
You will not be able to simulate a Verilog code that
has not been compiled successfully. Also remember that even if you know you
have a syntactically correct code, you must compile it before running
it.
- If your my_test.v
file was compiled successfully you can simulate it by typing:
$vsim top_level_module_name
- Note: When running a simulation, you must
specify the top-level module name, not the file name.
This will run the ModelSim
simulator and a window will pop up.
- You can now open additional windows that
you wish to view by choosing an option under the "View"pull-down menu
in the "ModelSim SE PLUS 6.1b"window, for
instance "View" -> "Signals..."and "View"
-> "Waves...". for now you will
not need any additional windows, but you may want to play around with the
options to familiarize yourself with the capabilities and features of ModelSim.
- You are now ready to Run
the program. You can use the "run" menu items or run icons in
the ModelSim window to run the simulation for
specified numbers of time steps. Output from display and monitor
statements will be displayed in the ModelSim
window.
- Note: If you are working from a text-only
shell (e.g. a SSH connection) you can run vsim
in a non-graphical mode by specifying the -c flag:
$vsim -c top_level_module_name
In this case, you will get a command prompt of the
form
VSIM>
You can run the simulation for a specified number of time
steps by typing the run command at this prompt. For instance to run for 100
time steps, type:
VSIM> run 100
- You can run the simulation until it
terminates by using the -all option; this is also useful to obtain
the file transcript for the complete execution:
VSIM> run
-all
- Use CTRL-D to leave the command-line
mode of ModelSim
· You now have the
basics needed to write, compile and run/simulate a Verilog
application. . You are encouraged to try the tool yourself since it is probably
the most efficient way for you to get familiar to it.
- FOR MORE INFORMATION ABOUT MODELSIM, look at
the "help" window
Last Update: Feb 17, 2010 JGK