Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Doubt in blocking and non blocking

Status
Not open for further replies.

marihari

Newbie level 5
Newbie level 5
Joined
Jan 6, 2013
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,335
I am new to the system verilog. Blocking statements can be used for combinational circuits and non blocking statements can be used for sequential circuits. But i don't know the reason behind using the use blocking and non blocking. Please help me.
 

If you understand operation of sequential and combinational circuits, explanation of blocking and non-blocking is self-explanatory. In sequential circuits, we just want outputs of many memory elements(flops, registers) to be updated simultaneously on valid clk edge, so non-blocking assignments are required.

In combinational circuits, assignments have dependency on previous assignments. So next instruction executes after current one and execution takes place in same way as control passes in high level languages such as C/C++.
 

If you understand operation of sequential and combinational circuits, explanation of blocking and non-blocking is self-explanatory. In sequential circuits, we just want outputs of many memory elements(flops, registers) to be updated simultaneously on valid clk edge, so non-blocking assignments are required.

In combinational circuits, assignments have dependency on previous assignments. So next instruction executes after current one and execution takes place in same way as control passes in high level languages such as C/C++.

Thanks for your valuable reply
 

I intentionally try to avoid using the blocking expression"=".
actually the "<=" could do all your work, both combinational and sequential circuits.

sequential
always@(posedge clk)
begin
a<=b;
end


combination
always@(b)
begin
a<=b;
end
 

I intentionally try to avoid using the blocking expression"=".
actually the "<=" could do all your work, both combinational and sequential circuits.

Hi Naught,
what if there is a combinational logic using a as input. suppose there is another logic to be defined as c=a AND b;
than you will end up in unnecessary always blocks with race conditions on c, leading to momentarily corrupt values in c(spikes). Another important thing i want to mention here the way execution take place of always. If constraints are same, execution take place randomly. So it's highly recommended practice to design combinational logic using blocking assignments.
Do you synthesize the logic you design in this manner?
 

I checked the verilog syntax book, sorry I confused VHDL with verilog. Your way is better.

could you please explain a little more about "If constraints are same, execution take place randomly."?
 

could you please explain a little more about "If constraints are same, execution take place randomly."?

Suppose there are 2 or more always with similar conditions(same time edges) :
always @(posedge clk or posedge rst)
if (rst) y1 = 0; // reset
else y1 = y2;

always @(posedge clk or posedge rst)
if (rst) y2 = 1; // preset
else y2 = y1;

Then order of execution of these always blocks is unknown. Suppose after reset, first always executes first, both y1, y2 will take value 1 and if second always executes first after reset, both y1, y2 will take value 0, leading to race condition.
 
  • Like
Reactions: naught

    naught

    Points: 2
    Helpful Answer Positive Rating
good example. Thanks.

and obviously one shall avoid designing a logic in this way.
 

But still people does mix both blocking and non-blocking statements.

as
always@(posedge(clk))
begin
temp_var=a&b;
if(condition)
temp_reg<=temp_var;
end

For simulation and synthesis how does it differ?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top