The Designer's Guide Community Forum
https://designers-guide.org/forum/YaBB.pl
Design Languages >> Verilog-AMS >> Blocking assignment working as a non-blocking....
https://designers-guide.org/forum/YaBB.pl?num=1412710731

Message started by paul miller on Oct 7th, 2014, 12:38pm

Title: Blocking assignment working as a non-blocking....
Post by paul miller on Oct 7th, 2014, 12:38pm

I am using a holding register to hold values in a testbench so that I do not have to remember them all myself (probably a good thing, I'm forgetful).

below is a code snippet from what I'm using

REG [4:0] USER_REG1_UI;
assign user_reg1_ui = {value4, value3, value2, value1, value0};

initial
begin
value4 =0;
value3 =0;
value2 =0;
value1 =0;
value0 =0;
end

initial begin
#(startup delays);

value4 = 1;
value2 = 1;
value1 = 1;


`WR(USER_REG1_UI, user_reg1_ui)

end

`WR is a defined task that writes my device with the address for the first argument and the value as the second argument.  

I would expect this to write
USER_REG1_UI with a 5'b10110;
what it is actually occuring is that it is writing a 5'b00000;

it correctly writes the 5'b10110 when I modify by adding a delay in after updating my control register. (see below)


REG [4:0] USER_REG1_UI;
assign user_reg1_ui = {value4, value3, value2, value1, value0};

initial
begin
value4 =0;
value3 =0;
value2 =0;
value1 =0;
value0 =0;
end

initial begin
#(startup delays);

value4 = 1;
value2 = 1;
value1 = 1;

#(1ps) <---- 1 ps delay.

`WR(USER_REG1_UI, user_reg1_ui)

end

Is this expected?  If so, how do I do this without needing the 1ps delay?  I would like to remove the delay because if I do this enough times, I end up losing a clock cycle.

Title: Re: Blocking assignment working as a non-blocking....
Post by boe on Oct 8th, 2014, 1:46am


paul miller wrote on Oct 7th, 2014, 12:38pm:
I am using a holding register to hold values in a testbench so that I do not have to remember them all myself (probably a good thing, I'm forgetful).
...
Is this expected?  If so, how do I do this without needing the 1ps delay?  I would like to remove the delay because if I do this enough times, I end up losing a clock cycle.
Yes, this is expected: the # ensures that the assign is executed before the WR Task.
To avoid this, you could e.g. throw an event and use a process triggering on that to start the WR Task.
- B O E

Title: Re: Blocking assignment working as a non-blocking....
Post by paul miller on Oct 8th, 2014, 5:16am

Shouldn't the assign be instantaneous?
And even if it isn't, shouldn't all but the last of the value updates occur before the write command? E.G.

value4 = 1
value3 = 1
value2 = 1

`WR(reg, holding value)

would see
`WR(reg, 10100) instead of `WR(reg, 10110)

?

Title: Re: Blocking assignment working as a non-blocking....
Post by boe on Oct 8th, 2014, 5:32am


paul miller wrote on Oct 8th, 2014, 5:16am:
Shouldn't the assign be instantaneous?
And even if it isn't, shouldn't all but the last of the value updates occur before the write command? E.G.

value4 = 1
value3 = 1
value2 = 1

`WR(reg, holding value)

would see
`WR(reg, 10100) instead of `WR(reg, 10110)

?
Paul, the assignment to value2, ... is instantaneous, yes. But the control needs to be transferred to the assign statement for the values to appear at user_reg1_ui. And unless the WR task does it (or the # delay or something else), you get the previous values.
- B O E

Title: Re: Blocking assignment working as a non-blocking....
Post by boe on Oct 8th, 2014, 5:36am

Paul,
more detailed reply:
the assign is a "block" that runs in parallel (virtually) to the init block. For efficiency reasons, control between the blocks is transferred on syncing events (e.g. # delays) only.
- B O E

Title: Re: Blocking assignment working as a non-blocking....
Post by paul miller on Oct 8th, 2014, 6:16am

repeated assignments ("=") are not syncing events?

Thank you for your rapid replies.


Title: Re: Blocking assignment working as a non-blocking....
Post by paul miller on Oct 8th, 2014, 6:22am

Also,

is there a way I can do a similar functionality without requiring that delay?  

E.G.  If I include the

assign USER_REG1 = {valueX, ...} inside the initial block will this remove the need for the #1p delay?

Title: Re: Blocking assignment working as a non-blocking....
Post by boe on Oct 13th, 2014, 3:33am


paul miller wrote on Oct 8th, 2014, 6:22am:
Also,

is there a way I can do a similar functionality without requiring that delay?  

E.G.  If I include the

assign USER_REG1 = {valueX, ...} inside the initial block will this remove the need for the #1p delay?
You cannot have assign statements in an initial block.
There a various solutions for this. You could e.g. create a WR_USER_REG1, which is defined as WR(USER_REG1_UI, {...}).
Using an event to trigger writing also ensures syncing.
- B O E

The Designer's Guide Community Forum » Powered by YaBB 2.2.2!
YaBB © 2000-2008. All Rights Reserved.