3

在我的工作台程序中,我有这样的东西(简化):

// bench.sv
program tb (input clk, ...);
  initial begin
    ...
    repeat (100) begin
      main_module_interface.write_index <= bench.write_index;
      // drive additional inputs
      ...

      @(clk);

      $display("%t : BENCH", $realtime);

在我的主模块中,我有一个生成循环来创建我的index_reg模块

// main_module.sv
generate
  for (genvar ix = 0; ix < 32; ix++) begin
    index_reg #(.WIDTH(32), .INDEX(ix)) r (
      .clk,
      .ind(writeIFC.write_index),
      ...
    );
  end
endgenerate

然后在我的index_reg模块中,我添加了以下调试代码:

// index_reg.sv
always @ (posedge clk) begin
  if (INDEX == 10) begin
    $display("I see the clock");
  end
end

我希望看到这个输出:

I see the clock
10 : BENCH
I see the clock
20 : BENCH
I see the clock
30 : BENCH
I see the clock
40 : BENCH
I see the clock
50 : BENCH
etc.

但有时,“我看到时钟”每隔一段时间才会出现一次。所以我看到

10 : BENCH
I see the clock
20 : BENCH
30 : BENCH
I see the clock
40 : BENCH
50 : BENCH
etc.

我不明白为什么会发生这种情况。有人可以指出我正确的方向吗?非常感谢。

4

1 回答 1

2

在没有看到更多代码的情况下,这是我最好的猜测。

@(clk);

该代码在每个clk边缘触发,包括posedgenegedge

always @ (posedge clk) begin

该代码仅在posedgeof上触发clk,即每隔一次触发一次。

这可能就是为什么你看到BENCH的频率是 的两倍I see the clock

如果这不能回答您的问题,请提供任何人都可以编译和运行的完整代码示例。

于 2011-10-11T12:38:24.630 回答