Clear Filters
Clear Filters

How to restart ModelSim simulation after each iteration from MATLAB script co-simulation?

27 views (last 30 days)
I am working on a vhdl model that is simulated using hdl cosimulator app from simulink. The control and initialization steps are described as MATLAB script. The data is sent from matlab to simulink using from workspace blocks, then simulink fed the hdl function (Modelsim) using shared memory. After simulation process in Modelsim the data sent back to MATLAB. Currently I am facing the problem of timing, in the first iteration the ModelSim output is fine but in the 2nd and on, they delayed by a specific timing.
What I would like to do is how to restart simulation in modelsim from matlab script or from simulink after each iteration process ?
Marc Erickson
Marc Erickson on 2 Jun 2023
Within the HDL simulator, one can invoke a simulator restart which will reset all simulator state and reload the application that communicates with Simulink.
Unfortunately, there is no way to invoke this restart from within our application because doing so will hang the HDL simulator.
For each run of Simulink, it is safest to reinvoke the HDL simulator. For non-interactive use, using the "-c" option to vsim will ensure a faster startup and run time.
Bilal MEJMAA on 7 Jun 2023
Thank you so much for your answer. I am starting the cosimulation using this cmd "Sim_out = sim('Modelname')", I don't know where to use the -c option. I am also thinking of using a "" that executes the "restart -force -nowave" cmd, but I have no idea how to execute a .d file from matlab script

Sign in to comment.

Accepted Answer

Bharath Venkataraman
Bharath Venkataraman on 15 Jun 2023
I believe Marc's suggestion is to close ModelSim after every run of Simulink and reopen it.
To start ModelSim, you typically use the vsim command from MATLAB. This may be something you do manually, or it may be executed in the model PreLoad, PostLoad or InitFcn (see Model callbacks). Move it to the StartFcn or InitFcn instead - this will start a new ModelSim each time you simulate (make sure you close ModelSim after you each simulation).
Marc Erickson
Marc Erickson on 22 Jun 2023
Yes, great, the most convenient way to start the co-simulation is through vsim.m like you discovered!
If you desire to shut down ModelSim after each iteration, my suspicion is that you are not interested in interactively debugging the HDL simulation. In that case, you can likely get the behavior you are looking for by running the HDL simulation in the background--it will close the HDL simulator automatically.
Try the 'runmode' flag to vsim.m to specify running in batch mode.
'runmode' - Specify how to start the HDL simulator. One of the following strings:
'Batch' : On Windows, run in a non-interactive command window
On Linux, run in background with no window
'CLI' : Run in an interactive command-line window
'GUI' : Run with ModelSim graphical user interface
Default: 'GUI'
So your command would look like:

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!