为什么 $display 在我期望的时候没有执行?

发布于 2024-12-09 13:02:11 字数 1169 浏览 1 评论 0原文

在我的基准程序中,我有这样的东西(简化的):

// 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);

在我的主模块中,我有一个 generate 循环来创建我的 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.

我无法理解为什么会发生这种情况。有人可以指出我正确的方向吗?

In my bench program, I have something like this (simplified):

// 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);

In my main module, I have a generate loop to create my index_reg modules

// 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

Then in my index_reg module, I have added the following debug code:

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

I would expect to see this output:

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.

But sometimes, the "I see the clock" only shows up every other time. So I see

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

I can't understand why that might happen. Can someone please point me in the right direction?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执手闯天涯 2024-12-16 13:02:11

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

@(clk);

该代码在每个 clk 边沿(包括 posegenegedge)上触发。

always @ (posedge clk) begin

该代码仅在 clkposege 上触发,每隔一段时间触发一次。

这可能就是为什么您看到BENCH的频率是我看到时钟的两倍。

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

Without seeing more of the code, here is my best guess.

@(clk);

That code is triggered on every clk edge, both posedge and negedge.

always @ (posedge clk) begin

That code is only triggered on posedge of clk, which is every other time.

That may be why you see BENCH twice as often as I see the clock.

If that doesn't answer your question, provide a complete code example that anyone can compile and run.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文