Electronics Tinkerer
Projects 'N Stuff

Modelsim Project Setup

Last Update: 2023-10-28 This tutorial will be using the verilog files available here: Verilog Files When you first open Modelsim, there might be a welcome window. Press "Jumpstart" to close. The Modelsim welcome screen, showing the ever exciting "Jumpstart" button. With that closed, you should be greeted with the project startup page. This shows a list of the various libraries that are loaded. A list of libraries which are included with Modelsim. To get started with a new project, we first need to set our working directory. Go to File > Change Directory... and navigate to a directory where you want to perform your simulation. I typically create a "sim" directory within my projects specially for this purpose. Selection of change directory. With the working directory set, we can create a new project. Navigate to File > New > Project. You need to choose a project name. For this tutorial, I am going to call this "counter-test" The other fields in the window include the project location (which should be the directory you just chose) and the library name (which is where the compiler will place all the compiled modules). A lovely window that lets us name our new project! Once you have named the project, press OK. A new window should pop up. Click on "Add Existing File". In the following pop up, click "Browse" and navigate to your verilog files. Select all that you need for the testing. There are two options for adding the files. The default is to reference the HDL source from its curernt location. This allows you to keep your code in one location but you must not move it later (or you'll have to re-reference it in Modelsim). The second option is to copy it to the project directory, which I usually do not recommend since you will then have two copies of your source files and you will need to keep them in sync. When you are done, press OK and close the remaining pop up windows. Listing of files to be added to the project by reference. In the main window, you should see your source files appear. Next to each will be a blue questionmark. This indicates that Modelsim has not yet tried to compile the source files. Our source files sitting in a list. To fix this, you have two options. First option is to compile each one at a time by right-clicking on the file and selecting Compile > Compile Selected. Compiling only one file. The second option is to navigate to the window menu and select Compile > Compile All. Compiling all files. If everything went well, you should have no errors in the transcript window and the files will have a green checkmark: All files are green and there are no errors in the transcript window! If things went less then well, you can navigate to Compile > Compile Summary to view the compiler errors. Compile summary menu item.

Running a Simulation

Once all your source files compile successfully, navigate to Simulate > Start Simulation. Selection of the run simulation option. This will open a window where you can select the library module that you want to run as the top level in your simulaton. Click on the '+' icon next to your library name (most likely, "work") and select the module to test. Selection of the tb_counter module so that we can simulate the counter test bench. Select "OK" and the simulation view will be opened. To the left is the hierarchical display of all the instantiated modules in your design. When one is selected, the blue "Objects" window will show the relevant variables, nets, and parameters along with their current values. Simulation window showing the module hierarchy, objects, values, and simulation status. For a simple test bench like the one we are using, the waveform viewer is a good way to get an idea of what the circuit is doing. The first step to using the waveform viewer is to add a signal to view. This can be done by right clicking on the instance of interest from the design hierarchy and selcting Add to > Wave > All items in region. Selection of items to add to the wave viewer. A wave viewer window will appear. A few key buttons to note: Waveform window with two signals. For the simple counter test, we can set the run time to 100 ns and press the Run button. After pressing (F) to soom full, we see that we get a nice clock signal but the counter's value is this flat red line. In Modelsim, a red line means that the signal contains at least one bit with value 'X', which is "unknown." This happens since we did not initialize the counter's internal register to some known value at the beginning of the sim. (You can tell most simulators to do this initialization automatically, typically with all 0's or random data, if you so choose). Green waveform for clock, red (bad) waveform for counter value. For the sake of the tutorial, we will try setting its value in the sim instead of using a reset or initial block. To do this, go back to the simulation window and right click on the counter's internal register and select Modify > Change Value. Selecting Change Value on a signal with a currently unknown value. This will open a window that allows you to set the value of the signal. In this case, I am going to set the counter to all zeros. Setting of the counter's value to all zeros. If we go back to the wave window and press the Run button, we see that our counter starts to work as expected! The counter is incrementing once per clock cycle.

Tips

Saving your waveform window setup

Let's say that you are looking at a design with a few hundred signals in the wave viewer and you have spend a few hours getting them all arranged nicely in just the right order. You suddenly notice that your laptop's battery is at 5% and you'll need stop working ASAP. The good news is that you don't have to lose all that organizational work! Simply press Ctrl+S in the waveform window (File > Save Format) and your configuration will be saved. The next time that your open the wave viewer, this config can be loaded with File > Load and selecting the ".do" file.

Keyboard "shortcuts"

Many of the commands that you run via the GUI menus can be run from the sim window's transcript prompt. Take for example the 'run' command. Once your design is loaded, you can type "run" to start the simulation. 'restart' will also reset the simulation.

Opening an existing project

To open an existing project, follow the directions to change the directory as outlined above. Then navigate to File > Open, set the file type to Project Files (*.mpf) and locate the project file you want to open.
That's all!
© 2021-2024 — Electronics Tinkerer — All rights reserved.
Top | Home | Privacy | Terms of Service