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?

asked Dec 19, 2019 at 17:05
\$\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.

Dave Tweed
184k17 gold badges248 silver badges431 bronze badges
answered Dec 19, 2019 at 17:37
\$\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\$ Commented Apr 10, 2021 at 14:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.