Below is my code where iam trying to print the variable value of class using $monitor() function. Here it prints only one value at end of simulation.But As per LRM It is quoted as “When a $monitor task is invoked with one or more arguments, the simulator sets up a mechanism whereby each time a variable or an expression in the argument list changes value—with the exception of the $time”
Please clarify if there is any limitation when we use class variables inside $monitor.
class self;
rand bit [2:0] a;
randc bit [1:0] b;
endclass
module test;
self s1;
initial begin
repeat(10)
s1=new;
s1.randomize();
end
initial begin
$monitor(“Monitor Value of b is =%d”, s1.b);
end
initial begin
#400
$finish;
end
endmodule
$monitor will print the value only at the end of the time step. If there are multiple changes to same variable in a single timestep(same as your case) then only 1 value(which is last) will be printed.
Put a $display inside the repeat block.
In reply to Naven8:
I tried with $display. It is working. But if i give some delay in repeat block like below, then the all the random values should be printed. But the output is same.
Can i know the reason? How can i print all the random values using $monitor in my scenario?
In this case how a time stamp can be defined?
initial begin
repeat(10)
#10;
s1=new;
s1.randomize();
end
In reply to muralidar:
I think you should go through section “4. Scheduling semantics” in LRM. This will clarify all your doubts.
In reply to Naven8:
First of all vcs is not allowing me to monitor dynamic variables. Which tool you are using? (I am not sure how monitor will behave when object is not created.)
In your first attempt you are creating object multiple times but randomizing only once.
// begin-end is missing after repeat
repeat(10)
s1=new;
s1.randomize();
2nd time also the same thing happening(missing begin-end).
repeat(10)
#10;
s1=new;
s1.randomize();
end
In reply to Naven8:
I would never use $monitor. You are only allowed one active $monitor in your entire simulation. $monitor was used as an interactive debugging aid for Verilog-XL, which used Verilog as its tool command language.
As Naven8 write, there is also a problem if you try to reference a null class variable at time 0, you will get a fatal error.
If you really want to see the result of a class object after calling randomize(), then create a post_randomize() method in the class to display the results.
In reply to dave_59:
Thanks Naven8 for your replay. I am using questasim to compile the code. Begin end is there in my code.