Main Content

vsim

Start and configure ModelSim for use with HDL Verifier

Description

vsim starts and configures the ModelSim™ simulator for use with the MATLAB® or Simulink® cosimulation.

vsim creates a startup (or .do) file that adds these Tcl commands to ModelSim:

You can use these ModelSim Tcl commands instead of the ModelSim vsim command. These commands load instances of VHDL® entities or Verilog® modules for simulations that use MATLAB or Simulink for verification.

Tip

When attempting to automate the cosimulation, use pingHdlSim to add a pause between the call to vsim and the call to run the simulation.

example

vsim(Name,Value) configures the ModelSim simulator using options specified by one or more name-value pair arguments.

example

Examples

Start and Configure ModelSim

Change the folder location to the ModelSim project folder, and then call the vsim function using the default executable. The function creates a temporary .do file in a temporary folder.

Specify the Tcl command vsimmatlab by using the 'tclstart' name-value pair argument. Specify to load an instance of the VHDL entity parse in the library work for MATLAB verification.

Begin the testbench session for an instance of the entity parse by using the matlabtb command. Specify TCP/IP socket communication on port 4449 and a testbench timing value of 10 ns.

cd VHDLproj  % Change folder to ModelSim project folder
vsim('tclstart','vsimmatlab work.parse; matlabtb parse 10 ns -socket 4449')

Change the folder location to the ModelSim project folder, and then call the vsim function. Specify the use of TCP/IP socket communication on the same computer for links between Simulink and ModelSim by using the 'socketsimulink' name-value pair argument. Specify using socket port 4449.

cd VHDLproj  % Change folder to ModelSim project folder
vsim('tclstart','vsimulink work.parse','socketsimulink','4449')
 

Input Arguments

collapse all

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: vsim('tclstart','vsimulink work.parse','socketsimulink','4449') specifies executing the vsimulink command during startup and using port number 4449 for socket communication between ModelSim and Simulink.

Path to the HDL Verifier HDL libraries, specified as the comma-separated pair consisting of 'libdir' and a folder name. The folder contains the libraries that enable ModelSim to communicate with MATLAB when ModelSim runs on a machine that does not have MATLAB installed.

If this property is not specified, the function uses the default path in the MATLAB installation.

Library file built using a compiler supplied with the HDL simulator, specified as the comma-separated pair consisting of 'libfile' and the library file name. The default library file is the version built using the same compiler that MATLAB uses. If the HDL simulator links to other libraries (including SystemC libraries) that are built using a compiler supplied with the HDL simulator, you can specify the library file using this name-value pair argument. See Cosimulation Libraries for versions of the library built using other compilers.

Note

Do not include the OS-specific library extension in the library file name.

Location to run the HDL simulator, specified as the comma-separated pair consisting of 'rundir' and a folder name.

If the value is “TEMPDIR”, the function creates a temporary directory to run ModelSim. By default, the function uses the current folder.

Run mode for the HDL simulator, specified as the comma-separated pair consisting of 'runmode' and one of the values in this table.

Value

Description

'GUI'

Start the HDL simulator with the ModelSim graphical user interface.

'CLI'

Start the HDL simulator in an interactive terminal window.

'Batch'

Start the HDL simulator in the background with no window (Linux®) or in a noninteractive command window (Windows®).

TCP/IP socket communication for links between ModelSim and MATLAB, specified as the comma-separated pair consisting of 'socketmatlabsysobj' and a port number or service name. If you are setting up communication between computing systems, you must also specify the internet address or name of the remote host.

Note

  • If ModelSim and MATLAB are running on the same computer, you can use shared memory for communication.

  • When this argument is not specified, the function uses shared memory communication. For more information on choosing TCP/IP socket ports, see TCP/IP Socket Ports.

TCP/IP socket communication for links between ModelSim and Simulink, specified as the comma-separated pair consisting of 'socketsimulink' and a port number or service name. If you are setting up communication between computing systems, you must also specify the name or internet address of the remote host.

Note

  • If ModelSim and MATLAB are running on the same computer, you can use shared memory for communication.

  • When this argument is not specified, the function uses shared memory communication. For more information on choosing TCP/IP socket ports, see TCP/IP Socket Ports.

Specify yes to create a startup Tcl file and launch ModelSim from vsim. Specify no to create a startup Tcl file without launching ModelSim.

The startup Tcl file contains pointers to MATLAB libraries. To run ModelSim on a machine without MATLAB, copy the startup Tcl file and MATLAB library files to the remote machine and start ModelSim manually. See Cosimulation Libraries.

Name and location of the generated Tcl file, specified as the comma-separated pair consisting of 'startupfile' and a path name. Each invocation of vsim creates a Tcl script that is applied during HDL simulator startup. By default, vsim generates the file name compile_and_launch.tcl in the folder specified by rundir. If the file name already exists, the file contents are overwritten. You can edit and use the generated file in a regular shell outside of MATLAB. For example:

sh> vsim -gui -do compile_and_launch.tcl

Tcl commands to execute during ModelSim startup, specified as the comma-separated pair consisting of 'tclstart' and one of these values:

  • vsimmatlab

  • vsimulink

  • vsimmatlabsysobj

The function appends these commands to the startup file.

Path to the ModelSim executable folder, specified as the comma-separated pair consisting of 'vsimdir' and a path name. By default, the function uses the first version of vsim.exe that it finds on the system path (defined by the path variable).

Specify this name-value pair argument if you want to start a different version of the ModelSim simulator, or if the version of the simulator you want to run is not on the system path.

Version History

Introduced in R2008a