这是用户在 2024-5-29 13:27 为 https://ww2.mathworks.cn/help/hdlverifier/ug/verify-hdl-model-with-matlab-testbench.html 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?
Main Content 主要内容

Verify HDL Module with MATLAB Test Bench
使用 MATLAB 测试台验证 HDL 模块

This tutorial guides you through the basic steps to set up an HDL Verifier™ application that uses MATLAB® to verify a simple HDL design. In this tutorial, you develop, simulate, and verify a model of a pseudorandom number generator based on the Fibonacci sequence. The model is coded in VHDL®.
本教程指导您完成设置 HDL Verifier™ 应用程序的基本步骤,该应用程序使用 MATLAB® 验证简单的 HDL 设计。在本教程中,您将开发、仿真和验证一个基于斐波那契数列的伪随机数发生器模型。该模型使用 VHDL® 编码。

This tutorial uses QuestaSim® to create and run a testbench and therefore requires QuestaSim to be on the system path. For other supported tools and requirements see Cosimulation Requirements.
本教程使用 QuestaSim® 创建和运行测试平台,因此要求系统路径中包含 QuestaSim。有关其他支持工具和要求,请参阅 Cosimulation Requirements。

Start the MATLAB Server 启动 MATLAB 服务器

This section describes how to start the MATLAB server component and check for client connections using shared memory or TCP/IP socket mode. These instructions assume you are familiar with the MATLAB user interface.
本节介绍如何使用共享内存或 TCP/IP 套接字模式启动 MATLAB 服务器组件并检查客户端连接。这些说明假定您熟悉 MATLAB 用户界面。

1. Start MATLAB. 1.启动 MATLAB。

2. Verify that the MATLAB server is running by calling hdldaemon('status') in the MATLAB Command Window.
2.在 MATLAB 命令窗口 . 中调用 hdldaemon('status') 验证 MATLAB 服务器是否正在运行

  • If the server is not running, the message reads: HDLDaemon is NOT running.
    如果服务器未运行,则消息内容为 HDLDaemon is NOT running

  • If the server is running in TCP/IP socket mode, the message reads: HDLDaemon socket server is running on Port portnum with 0 connections.
    如果服务器在 TCP/IP 套接字模式下运行,则报文内容为 HDLDaemon socket server is running on Port portnum with 0 connections .

  • If the server is running in shared memory mode, the message reads: HDLDaemon shared memory server is running with 0 connections.
    如果服务器在共享内存模式下运行,则消息内容为 HDLDaemon shared memory server is running with 0 connections

  • If the server is not currently running, skip to step 5.
    如果服务器当前未运行,请跳至步骤 5

3. Shut down the server by typing hdldaemon('kill'). You will see the message HDLDaemon server was shutdown, which confirms that the server is shut down.
3.键入 hdldaemon('kill') 关闭服务器。您将看到 HDLDaemon server was shutdown 消息,确认服务器已关闭。

4. Start the server in TCP/IP socket mode by calling hdldaemon('socket', 0). The value 0 in the property name/property value pair ('socket' 0) specifies that the operating system assigns the server a TCP/IP socket port that is available on your system.
4.通过调用 hdldaemon('socket', 0) 以 TCP/IP 套接字模式启动服务器。属性名/属性值对 ('socket' 0) 中的值 0 表示操作系统为服务器分配了一个在系统中可用的 TCP/IP 套接字端口。

5. The server informs you that it has started by displaying the message:
5.服务器通过显示信息通知您它已启动:

HDLDaemon socket server is running on Port portnum with 0 connections.

Make note of the portnum. You need it when you issue the matlabtb command in Load Simulation. Note that the portnum will be specific to your system.
请注意 portnum 。在加载模拟中发出 matlabtb 命令时需要用到它。请注意, portnum 将针对您的系统。

You may also specify the MATLAB server to use shared memory communication instead of TCP/IP socket communication. For this tutorial we use socket communication. For details on how to specify the various options, see hdldaemon.
您也可以指定 MATLAB 服务器使用共享内存通信,而不是 TCP/IP 套接字通信。在本教程中,我们使用套接字通信。有关如何指定各种选项的详细信息,请参阅 hdldaemon

