Products & Services Solutions Academia Support User Community Company

Learn more about EDA Link Simulator   

Run MATLAB Test Bench Simulation

Process for Running MATLAB Test Bench Cosimulation

To start and control the execution of a simulation in the MATLAB environment, perform the following steps:

  1. Check the MATLAB server's link status.

  2. Run and monitor the test bench session.

  3. Apply test bench stimuli.

  4. Restart simulator during a test bench session (if necessary).

Checking the MATLAB Server's Link Status

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.

Running a Test Bench Cosimulation

These steps describe a typical sequence for running a simulation interactively from the main HDL simulator window:

  1. 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.

  2. Issue matlabtb command at the HDL simulator prompt.

    When you begin a specific test bench session, you specify parameters that identify the following information:

    For example:

    hdlsim> matlabtb osc_top -sensitivity /osc_top/sine_out
          -socket 4448 -mfunc hosctb
  3. Start 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
    
  4. 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.

  5. 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.

  6. 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.

Applying Stimuli with the HDL Simulator force Command

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:

Restarting a Test Bench Simulation

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:

  1. Make the HDL simulator your active window, if your input focus was not already set to that application.

  2. Reload HDL design elements and reset the simulation time to zero.

  3. Reissue the matlabtb command.

  


Recommended Products

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