Lets consider the following code, I want to make the b x for #2 whenever a changes
module test();
reg [3:0] a;
initial
begin
$vcdpluson();
a <=0;
#5
a <= 1;
#5
a <= 2;
#1
a <= 3;
#4
a <= 5;
end
reg [3:0] b;
always @(a)
begin
b = 3'bx;
b = #2 a;
end
endmodule
I am getting the following waveform from simulation
When a changes from 1->2 and 2->3, I expect the always block to get triggered(since the sensitivity list has only a). after #2 from 2->3 transition b should have become 3. But looks like after #1 b has become 3, it means the always @(a) loop didn't get triggered for the 2->3 transition of a. How to enable that ?
-
\$\begingroup\$ You have to post complete waveform with signal names, not a part of it. \$\endgroup\$Mitu Raj– Mitu Raj2021年05月07日 12:38:21 +00:00Commented May 7, 2021 at 12:38
1 Answer 1
Your problem is you are using blocking assignments to write to b
. That means your always @a
procedure gets blocked for 2 time units before its able to see the next change on a
.
By using a non-blocking assignment, the assignment gets queued, and the always procedure immediately goes back to the top waiting for the next change on a
always @(*)
begin
b <= 3'bx;
b <= #2 a;
end
-
\$\begingroup\$ even if you use non blocking statement it wont work \$\endgroup\$arun– arun2021年05月11日 05:44:43 +00:00Commented May 11, 2021 at 5:44
-
\$\begingroup\$ What's the meaning of 'won't work'? , are the waveforms exactly the same? You haven't edited your question to include more details on waveforms after and before changes made to the code.@arun \$\endgroup\$Mitu Raj– Mitu Raj2021年05月11日 07:25:25 +00:00Commented May 11, 2021 at 7:25