| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → EDA Simulator Link |
| Contents | Index |
| Learn more about EDA Link Simulator |
| On this page… |
|---|
Process for Running MATLAB Test Bench Cosimulation Checking the MATLAB Server's Link Status Running a Test Bench Cosimulation |
To start and control the execution of a simulation in the MATLAB environment, perform the following steps:
Restart simulator during a test bench session (if necessary).
The first step to starting an HDL simulator and MATLAB test bench session is to check the MATLAB server's link status. Is the server running? If the server is running, what mode of communication and, if applicable, what TCP/IP socket port is the server using for its links? You can retrieve this information by using the MATLAB function hdldaemon with the 'status' option. For example:
hdldaemon('status')
The function displays a message that indicates whether the server is running and, if it is running, the number of connections it is handling. For example:
HDLDaemon socket server is running on port 4449 with 0 connections
If the server is not running, the message reads
HDLDaemon is NOT running
See "Link Status" in the hdldaemon reference documentation for information on determining the mode of communication and the TCP/IP socket in use.
These steps describe a typical sequence for running a simulation interactively from the main HDL simulator window:
Set breakpoints in the HDL and MATLAB code to verify and analyze simulation progress and correctness.
How you set breakpoints in the HDL simulator will vary depending on what simulator application you are using.
In MATLAB, there are several ways you can set breakpoints; for example, by using the Set/Clear Breakpoint button on the toolbar.
Issue matlabtb command at the HDL simulator prompt.
When you begin a specific test bench session, you specify parameters that identify the following information:
The mode and, if appropriate, TCP/IP data necessary for connecting to a MATLAB server (see matlabtb reference)
The MATLAB function that is associated with and executes on behalf of the HDL instance (see Binding the HDL Module Component to the MATLAB Test Bench Function)
Timing specifications and other control data that specifies when the module's MATLAB function is to be called (see Schedule Options for a Test Bench Session)
For example:
hdlsim> matlabtb osc_top -sensitivity /osc_top/sine_out
-socket 4448 -mfunc hosctbStart the simulation by entering the HDL simulator run command.
The run command offers a variety of options for applying control over how a simulation runs (refer to your HDL simulator documentation for details). For example, you can specify that a simulation run for several time steps.
The following command instructs the HDL simulator to run the loaded simulation for 50000 time steps:
run 50000
Step through the simulation and examine values.
How you step through the simulation in the HDL simulator will vary depending on what simulator application you are using.
In MATLAB, there are several ways you can step through code; for example, by clicking the Step toolbar button.
When you block execution of the MATLAB function, the HDL simulator also blocks and remains blocked until you clear all breakpoints in the function's M-code.
Resume the simulation, as needed.
How you resume the simulation in the HDL simulator will vary depending on what simulator application you are using.
In MATLAB, there are several ways you can resume the simulation; for example, by clicking the Continue toolbar button.
The following HDL simulator command resumes a simulation:
run -continue
For more information on HDL simulator and MATLAB debugging features, see the appropriate HDL simulator documentation and MATLAB online help or documentation.
After you establish a link between the HDL simulator and MATLAB, you can then apply stimuli to the test bench environment. One way of applying stimuli is through the iport parameter of the linked MATLAB function. This parameter forces signal values by deposit.
Other ways to apply stimuli include issuing force commands in the ModelSim main window or using the Edit > Clock option in the ModelSim Signals window.
For example, consider the following sequence of force commands:
VSIM n> force clk 0 0 ns, 1 5 ns -repeat 10 ns VSIM n> force clk_en 1 0 VSIM n> force reset 0 0
These commands drive the following signals:
The clk signal to 0 at 0 nanoseconds after the current simulation time and to 1 at 5 nanoseconds after the current HDL simulation time. This cycle repeats starting at 10 nanoseconds after the current simulation time, causing transitions from 1 to 0 and 0 to 1 every 5 nanoseconds, as the following diagram shows.
![]()
For example,
force /foobar/clk 0 0, 1 5 -repeat 10
The clk_en signal to 1 at 0 nanoseconds after the current simulation time.
The reset signal to 0 at 0 nanoseconds after the current simulation time.
Because the HDL simulator issues the service requests during a MATLAB test bench session, you must restart a test bench session from the HDL simulator. To restart a session, perform the following steps:
Make the HDL simulator your active window, if your input focus was not already set to that application.
Reload HDL design elements and reset the simulation time to zero.
Reissue the matlabtb command.
Note To restart a simulation that is in progress, issue a break command and end the current simulation session before restarting a new session. |
![]() | Schedule Options for a Test Bench Session | Stop Test Bench Simulation | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |