关于逻辑值变化的事件(Event on logic value change)

编程入门 行业动态 更新时间:2024-10-10 23:17:15
关于逻辑值变化的事件(Event on logic value change)

我通常使用@运算符来等待特定信号的任何逻辑值变化。 例如,等待信号a任何变化,我通常会这样做

wire a; //... @(a); // wait any value change 0->1 or 1->0, or x->1 etc

但是现在我意识到上面的代码并不总是按预期工作,特别是当我们引入信号强度时,如下面的代码所示:

module test; wire a; logic sweak1 = 0; logic spull1 = 0; assign (weak0,weak1) a = sweak1 ? 1'b1 : 1'bz; assign (pull0,pull1) a = spull1 ? 1'b1 : 1'bz; task wait_a_change(); @(a); endtask initial forever begin $display("Value: a = %b %v @%0t", a, a, $time); wait_a_change(); end initial begin sweak1 = 1; #10; spull1 = 1; #10; spull1 = 0; #10; spull1 = 1; #10; end endmodule

即使a的逻辑值没有改变,事件@(a)也会触发。 所以我的第一个解决方案就是:

task wait_a_change(); if (a) @(negedge a); else @(posedge a); endtask

该解决方案需要额外检查(也行)。 有没有更好的解决方案?

I usually use the @ operator to wait for any logical value change of a particular signal. For example to wait on any change in signal a, I usually do

wire a; //... @(a); // wait any value change 0->1 or 1->0, or x->1 etc

But now I realized that the above codes will not always work as expected especially when we introduce signal strength, as illustrated in following code:

module test; wire a; logic sweak1 = 0; logic spull1 = 0; assign (weak0,weak1) a = sweak1 ? 1'b1 : 1'bz; assign (pull0,pull1) a = spull1 ? 1'b1 : 1'bz; task wait_a_change(); @(a); endtask initial forever begin $display("Value: a = %b %v @%0t", a, a, $time); wait_a_change(); end initial begin sweak1 = 1; #10; spull1 = 1; #10; spull1 = 0; #10; spull1 = 1; #10; end endmodule

The event @(a) will trigger even if the logical value of a doesn't change. So my first solution to overcome this is by doing:

task wait_a_change(); if (a) @(negedge a); else @(posedge a); endtask

That solution requires additional check (and line too). Is there any better solution?

最满意答案

试试@(!a) 。 通过布尔表达式,它失去了力量。 你唯一松动的是x-> z过渡。 (你的解决方案也不会抓到它)。 如果你需要,你最好更好地解释你想要完成的事情,这可能是一个完全不同的方法。

Try @(!a). By putting it through a Boolean expression, it loses its strength. The only thing you loose is x->z transitions. (your solution would not catch that either). If you need that, you had better explain better what you are trying to accomplish, where might be an entirely different approach to take.

更多推荐

本文发布于:2023-07-27 03:58:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1284840.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:逻辑   事件   Event   logic   change

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!