0
\$\begingroup\$

I'm relatively new to SV. I'm building a testbench in which I want to monitor a signal and take some action if it value changes @ clock posedge. I’m looking for a compact way to this (I.e. not using a register).

logic [31:0] var_signal

Inizialmente
begin
  for(i=0; i<max_cles; i++) begin
      @(posedge clk_i);
      //check if var_signal changed and do something
  end
end

I searched the web and found threads on assertions but it is not what I want to do here. Any hints?

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

I want to monitor a signal and take some action if it value changes @ clock posedge.

I know you don't want to use a register but it can be test-bench register. You have to make a copy at the clock edge and compare it against the old value:

logic [31:0] new_var_signal
always @(posedge clk_i)
   new_var_signal <= var_signal;

assign signal_changed_at_clock_edge = (new_var_signal != var_signal) ? 1 : 0;

There is a caveat: if the signal can also become 'z' or 'x' you should use:

assign signal_changed_at_clock_edge = (new_var_signal !== var_signal) ? 1 : 0;

Note that you are in an ideal simulation environment and there is no such moment as @(posedge.. That moment is infinitely short.

In a real digital design the signal has to be stable around the clock edge. The time before the clock edge is called the setup time and the time after is called the hold time.

\$\endgroup\$
1
  • \$\begingroup\$ How do I detect if a two signals toggled in same verilog queuing window? i.e error if two signals toggled in active window or error if two signals toggled in nba window \$\endgroup\$
    – Jean
    Apr 10, 2021 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.