Start QuestaSim Simulator and Set Up for Cosimulation
启动 QuestaSim 模拟器并进行模拟设置

This section describes the basic procedure to start the QuestaSim software and set up a QuestaSim design library. These instructions assume you are familiar with the QuestaSim user interface.
本节介绍启动 QuestaSim 软件和设置 QuestaSim 设计库的基本步骤。这些说明假定您已熟悉 QuestaSim 用户界面。

1. To start QuestaSim, enter vsim in the MATLAB Command Window. This function launches and configures QuestaSim for use with the HDL Verifier software. The first folder of QuestaSim should match your MATLAB current folder.
1.要启动 QuestaSim,请在 MATLAB 命令窗口中输入 vsim 。此函数启动并配置 QuestaSim,以便与 HDL Verifier 软件一起使用。QuestaSim 的第一个文件夹应与 MATLAB 当前文件夹一致。

2. Verify the current QuestaSim folder. You can verify that the current QuestaSim folder matches the MATLAB current folder by entering the ls command in the QuestaSim Command Window.
2.验证当前 QuestaSim 文件夹。您可以在 QuestaSim 命令窗口中输入 ls 命令,验证当前 QuestaSim 文件夹是否与 MATLAB 当前文件夹一致。

The command should list the files modsimrand.m, modsimrand.vhd, modsimrand_plot.m, draw_modsimrand_fig.m, transcript, and compile_and_launch.tcl.
命令应列出文件 modsimrand.m , modsimrand.vhd , modsimrand_plot.m , draw_modsimrand_fig.m , transcriptcompile_and_launch.tcl

If it does not, change your QuestaSim folder to the current MATLAB folder. You can find the current MATLAB folder by looking in the Current Folder Browser or by viewing the Current Folder navigation bar. In QuestaSim, you can change the working folder by issuing the command: cd directory
如果没有,请将 QuestaSim 文件夹更改为当前 MATLAB 文件夹。您可以通过 "当前文件夹浏览器 "或查看 "当前文件夹 "导航栏找到当前 MATLAB 文件夹。在 QuestaSim 中,您可以发出以下命令更改工作文件夹: cd directory

Where directory is the folder you want to work from. Or you may change directory by selecting File > Change Directory...
其中 directory 是您要使用的文件夹。或者选择文件 > 更改目录... 来更改目录。

3. Create a design library to hold your compilation results. To create the library and the required _info file, enter the vlib command:
3.创建设计库,保存编译结果。要创建库和所需的 _info 文件,请输入 vlib 命令:

QuestaSim> vlib work

Note: You must use the QuestaSim File menu or the vlib command to create the library folder so that the required _info file is created. Do not create the library with operating system commands.
注意: 必须使用 QuestaSim 文件菜单或 vlib 命令创建库文件夹,以便创建所需的 _info 文件。请勿使用操作系统命令创建库。

Develop VHDL Code 开发 VHDL 代码

After setting up a design library, you need to use the QuestaSim Editor to create and modify your VHDL code. For this tutorial, you do not need to create the VHDL code yourself. Instead, open and examine the existing file modsimrand.vhd. This section highlights areas of code in modsimrand.vhd that are of interest for a QuestaSim and MATLAB test bench.
建立设计库后,您需要使用 QuestaSim 编辑器来创建和修改 VHDL 代码。在本教程中,您无需自己创建 VHDL 代码。相反,请打开并检查现有文件 modsimrand.vhd 。本节将重点介绍 QuestaSim 和 MATLAB 测试台所关注的 modsimrand.vhd 中的代码区域。

If you choose not to examine the VHDL code at this time, skip to Compile VHDL Code.
如果此时不检查 VHDL 代码,请跳至编译 VHDL 代码。

You can open modsimrand.vhd in the edit window with the edit command:
您可以使用 edit 命令在编辑窗口中打开 modsimrand.vhd

QuestaSim> edit modsimrand.vhd

QuestaSim opens its edit window and displays the VHDL code of modsimrand.vhd.
QuestaSim 打开编辑窗口,显示 modsimrand.vhd 的 VHDL 代码。

1_vhdl_code.png

While you are viewing the file:
查看文件时:

1. The line ENTITY modsimrand contains the definition for the VHDL entity modsimrand:
1. ENTITY modsimrand 行包含 VHDL 实体 modsimrand 的定义:

