【问题标题】:Why does the force statement get stuck? And how to force a single bit in an array of bits?为什么 force 语句会卡住?以及如何强制位数组中的一个位?
【发布时间】:2023-02-25 20:55:13
【问题描述】:
module dut_top;
    wire [31:0] ctrl_32bit;
    wire        ctrl_1bit;
    assign ctrl_32bit = 0;
    assign ctrl_1bit=0;
    
    initial begin #1000ns; end
endmodule

program automatic test;
    initial begin
        repeat(5) begin
            #100ns;
            force dut_top.ctrl_32bit[0] =~ dut_top.ctrl_32bit[0]; //LINE 1
            force dut_top.ctrl_1bit     =~ dut_top.ctrl_1bit;     //LINE 2
            force dut_top.ctrl_32bit[0] =  dut_top.ctrl_1bit;     //LINE 3
        end
    end
endprogram

我的代码如上所示。 LINE 1 卡住了。但是在注释掉 LINE 1 之后,LINE 2 和 LINE 3 工作正常。

  1. 这是什么原因?我觉得是和timeslot有关,但是我自己也说不清楚。
  2. 这个需求应该怎么解决?

    我想每隔一段时间在一个位数组中强制一个位。

【问题讨论】:

    标签: verilog system-verilog test-bench


    【解决方案1】:

    您的代码在一个模拟器(Cadence)上对我来说运行良好,但它的行为方式与您在另一个模拟器(Synopsys VCS)上描述的方式相同。

    VCS 向我展示了这条消息:

    No TimeScale specified
    
    Warning-[DRTZ] Detect delay value roundoff to 0
      Delay from design or SDF file roundoff to 0 based on timescale
      Please use switch -diag timescale to dump detailed information.
    

    这让我想知道正在使用什么时间尺度,所以我将 $printtimescale 任务添加到每个模块。 Cadence 默认使用 1ns 作为时间单位和精度,而 VCS 使用 1s。对于 VCS,由于您的延迟(1000ns 和 100ns)小于默认精度(1s),因此延迟设置为 0。

    由于 IEEE Std 1800-2017 未指定默认时间刻度,因此您必须明确设置它。一种方法是使用 `timescale 编译器指令,如下所示(请参阅 IEEE Std 1800-2017,第 22.7 节`时间尺度):

    `timescale 1ns/1ns
    
    module dut_top;
        wire [31:0] ctrl_32bit;
        wire        ctrl_1bit;
        assign ctrl_32bit = 0;
        assign ctrl_1bit  = 0;
        
        initial $printtimescale;
        initial begin #1000ns; end
    endmodule
    
    program automatic test;
        initial begin
            $printtimescale;
            $monitor($time,, dut_top.ctrl_1bit,, dut_top.ctrl_32bit[0]);
            repeat(5) begin
                #100ns;
                force dut_top.ctrl_32bit[0] = ~dut_top.ctrl_32bit[0]; //LINE 1
                force dut_top.ctrl_1bit     = ~dut_top.ctrl_1bit;     //LINE 2
                force dut_top.ctrl_32bit[0] =  dut_top.ctrl_1bit;     //LINE 3
            end
        end
    endprogram
    

    这是我runnable on EDA playground 的 VCS 输出:

    TimeScale of dut_top is 1 ns / 1 ns 
    TimeScale of test is 1 ns / 1 ns 
                       0 0 0
                     100 1 1
                     200 0 0
                     300 1 1
                     400 0 0
                     500 1 1
    $finish at simulation time                  500
    

    我添加了 $monitor 任务来显示输出。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-23
      • 1970-01-01
      • 1970-01-01
      • 2012-11-23
      • 2012-10-11
      • 1970-01-01
      • 2014-12-28
      • 2012-03-04
      相关资源
      最近更新 更多