Hi Folks
In the last write-up, I mentioned threads in simulation. Specifically, I said that the threads of a simulation can interact with each other. Well, what does that mean? Consider the Verilog code-snippet below –
assign y = a + b; // continuous assignment
initial begin // initial block
$monitor(“@time %t -> a=%d, b=%d, y=%d”, $time,a,b,y);
a = 0; b = 0;
#10
a = 5;
#10
b = -5;
#10
$finish;
end
It produces this output:
@time 0 -> a= 0, b= 0, y= 0
@time 10 -> a= 5, b= 0, y= 5
@time 20 -> a= 5, b= -5, y= 0
Let’s explain this in a moment.
For the sake of convenience, let’s call the ‘continuous assignment statement’ in the code snippet as T1. Let’s call the ‘initial block’ in the code snippet as T2.
What we did in T2 is — we changed the value of variables ‘a’ and ‘b’ randomly over a period of time.
When the values of ‘a’ and ‘b’ changed, T1 triggered? Why is that?
The reason is –
Variables ‘a’ and ‘b’ are on the RHS of T1 expression. That is, ‘a’ and ‘b’ are in the sensitivity list of T1
Technically, a value change in ‘a’ or ‘b’ is known as an ‘event on a’ or ‘event on b’ respectively
According to the rules of Verilog, whenever an event occurs on the sensitivity list of a continuous assignment statement, the expression in the continuous assignment has to be evaluated and the newly computed value of the RHS has to be assigned to the LHS
As per T2, we are causing events on a or b at times 0, 10 and 20. Hence, new values of ‘a+b’ (and hence y) are printed at times 0, 10 and 20.
So, an action on T2 is causing T1 to execute.
Now, does it give an idea on how T1 and T2 can interact? The rest is your creativity as you try to write complex models.
Happy coding, Folks!
Tech Pubs,
ProxeleraPost navigation