ENTITY modsimrand IS

PORT (

clk : IN std_logic ;

clk_en : IN std_logic ;

reset : IN std_logic ;

dout : OUT std_logic_vector (31 DOWNTO 0);

END modsimrand;

This is the entity that will be verified in the MATLAB environment. Note that:
这是将在 MATLAB 环境中验证的实体。请注意

  • By default, the MATLAB server assumes that the name of the MATLAB function that verifies the entity in the MATLAB environment is the same as the entity name. You can name the MATLAB function explicitly. However, if you do not specify a name, the server expects the function name to match the entity name. In this example, the MATLAB function name is modsimrand_plot and does not match the entity name.
    默认情况下,MATLAB 服务器会假定在 MATLAB 环境中验证实体的 MATLAB 函数名称与实体名称相同。您可以明确命名 MATLAB 函数。但是,如果不指定名称,服务器会认为函数名称与实体名称一致。在本例中,MATLAB 函数名称是 modsimrand_plot ,与实体名称不匹配。

  • You must define the entity with a PORT clause that includes at least one port definition. Each port definition must specify a port mode (IN, OUT, or INOUT) and a VHDL data type that is supported by the HDL Verifier software. The entity modsimrand in this example is defined with three input ports clk, clk_en, and reset of type STD_LOGIC and an output port dout of type STD_LOGIC_VECTOR. The output port passes simulation output data to the MATLAB function for verification. The optional input ports receive clock and reset signals from the function. Alternatively, the input ports can receive signals from QuestaSim force commands. For more information on coding port entities for use with MATLAB, see Coding HDL Modules for Verification with MATLAB.
    您必须使用 PORT 子句定义实体,该子句至少包含一个端口定义。每个端口定义必须指定一种端口模式( INOUTINOUT )和 HDL Verifier 软件支持的 VHDL 数据类型。本示例中的实体 modsimrand 定义了三个输入端口 clkclk_enreset 类型为 STD_LOGIC 和一个输出端口 dout 类型为 STD_LOGIC_VECTOR 。输出端口将仿真输出数据传递给 MATLAB 函数进行验证。可选输入端口从函数接收时钟和复位信号。或者,输入端口可以接收来自 QuestaSim force 命令的信号。有关使用 MATLAB 对端口实体进行编码的更多信息,请参阅使用 MATLAB 进行验证的 HDL 模块编码。

2. The remaining code for modsimrand.vhd defines a behavioral architecture for modsimrand that writes a randomly generated Fibonacci sequence to an output register when the clock experiences a rising edge.
2. modsimrand.vhd 的剩余代码定义了 modsimrand 的行为架构,当时钟出现上升沿时,将随机生成的斐波那契序列写入输出寄存器。

When you finish examining the file, close the QuestaSim edit window.
完成文件检查后,关闭 QuestaSim 编辑窗口。

Compile VHDL Code 编译 VHDL 代码

After you create or edit your VHDL source files, you need to compile them. In this tutorial, you need to compile modsimrand.vhd. You can compile the file is by clicking the file name in the project workspace and select Compile > Compile All. An alternative is to specify modsimrand.vhd with the vcom command:
创建或编辑 VHDL 源文件后,需要对其进行编译。在本教程中,您需要编译 modsimrand.vhd 。您可以在项目工作区中单击文件名,然后选择编译 > 全部编译来编译该文件。另一种方法是使用 vcom 命令指定 modsimrand.vhd

QuestaSim> vcom modsimrand.vhd

If the compilation succeeds, messages appear in the Command Window and the compiler populates the work library with the compilation results.
如果编译成功,命令窗口中会显示信息,编译器会将编译结果填充到工作库中。

2_vcom_success.png

Develop MATLAB Function 开发 MATLAB 函数

The HDL Verifier software verifies HDL hardware in MATLAB using MALAB test bench functions. You need to create or edit the MATLAB test bench function that meets the HDL Verifier requirements. For this tutorial, you do not need to develop the MATLAB test bench function yourself. Instead, open and examine the existing file modsimrand_plot.m.
HDL Verifier 软件使用 MALAB 测试台函数在 MATLAB 中验证 HDL 硬件。您需要创建或编辑符合 HDL Verifier 要求的 MATLAB 测试台函数。在本教程中,您无需自己开发 MATLAB 测试台函数。相反,请打开并检查现有文件 modsimrand_plot.m

If you choose not to examine the MATLAB function at this time, skip to Load Simulation.
如果您选择此时不检查 MATLAB 函数,请跳至加载模拟。

Note: modsimrand_plot.m is a lower-level component of the MATLAB Random Number Generator example. Plotting code within modsimrand_plot.m is not discussed in the next section. This tutorial focuses only on those parts of modsimrand_plot.m that are required for MATLAB to verify a VHDL model.
注意: modsimrand_plot.m 是 MATLAB 随机数生成器示例的低级组件。下一节将不再讨论 modsimrand_plot.m 中的绘图代码。本教程仅关注 modsimrand_plot.m 中 MATLAB 验证 VHDL 模型所需的部分。

You can open modsimrand_plot.m in the MATLAB Editor by typing edit modsimrand_plot.m in the MATLAB Command Window.
在 MATLAB 命令窗口中键入 edit modsimrand_plot.m 可以在 MATLAB 编辑器中打开 modsimrand_plot.m

While you are viewing the file:
查看文件时:

1. On line 1, you will find the MATLAB function name specified along with its required parameters: function [iport,tnext] = modsimrand_plot(oport,tnow,portinfo)
1.在第 1 行,您将看到 MATLAB 函数名称及其所需的参数: function [iport,tnext] = modsimrand_plot(oport,tnow,portinfo)

This function definition is important because it represents the communication channel between MATLAB and QuestaSim. When you code the function:
该函数定义非常重要,因为它代表了 MATLAB 和 QuestaSim 之间的通信通道。在编写函数代码时

  • You must define the function with two output parameters, iport and tnext, and three input parameters, oport, tnow, and portinfo. See MATLAB Function Syntax and Function Argument Definitions.
    您必须为函数定义两个输出参数 iporttnext 以及三个输入参数 oporttnowportinfo 。请参见 MATLAB 函数语法和函数参数定义。

  • You can use the iport parameter to drive input signals instead of, or in addition to, using other signal sources, such as QuestaSim force commands. Depending on your application, you might use any combination of input sources. However, if multiple sources drive signals to a single iport, you will need a resolution function to handle signal contention.
    您可以使用 iport 参数来驱动输入信号,而不是使用其他信号源(如 QuestaSim force 命令)。根据您的应用,您可以使用任何输入源组合。但是,如果多个信号源将信号驱动至单个 iport ,则需要一个解析函数来处理信号争用问题。

2. On lines 21 and 22, you will find some parameter initialization:
2.在第 21 行和第 22 行,你会看到一些参数初始化:

tnext = [];

iport = struct();

In this case, function outputs iport and tnext are initialized to empty values.
在这种情况下,函数输出 iporttnext 被初始化为空值。

3. You need to know the types of the data that the MATLAB test bench function receives from and returns to QuestaSim and how HDL Verifier handles this data; see Supported Data Types. This function includes the following port data type definitions and conversions:
3.您需要了解 MATLAB 测试台函数从 QuestaSim 接收并返回的数据类型,以及 HDL Verifier 如何处理这些数据;请参阅支持的数据类型。该函数包括以下端口数据类型定义和转换:

  • The entity defined for this tutorial consists of three input ports of type STD_LOGIC and an output port of type STD_LOGIC_VECTOR.
    本教程定义的实体包括三个 STD_LOGIC 类型的输入端口和一个 STD_LOGIC_VECTOR 类型的输出端口。

  • Data of type STD_LOGIC_VECTOR consists of a column vector of characters with one bit per character.
    STD_LOGIC_VECTOR 类型的数据由字符列向量组成,每个字符一个比特。

  • The interface converts scalar data of type STD_LOGIC to a character that matches the character literal for the corresponding enumerated type.
    该接口可将 STD_LOGIC 类型的标量数据转换为与相应枚举类型的字符字面匹配的字符。

On line 61, the line of code containing oport.dout shows how the data that a MATLAB function receives from QuestaSim is converted for use in the MATLAB environment:
在第 61 行,包含 oport.dout 的代码行显示了 MATLAB 函数从 QuestaSim 收到的数据如何转换以便在 MATLAB 环境中使用:

ud.buffer(cyc) = mvl2dec(oport.dout)

In this case, the function receives STD_LOGIC_VECTOR data on oport. The function mvl2dec converts the bit vector to a decimal value that can be used in arithmetic computations. Supported Data Types provides a summary of the types of data conversions to consider when coding your own MATLAB functions.
在这种情况下,函数在 oport 上接收 STD_LOGIC_VECTOR 数据。函数 mvl2dec 将位向量转换为可用于算术计算的十进制值。支持的数据类型概述了在编码自己的 MATLAB 函数时需要考虑的数据转换类型。

4. Browse through the rest of modsimrand_plot.m. When you are finished, go to Load Simulation.
4.浏览 modsimrand_plot.m 的其余部分。完成后,转到加载模拟。

Load Simulation 负载模拟

After you compile the VHDL source file, you are ready to load the model for simulation. This section explains how to load an instance of entity modsimrand for simulation:
编译 VHDL 源文件后,就可以加载模型进行仿真了。本节将介绍如何加载实体 modsimrand 的实例进行仿真:

1. Load the instance of modsimrand for verification. To load the instance, specify the vsimmatlab command:
1.加载 modsimrand 实例进行验证。要加载实例,请指定 vsimmatlab 命令:

QuestaSim> vsimmatlab modsimrand

The vsimmatlab command starts the QuestaSim simulator, vsim, specifically for use with MATLAB. QuestaSim displays a series of messages in the Command Window as it loads the entity's packages and architecture.
vsimmatlab 命令启动专门用于 MATLAB 的 QuestaSim 仿真器 vsim 。QuestaSim 在加载实体的软件包和结构时,会在命令窗口中显示一系列信息。

3_vsimmatlab_start.png

2. Initialize the simulator to verify modsimrand with MATLAB. You initialize QuestaSim by using the matlabtb command. This command defines the communication link and a callback to a MATLAB function that executes in MATLAB on behalf of QuestaSim. In addition, the matlabtb command can specify parameters that control when the MATLAB function executes.
2.初始化模拟器,用 MATLAB 验证 modsimrand 。使用 matlabtb 命令初始化 QuestaSim。该命令定义了通信链路以及代表 QuestaSim 在 MATLAB 中执行的 MATLAB 函数的回调。此外, matlabtb 命令还可以指定控制 MATLAB 函数执行时间的参数。

For this tutorial, enter the following matlabtb command in QuestaSim:
在本教程中,请在 QuestaSim 中输入以下 matlabtb 命令:

> matlabtb modsimrand -mfunc modsimrand_plot -rising /modsimrand/clk -socket portnum

Arguments in the command line specify the following conditions:
命令行参数指定以下条件:

  • modsimrand — Specifies the VHDL module to cosimulate.
    modsimrand - 指定要模拟的 VHDL 模块。

  • -mfunc modsimrand_plot — Links an instance of the entity modsimrand to the MATLAB function modsimrand_plot.m. The argument is required because the entity name is not the same as the test bench function name.
    -mfunc modsimrand_plot - 将实体 modsimrand 的实例链接到 MATLAB 函数 modsimrand_plot.m 。该参数是必需的,因为实体名称与测试台函数名称不同。

  • -rising /modsimrand/clk — Specifies that the test bench function be called whenever signal /modsimrand/clk experiences a rising edge.
    -rising /modsimrand/clk - 指定在信号 /modsimrand/clk 出现上升沿时调用测试台函数。

  • -socket portnum — Specifies the port number portnum returned by the call to hdldaemon in Start the MATLAB Server.
    -socket portnum - 指定启动 MATLAB 服务器中调用 hdldaemon 返回的端口号 portnum

3. Initialize clock and reset input signals. You can drive simulation input signals using several mechanisms, such as the QuestaSim force commands and an iport parameter (see Syntax of a Test Bench Function). For now, enter the following force commands:
3.初始化时钟和复位输入信号。您可以使用 QuestaSim force 命令和 iport 参数等多种机制驱动仿真输入信号(请参阅测试平台函数语法)。现在,请输入以下 force 命令:

> force /modsimrand/clk 0 0 ns, 1 5 ns -repeat 10 ns

> force /modsimrand/clk_en 1

> force /modsimrand/reset 1 0, 0 50 ns

The first command forces the clk signal to value 0 at 0 nanoseconds and to 1 at 5 nanoseconds. After 10 nanoseconds, the cycle starts to repeat every 10 nanoseconds. The second and third force commands set clk_en to 1 and reset to 1 at 0 nanoseconds and to 0 at 50 nanoseconds.
第一条命令强制 clk 信号在 0 纳秒时为 0,在 5 纳秒时为 1。10 纳秒后,循环开始每 10 纳秒重复一次。第二和第三条 force 命令将 clk_en 设置为 1,将 reset 设置为 0 纳秒时为 1,50 纳秒时为 0。

The QuestaSim environment is ready to run a simulation. Now, you need to set up the MATLAB function.
QuestaSim 环境已准备好运行仿真。现在,您需要设置 MATLAB 函数。

Run Simulation 运行模拟

This section explains how to start, monitor, and rerun the simulation.
本节介绍如何启动、监控和重新运行模拟。

Run the Simulation for the First Time
首次运行模拟

Before running the simulation for the first time, you must verify the client connection. You may also want to set breakpoints for debugging.
首次运行模拟之前,必须验证客户端连接。您可能还需要设置用于调试的断点。

Perform the following steps:
执行以下步骤:

1. Open QuestaSim and MATLAB windows.
1.打开 QuestaSim 和 MATLAB 窗口。

2. In MATLAB, verify the client connection by calling hdldaemon with the 'status' option: hdldaemon('status'). This function returns a message indicating a connection exists:
2.在 MATLAB 中,使用 'status' 选项调用 hdldaemon 验证客户端连接: hdldaemon('status') 。该函数会返回一条信息,表明存在连接:

HDLDaemon socket server is running on port 4795 with 1 connection

Or

HDLDaemon shared memory server is running with 1 connection

Note: If you attempt to run the simulation before starting the hdldaemon in MATLAB, you will receive the following warning:
注意:如果在 MATLAB 中启动 hdldaemon 之前尝试运行模拟,将会收到以下警告:

#ML Warn - MATLAB server not available (yet),

The entity 'modsimrand' will not be active

3. Open modsimrand_plot.m in the MATLAB Editor.
3.在 MATLAB 编辑器中打开 modsimrand_plot.m .

4. Search for oport.dout and set a breakpoint at that line by clicking next to the line number. A red breakpoint marker will appear.
4.搜索 oport.dout 行,点击该行行号旁边的位置,在该行设置断点。这时会出现一个红色的断点标记。

5. Return to QuestaSim and enter the following command:
5.返回 QuestaSim 并输入以下命令:

> run 80000

This command instructs QuestaSim to advance the simulation 80,000 time steps (80,000 nanoseconds using the default time step period). Because you previously set a breakpoint in modsimrand_plot.m, the simulation runs in MATLAB until it reaches the breakpoint.
该命令指示 QuestaSim 将仿真提前 80,000 个时间步(使用默认时间步周期为 80,000 纳秒)。由于您之前在 modsimrand_plot.m 中设置了断点,因此仿真将在 MATLAB 中运行,直至到达断点。

QuestaSim is now blocked and remains blocked until you explicitly unblock it. While the simulation is blocked, note that MATLAB displays the data that QuestaSim passed to the MATLAB function in the Workspace window.
QuestaSim 现在处于阻塞状态,并一直保持阻塞状态,直到您明确解除阻塞。当仿真被阻塞时,请注意 MATLAB 会在工作区窗口中显示 QuestaSim 传递给 MATLAB 函数的数据。

In MATLAB, an empty figure window opens. You can use this window to plot data generated by the simulation.
在 MATLAB 中,会打开一个空图表窗口。您可以使用该窗口绘制模拟生成的数据。

6. Examine oport, portinfo, and tnow by hovering over these arguments inside the MATLAB Workspace window. Observe that tnow, the current simulation time, is set to 0. Also notice that you can see the portinfo argument in the MATLAB workspace because the simulation has reached a breakpoint during the first call to modsimrand_plot.
6.将鼠标悬停在 MATLAB 工作区窗口内的 oportportinfotnow 参数上,查看这些参数。注意当前模拟时间 tnow 已设置为 0 。此外,您还可以在 MATLAB 工作区中看到 portinfo 参数,因为在第一次调用 modsimrand_plot 时,仿真已达到一个断点。

7. Click Continue in the MATLAB Editor. The next time the breakpoint is reached, notice that portinfo no longer appears in the MATLAB workspace. The portinfo function does not show because it is passed in only on the first function call. Also note that the value of tnow advances from 0 to 5e-09.
7.单击 MATLAB 编辑器中的继续。下一次到达断点时,请注意 portinfo 不再出现在 MATLAB 工作区中。 portinfo 函数没有显示,因为它只在第一次函数调用时传入。另外请注意, tnow 的值从 0 变为 5e-09。

8. Clear the breakpoint by clicking the red breakpoint marker.
8.点击红色断点标记,清除断点。

9. Unblock QuestaSim and continue the simulation by clicking Continue in the MATLAB Editor. The simulation runs to completion. As the simulation progresses, it plots generated data in the figure window. When the simulation completes, the figure window appears as shown below.
9.在 MATLAB 编辑器中单击 "继续",解锁 QuestaSim 并继续仿真。仿真运行完成。随着仿真的进行,会在图形窗口中绘制生成的数据。仿真完成后,图形窗口如下所示。

4_simulation_figure.png

Rerun the Simulation 重新运行模拟

If you want to run the simulation again, you must restart the simulation in QuestaSim, reinitialize the clock, and reset input signals. To do so:
如果要再次运行仿真,必须在 QuestaSim 中重新启动仿真,重新初始化时钟并重置输入信号。具体操作如下

1. Close the figure window.
1.关闭图形窗口。

2. Restart the simulation in QuestaSim with the following command:
2.使用以下命令在 QuestaSim 中重新启动模拟:

> restart

The Restart dialog box appears. Leave all the options enabled, and click Restart.
此时会出现 "重新启动 "对话框。保留所有选项的启用状态,然后单击 "重新启动"。

Note: The Restart button clears the simulation context established by a matlabtb command. Therefore after restarting QuestaSim, you must reissue the previous command or issue a new command.
注意: 重新启动按钮将清除由 matlabtb 命令建立的仿真上下文。因此,重启 QuestaSim 后,您必须重新发布之前的命令或发布新命令。

3. Reissue the matlabtb command in QuestaSim:
3.在 QuestaSim 中重新发出 matlabtb 命令:

> matlabtb modsimrand -mfunc modsimrand_plot -rising /modsimrand/clk -socket portnum

4. Open modsimrand_plot.m in the MATLAB Editor.
4.在 MATLAB 编辑器中打开 modsimrand_plot.m .

5. Set a breakpoint at the same line as in the previous run.
5.在上一次运行的同一行设置断点。

6. Return to QuestaSim and re-enter the following commands to reinitialize clock and input signals:
6.返回 QuestaSim 并重新输入以下命令以重新初始化时钟和输入信号:

> force /modsimrand/clk 0 0,1 5 ns -repeat 10 ns

> force /modsimrand/clk_en 1

> force /modsimrand/reset 1 0, 0 50 ns

7. Enter a command to start the simulation, for example:
7.输入启动模拟的命令,例如

> run 80000

Shut Down Simulation 关闭模拟

To shut down a simulation in an orderly way:
有序关闭模拟:

In QuestaSim: 在 QuestaSim:

  1. Stop the simulation on the client side by selecting Simulate > End Simulation or entering the quit command.
    通过选择模拟 > 结束模拟或输入 quit 命令,在客户端停止模拟。

  2. Quit QuestaSim. 退出 QuestaSim。

In MATLAB, you can simply quit the application, which will shut down the simulation and also close MATLAB.
在 MATLAB 中,只需退出应用程序即可关闭模拟,同时关闭 MATLAB。

To shut down the server without closing MATLAB, you can call hdldaemon with the 'kill' option:
要在不关闭 MATLAB 的情况下关闭服务器,可以使用 'kill' 选项调用 hdldaemon

hdldaemon('kill')

The following message appears, confirming that the server is shut down:
出现以下信息,确认服务器已关闭:

HDLDaemon server was shutdown

See Also 另请参见

Related Topics 相关主题