0

Is there any difference between nonblocking and blocking assignment for the following counters?

module  nonblocking_counter (
  input clk,               
  input rstn,              
  output reg[3:0] out
);    

  always @ (posedge clk) begin
    if (! rstn)
      out <= 0;
    else 
      out <= out + 1;
  end
endmodule

module  blocking_counter (
    input clk,              
    input rstn,
    output reg[3:0] out              
);   

  always @ (posedge clk) begin
    if (! rstn)
      out = 0;
    else 
      out = out + 1;
  end
endmodule
delkov
  • 101
  • Possible duplicate of [Difference between blocking and nonblocking assignment Verilog](https://electronics.stackexchange.com/questions/91688/difference-between-blocking-and-nonblocking-assignment-verilog) – dave_59 Oct 15 '18 at 03:52
  • Actually, it is not. I understand the difference between them. I think in case of counter the behaviours are equal, am I right? – delkov Oct 15 '18 at 06:05

1 Answers1

1

The circuit generated by synthesis tools will be identical for this code. However in simulation, you have a race condition on the output that feeds the input of another synchronized process when using blocking assignments.

dave_59
  • 7,557
  • 1
  • 14
  • 26