This example guides you through the basic steps for setting up an HDL Verifier™ application using the Cosimulation Wizard in the Simulink® environment.
The Cosimulation Wizard is a graphical user interface (GUI) that guides you through the process of setting up cosimulation between MATLAB® or Simulink® and a Hardware Description Language (HDL) simulator.
In this example, you use Simulink and ModelSim® to verify a design of a raised cosine filter written in Verilog. The raised cosine filter is commonly used as a pulse shaping filter in digital communication systems. It produces no inter-symbol interference (ISI) for the input of modulated pulses.
To verify the functionality of this raised cosine filter, a Simulink testbench is provided. This testbench generates input to the HDL design under test (DUT) and plots the waveforms of both input and output.
The Cosimulation Wizard takes the provided Verilog file of this raised cosine filter as its input. It also collects user input required for setting up cosimulation in each step. At the end of the example, the Cosimulation Wizard generates a Simulink block that represents the HDL design in the Simulink model, a MATLAB script that compiles HDL design, and a MATLAB script that launches the HDL simulator for cosimulation. During simulation, you can watch the input and output waveforms of this HDL filter in Simulink.
These products are required for this example.
One of these supported HDL simulators: Mentor Graphics® ModelSim®/QuestaSim® or Cadence® Incisive®/Xcelium®
To launch the Cosimulation Wizard from the model, select the Apps tab in the Simulink toolstrip and click HDL Verifier. This action adds the HDL Verifier tab to the Simulink Toolstrip. Then, in the Mode section select HDL Cosimulation. Click Import HDL Files in the Generate Cosim Block section.
In the Cosimulation Type page, perform the following steps:
If you are using ModelSim or Questa, leave HDL Simulator option as
ModelSim. If you are using Incisive or Xcelium, change HDL Simulator option to
Leave the default option Use HDL simulator executables on the system path option if the HDL simulator executables appear on your system path. If these executable do not appear on the path, click on the Browse button to specify the location of these executables.
Click Next to proceed to the HDL Files page.
In the HDL Files page, perform the following steps:
Click Add and select either
rcostflt_rtl.v for Verilog or
rcosflt_rtl.vhd for VHDL.
Review the file in the file list with the file type identified as you expected.
Click Next to proceed to the HDL Compilation page.
In the HDL Compilation page, the Cosimulation Wizard lists the default commands in the Compilation Commands window. You do not need to change these commands for this tutorial.
When you run the Cosimulation Wizard with your own code, you may add or change the compilation commands in this window.
Click Next to proceed to the HDL Modules pane. This will in turn trigger the compilation. The MATLAB console displays the compilation log. If an error occurs during compilation, that error appears in the Status area.
In the Simulation Options pane, perform the following steps:
Specify the name of HDL module/entity for cosimulation. From the drop-down list, select
rcosflt_rtl. This module is the Verilog/VHDL module you use for cosimulation. If you do not see
rcosflt_rtl in the drop-down list, you can enter the file name manually.
For Connection method, select
Shared Memory if your firewall policy does not allow TCP/IP socket communication.
Click Next to proceed to the Simulink Ports pane. The Cosimulation Wizard launches the HDL simulator in the background console using the specified HDL module and simulation options. After the wizard launches the HDL simulator, the wizard populates the input and output ports on the Verilog/VHDL module
rcosflt_rtl and displays them in the next step.
In the Specify Port Types step, the Cosimulation Wizard displays two tables containing the input and output ports of
The Cosimulation Wizard attempts to identify the port type of each port. If the wizard incorrectly identifies a port, you can change the port type using these tables.
For input ports, you can select from
Unused. HDL Verifier connects only the input ports marked
Inputs to Simulink during cosimulation.
HDL Verifier connects output ports marked
Output with Simulink during cosimulation. The wizard and Simulink ignore those output ports marked
Unused during cosimulation.
You can change the parameters for signals identified as
Reset at a later step.
Accept the default port types and click Next to proceed to the Output Port Details page.
In the Output Port Details page, perform the following steps:
Set the sample time of
-1 to inherit via back propagation.
You can see from the Verilog code that the Cosimulation Wizard represents the output in a
sfix34_En29 format. Change the following fields:
Data Type to
Fraction Length to
Click Next to proceed to the Clock/Reset Details page.
For this example, set the clock Period (ns) to 20. From the Verilog code, you know that the reset is synchronous and the active value is 1. You can reset the entire HDL design at time 1 ns, triggered by the rising edge of the clock. Use a duration of 15 ns for the reset signal.
In the Clock/Reset page, perform the following steps:
Set HDL time unit to
Set clock period to 20.
Leave or set active edge to
Leave or set reset initial value to 1.
Set reset signal duration to 15.
Click Next to proceed to the Start Time Alignment page.
The Start Time Alignment page displays a plot for the waveforms of clock and reset signals. The Cosimulation Wizard shows the HDL time to start cosimulation with a red line. The start time is also the time at which the Simulink gets the first input sample from the HDL simulator.
In the Start Time Alignment page, set the alignment. The active edge of our clock is a rising edge. Thus, at time 20 ns in the HDL simulator, the registered output of the raised cosine filter is stable. No race condition exists, and the default HDL time to start cosimulation (20 ns) is what we want for this simulation. You do not need to make any changes to the start time.
Click Next to proceed to Block Generation.
Before you generate the HDL Cosimulation block, you have the option to determine the timescale before you finish the Cosimulation Wizard. Alternately, you can instruct HDL Verifier to calculate a timescale later. Timescale calculation by the verification software occurs after you connect all the input/output ports of the generated HDL Cosimulation block and start simulation.
In the Block Generation page, leave Automatically determine timescale at start of simulation selected (default). Later, you will have the opportunity to view the calculated timescale and change that value before you being simulation.
Click Finish to complete the Cosimulation Wizard session.
In this example, the Simulink test bench model
rcosflt_tb has been provided. After you click Finish in the Cosimulation Wizard, Simulink inserts the following items at the center of the model canvas:
An HDL Cosimulation block
A block to recompile the HDL design (contains a link to a script that is launched by double-clicking the block)
A block to launch the HDL simulator (contains a link to a script that is launched by double-clicking the block)
Position the HDL Cosimulation block so that the constant and convert blocks line up as inputs to the HDL Cosimulation block and the bus lines up as output. Connect the blocks. Your model now looks similar to that in the following figure.
Launch the HDL simulator by double-clicking the block labeled Launch HDL Simulator.
When the HDL simulator is ready, return to Simulink and start simulation.
Determine timescale. Recall that you selected Automatically determine timescale at start of simulation option on the last page of the Cosimulation Wizard. When doing so, HDL Verifier launches the Timescale Details graphical interface instead of starting the simulation. Both the HDL simulator and Simulink sample the
filter_out ports at 1 second. However, their sample time in the HDL simulator should be the same as the clock period (20 ns). Change the Simulink sample time of
/rcosflt_rtl/clk to 1 (seconds), and press Enter. The wizard then updates the table. The following figure shows the new timescale: 1 second in Simulink corresponds to 2e-008 s in the HDL simulator.
Click OK to close the Timescale Details dialog. Restart Simulink simulation and verify the results from the scope in the test bench model.
The scope displays both the delayed version of input to raised cosine filter and that filter's output. If you sample the output of this filter output directly, no inter-symbol-interference occurs.