在批处理模式下使用 Force - 2023.2 简体中文

Vivado Design Suite 用户指南: 逻辑仿真 (UG900)

Document ID
UG900
Release Date
2023-10-18
Version
2023.2 简体中文

以下代码示例显示了如何使用 add_force 命令将信号强制设为指定值。其中提供了简单的 Verilog 电路。第一个示例显示了 add_force 命令的交互用法,第二个示例显示了脚本用法。

示例 1:添加 Force

以下代码片段是 Verilog 电路:

module bot(input in1, in2,output out1);
reg sel;
assign out1 = sel? in1: in2;
endmodule
module top;
reg in1, in2;
wire out1;
bot I1(in1, in2, out1);
initial
begin
    #10 in1 = 1'b1; in2 = 1'b0;
    #10 in1 = 1'b0; in2 = 1'b1;
end
initial
    $monitor("out1 = %b\n", out1);
endmodule

您可以调用以下命令来观察 add_force 的效果:

xelab -vlog tmp.v -debug all
xsim work.top

在命令提示符处输入:

add_force /top/I1/sel 1
run 10
add_force /top/I1/sel 0
run all

您可使用 add_force Tcl 命令来将信号、连线或寄存器强制设为指定值:

add_force [-radix <arg>] [-repeat_every <arg>] [-cancel_after <arg>] [-quiet] 
[-verbose] <hdl_object> <values>...

如需了解有关此命令及其他 Tcl 命令的更多信息,请参阅 Vivado Design Suite Tcl 命令参考指南(UG835)

示例 2:add_force 搭配 remove_forces 的脚本用法

以下 Verilog 文件示例 top.v 用于例化计数器。您可在以下命令示例中使用此文件。

module counter(input clk,reset,updown,output [4:0] out1);
reg [4:0] r1;
always@(posedge clk)
begin
    if(reset)
        r1 <= 0;
    else
        if(updown)
            r1 <= r1 + 1;
        else
            r1 <= r1 - 1;
end
assign out1 = r1;
endmodule
module top;
reg clk;
reg reset;
reg updown;
wire [4:0] out1;
counter I1(clk, reset, updown, out1);
initial
begin
    reset = 1;
    #20 reset = 0;
end
initial
begin
    updown = 1; clk = 0;
end
initial
    #500 $finish;
initial
    $monitor("out1 = %b\n", out1);
endmodule

命令示例

  1. 使用以下命令创建名为 add_force.tcl 的文件:
    create_project add_force -force
    add_files top.v
    set_property top top [get_filesets sim_1]
    set_property -name xelab.more_options -value {-debug all} -objects [get_filesets 
    sim_1]
    set_property runtime {0} [get_filesets sim_1]
    launch_simulation -simset sim_1 -mode behavioral
    add_wave /top/*
  2. 以 Tcl 模式调用 Vivado Design Suite 并使用 source 命令找到 add_force.tcl 文件。
  3. 在 Tcl 控制台中,输入:
    set force1 [add_force clk {0 1} {1 2} -repeat_every 3 -cancel_after 500]
    set force2 [add_force updown {0 10} {1 20} -repeat_every 30]
    run 100

    在“Wave”(波形)窗口中可以观察到 out1 值的递增和递减。您可在 Vivado IDE 中使用 start_gui 命令观察波形。

    在“Wave”窗口中观察 updown 信号的值。

  4. 在 Tcl 控制台中,输入:
    remove_forces $force2
    run 100

    观察可见,仅有 out1 的值发生递增。

  5. 在 Tcl 控制台中,输入:
    remove_forces $force1
    run 100

    观察可见,out1 的值并未更改,因为 clk 信号并未切换。