Take control of your VHDL libraries in ModelSim

This is a follow-up to my article “Advanced VHDL verification on a budget”. This article is about understanding libraries in ModelSim, and how to tweak their location and visibility.

Before proceeding, you should have a proper understanding of the concept of libraries in VHDL. I recommend you get a copy of Peter J. Ashenden’s excellent book “The Designer’s Guide to VHDL” and then read chapter 5.4 on the subject. You may also find this book on Google Books. Also, I suggest you read the following posts on the Sigasi website:

Using ModelSim Altera Starter Edition

For advanced VHDL verification, the ModelSim Altera Starter Edition is an excellent option. It has mixed-language support, supports VHDL-2008, and with their free edition you may run any number of instances.

When you start up ModelSim Altera Starter Edition, you are greeted with the Library view, showing all the pre-compiled libraries as delivered with the simulator:

2016-03-22 13_02_08-ModelSim ALTERA STARTER EDITION 10.4b - Custom Altera Version

Fig. 1. ModelSim Altera Starter Edition default library view

When I counted, the number of libraries listed was 72(!). For a cleaner experience, you may hide most of these libraries if you want, like this:

  1. Navigate to your ModelSim install path, and
  2. Remove the read-only attribute of the the modelsim.ini file, and
  3. Edit modelsim.ini and comment out the libraries you would like to hide.

On my computer, the modelsim.ini file is located in the C:\mentor\modelsim\15.1\modelsim_ase directory. If you comment out only the Altera specific libraries, the ModelSim library view will look like this:

2016-03-22 13_24_52-ModelSim ALTERA STARTER EDITION 10.4b - Custom Altera Version

Fig. 2. Libraries view with vendor specific libraries removed

If you are only going to do VHDL simulation, you may hide even more libraries. For advanced VHDL only simulation, these are the only two default libraries that you will need:

2016-03-22 13_34_08-ModelSim ALTERA STARTER EDITION 10.4b - Custom Altera Version

Fig 3. Required default libraries for advanced VHDL simulation

This will be our default view for a later tutorial on Advanced VHDL Simulation.

ModelSim working directory

When you work with ModelSim, it always has the context of a current working directory. To view the path of your current working directory, type the pwd command in the ModelSim command window:

ModelSim> pwd
# C:/mentor/modelsim/15.1

ModelSim>

The example above shows my default working directory after I start ModelSim Altera Edition for the first time. As this directory is my installation path, this is certainly not a directory where I would want to work with my simulation projects. So, start by creating a new directory somewhere else on your computer and change your working directory there. The ModelSim command window responds to cd and mkdir commands, or you may use the File->Change Directory menu item to navigate to a directory of your choice.

If I am working with a new IP called my_ip, then my personal preference is to first create a directory called c:/proj/fpga/ip/my_ip. Below the my_ip directory I would then create at least the following 3 subdirectories:

  • c:/proj/fpga/ip/my_ip/src <- to store my IP source code
  • c:/proj/fpga/ip/my_ip/tb <- to store my IP testbench code
  • c:/proj/fpga/ip/my_ip/sim <– to be my ModelSim working directory

Then, navigate to to your sim working directory to start working on your simulation project.

Altering modelsim.ini the PROPER way

The modelsim.ini file in my C:/mentor/modelsim/15.1/modelsim_ase directory has a read-only attribute by default. This means that you are not supposed to fiddle with it!

Instead, make a copy of that default modelsim.ini file, and place it in your ModelSim working directory. The modelsim.ini file in your working directory now has precedence over the default modelsim.ini file in your ModelSim installation path. The modelsim.ini file in your working directory is now the file you want to edit to change the default libraries and settings.

This will be our preferred way of limiting the library scope of ModelSim. You may want to prepare multiple modelsim.ini files on your computer depending on your simulation requirements.

A modelsim.ini for working with pure VHDL code

For working with pure VHDL code this is the entire contents of my default modelsim.ini file:

[Library]
std = $MODEL_TECH/../std
ieee = $MODEL_TECH/../ieee

[vcom]
VHDL93 = 2008

[vsim]
Resolution = ps
UnbufferedOutput = 1

I place this file in every ModelSim working directory where I want to work with pure VHDL code. This modelsim.ini will:

  • Reference only the standard VHDL libraries by default
  • Set the VHDL compiler to VHDL-2008 mode (default is VHDL-2002)
  • Set timing resolution to 1 ps (default is 1 ns)
  • Set UnbufferedOutput = 1 (recommended setting by some verification libraries)

Working with ModelSim project (.mpf) files

Just to make the confusion complete, there is yet another type of file where settings may be stored. In your ModelSim working directory, you have the option of creating a new project (.mpf) file. When you open a project file, it’s content have precedence over any modelsim.ini file.

When you create a new project in ModelSim, you have the option of:

  • copy the contents of any existing modelsim.ini file into your project file, or
  • reference the contents of any existing modelsim.ini file in your project file

I always choose to reference the modelsim.ini file in my current directory.

modelsim.ini referencing another modelsim.ini

A modelsim.ini file may itself also reference another modelsim.ini file, like this:

[Library]
others = $MODEL_TECH/../modelsim.ini
...

And you may then add your custom libraries below the “others” line.

What is stored in the ModelSim working directory?

You should now be aware that the ModelSim working directory may contain:

  • a modelsim.ini file
  • one or more ModelSim project (.mpf) files.

This is also the default directory for other simulation specific files, like:

  • simulation input and output files
  • .do files (ModelSim scripting files)
  • the transcript file

But perhaps even more importantly: The ModelSim working directory is the is the default parent directory for compilation of new libraries. For each VHDL file in your project, you may specify a library name (if you don’t – then the default is library work). When you compile your project, it will be compiled into libraries which are located as subdirectories of your current working directory.

If you like – these compiled libraries may be moved around elsewhere on your computer, and referenced in your modelsim.ini files or in your .mpf project files. But – rather than moving compiled libraries around, it is better to have them compiled directly to their final destination. This is most easily done using scripting. I will demonstrate this in my upcoming Advanced VHDL Simulation tutorial.

Compiling Xilinx libraries with ModelSim Altera Starter Edition

Yes – this is possible! In Xilinx Vivado, choose Tools->Options to specify your ModelSim install path:

2016-03-22 16_43_02-Vivado Options

fig. 4 Specify the ModelSim install path in Xilinx Vivado

Then, in menu Tools->Compile Simulation Libraries, set the following options, and then push the Compile button:

2016-03-22 16_35_12-Compile Simulation Libraries

fig 5. Compiling Xilinx libraries with ModelSim Altera Edition

Using scripting, the Xilinx libraries will now be compiled into subdirectories of C:/proj/fpga/lib/msim_ase/viv2015.4. When compilation is done, this directory now looks like this:

2016-03-22 16_51_41-C__proj_fpga_lib_msim_ase_viv2015.4

fig 6. Xilinx libraries compiled with ModelSim Altera Edition

Notice that the Xilinx Compile Simulation Libraries tool created an all new modelsim.ini file. This can be copied to your ModelSim working directories if you want to work with Xilinx library objects in your simulation.

All set!

If you have followed this article along with my previous 2 articles:

– then you are all set for my upcoming tutorial on Advanced VHDL Simulation coming up soon!

  • If you would like to copy the modelsim.ini to the current directory without the hassle of finding where it is stored you can just use vmap:

    $ vmap -c
    Copying /opt/altera/14.1/modelsim_ase/linuxaloem/../modelsim.ini to modelsim.ini