Tutorial 6: Simulation

This material is by Steven Levitan and Akshay Odugoudarfor the environment at the University of Pittsburgh, 2008/2009.

We are using Mentor Graphics ModelSim SE-64 6.4

Coding the design

You can code up your design in Verilog or vhdl. For Verilog the file should end with an extension of  “.v” and for vhdl it should end with  “.vhd” For this example we will use the traffic light controller, traffic_light.vhd from the previous tutorial.

Copy this file to a new directory, and then cd to this new diretory

Setting up the environment

The Mentor Graphics Modelsim environment should be setup by sourcing the script  $CLASS/setupfiles/setup_all

Start Modelsim

> vsim

The modelsim window should come up and look like

Libraries and Projects

Modelsim uses the concept of projects to keep your design files. So, you need to define a project and a library to keep your project files.

Click on File à New à Project

The new project window should popup

Fill in a name for your project (traffic_light_project) note the location and default library name are set up for you.

Click OK

Since this is a new project, it will ask you to put some files in it.

Click on “Add existing File” then browse to your file. Leave the default “reference existing file” rather than copying it.

You can type in the file name or, use the browser, as shown

Click OK

The modelsim window should look like this now

Compiling

Click on your file in the workspace window and then Compile à Compile Selected

 

 

 

You can see the green check mark in the workspace window and the good message in the transcript window.

 

Simulating

Click simulate à start simulation

The Start Simulation window will pop up.  Click on the work library, then click on your design (traffic_light)  then click OK

 

Basic Simulation Commands

The simulator will now start. The available commands at the top of the window change, and you can see the simulation log file in the transcript window

 

 

 

The basic commands can be typed into the transcript window with the following explanations:

 

                 Instruction

Description

add wave *

It adds all the signals and variables to the wave window.

force

This command allows you to apply stimulus interactively to the VHDL signals.

run

The run command advances the simulation by the specified number of timesteps.

alias

The alias command displays or creates user-defined aliases

change

The change command modifies the value of a constant, generic or a variable.

delete

The delete command removes object from either list of wave window.

do

The do command executes commands contained in a macro file or the do file as it is commonly known to us.

exit

The exit command exits the simulator and the ModelSim application.

help

The help command displays in the Transcript pane a brief description and syntax for the

specified command.

noforce

The noforce command removes the effect of any active force commands on the selected objects.

restart

The restart command reloads the design elements and resets the simulation time to zero.

pause

The pause command placed within a macro interrupts the execution of that macro,  allowing you to perform interactive debugging of the macro file.

quit

The quit command exits the simulator.

vcom

The vcom command compiles the source code into a specified working library

vsim

The vsim command is used to invoke the VSIM simulator, to view the results of a previous simulation run.

write report

The write report command prints a summary of the design being simulated including a list of all design units with the names of their source files

           

As you start to type, help is provided in the transcript window with the required arguments and options for each command

“*” wild carding for signal names is allowed.

 

After add wave *

 

 

 

The basic commands and their description:

 

                 Instruction

Description

add wave *

It adds all the signals and variables to the wave window.

force

This command allows you to apply stimulus interactively to the VHDL signals.

run

The run command advances the simulation by the specified number of timesteps.

alias

The alias command displays or creates user-defined aliases

change

The change command modifies the value of a constant, generic or a variable.

delete

The delete command removes object from either list of wave window.

do

The do command executes commands contained in a macro file or the do file as it is commonly known to us.

exit

The exit command exits the simulator and the ModelSim application.

help

The help command displays in the Transcript pane a brief description and syntax for the

specified command.

noforce

The noforce command removes the effect of any active force commands on the selected objects.

restart

The restart command reloads the design elements and resets the simulation time to zero.

pause

The pause command placed within a macro interrupts the execution of that macro,  allowing you to perform interactive debugging of the macro file.

quit

The quit command exits the simulator.

vcom

The vcom command compiles the source code into a specified working library

vsim

The vsim command is used to invoke the VSIM simulator, to view the results of a previous simulation run.

write report

The write report command prints a summary of the design being simulated including a list of all design units with the names of their source files

           

 

To covert some signal into a clock right click on the signal name in the waveform

Then click Clock in the popup

 

You should be able to feed the clock parameters in the pop up.

 

 

One can also use the force command for a clock in the transcript window. You can see the command there as you set up the popup.

 

force –freeze sim:/<entityname>/clock_name 1 0, 0{Duty cycle in ns} –r <time period in ns>

 

In fact all your commands are kept in the transcript window AND in a transcript file.

That file can be edited and used as INPUT to the simulator so you do not have to keep restoring your state. These command files are called “do” files.

The transcript file starts its lines with “#” for information messages, these are comments for a do file. So you can keep them or delete them.

 

Edit the transcript file and save the file with an extension of <filename>.do then in the command line of ModelSim run the following command.

 

do <filename.do>

 

this will re-play all the commands in the file.