The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Mar 28th, 2024, 11:16pm
Pages: 1
Send Topic Print
Blocking assignment working as a non-blocking.... (Read 5504 times)
paul miller
New Member
*
Offline



Posts: 4

Blocking assignment working as a non-blocking....
Oct 07th, 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.
Back to top
 
 
View Profile   IP Logged
boe
Community Fellow
*****
Offline



Posts: 615

Re: Blocking assignment working as a non-blocking....
Reply #1 - 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
Back to top
 
 
View Profile   IP Logged
paul miller
New Member
*
Offline



Posts: 4

Re: Blocking assignment working as a non-blocking....
Reply #2 - 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)

?
Back to top
 
 
View Profile   IP Logged
boe
Community Fellow
*****
Offline



Posts: 615

Re: Blocking assignment working as a non-blocking....
Reply #3 - 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
Back to top
 
 
View Profile   IP Logged
boe
Community Fellow
*****
Offline



Posts: 615

Re: Blocking assignment working as a non-blocking....
Reply #4 - 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
Back to top
 
 
View Profile   IP Logged
paul miller
New Member
*
Offline



Posts: 4

Re: Blocking assignment working as a non-blocking....
Reply #5 - Oct 8th, 2014, 6:16am
 
repeated assignments ("=") are not syncing events?

Thank you for your rapid replies.

Back to top
 
 
View Profile   IP Logged
paul miller
New Member
*
Offline



Posts: 4

Re: Blocking assignment working as a non-blocking....
Reply #6 - 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?
Back to top
 
 
View Profile   IP Logged
boe
Community Fellow
*****
Offline



Posts: 615

Re: Blocking assignment working as a non-blocking....
Reply #7 - 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
Back to top
 
 
View Profile   IP Logged
Pages: 1
Send Topic Print
Copyright 2002-2024 Designer’s Guide Consulting, Inc. Designer’s Guide® is a registered trademark of Designer’s Guide Consulting, Inc. All rights reserved. Send comments or questions to editor@designers-guide.org. Consider submitting a paper or model.