# Verilog blocking/nonblocking assignment in clk generator with self triggered

**URL:** <https://verificationacademy.com/forums/t/verilog-blocking-nonblocking-assignment-in-clk-generator-with-self-triggered/29734>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, verilog-blocking-assignments\
**Created:** [July 23, 2014, 8:02am UTC](https://verificationacademy.com/forums/t/verilog-blocking-nonblocking-assignment-in-clk-generator-with-self-triggered/29734 "2014-07-23T08:02:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![N\_Raghava](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@N\_Raghava](https://verificationacademy.com/forums/u/N_Raghava)\
**Post date:** [July 23, 2014, 8:02am UTC](https://verificationacademy.com/forums/t/verilog-blocking-nonblocking-assignment-in-clk-generator-with-self-triggered/29734/1 "2014-07-23T08:02:58Z")

</div>

Why the following code is not self-triggered?

module osc1 (clk);  
output clk;  
reg clk;  
initial #10 clk = 0;  
always @(clk) #10 clk = ~clk;

always  
begin  
$monitor(“%0d clk=%0d\n”,$time,clk);  
#100 $finish;  
end  
endmodule  
output:

# 0 clk=x

# 10 clk=0

# 20 clk=1

when used non-blocking assignment it works normally i.e., always @(clk) #10 clk \<= ~clk;

output:

# 0 clk=x

# 10 clk=0

# 20 clk=1

# 30 clk=0

# 40 clk=1

# 50 clk=0

# 60 clk=1

# 70 clk=0

# 80 clk=1

# 90 clk=0

thanks in advance.

---

<div class="post-metadata">

**Author:** ![haitao73](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/haitao73/32/2385_2.png) [@haitao73](https://verificationacademy.com/forums/u/haitao73)\
**Post date:** [July 23, 2014, 8:47am UTC](https://verificationacademy.com/forums/t/verilog-blocking-nonblocking-assignment-in-clk-generator-with-self-triggered/29734/2 "2014-07-23T08:47:35Z")

</div>

hi,  
@clk and #10 clk = ~clk is blocking assignment, the two statement are scheduled at Active region,  
but @clk and #10 clk \<= ~clk, the first statement is scheduled at Active region and the sencond is scheduled at NBA region, when clk \<= ~clk hanpen, the toggle of clk will reactive the @clk hanppen, and periodic trigger the non-blocking statement.

the generally writing style like below:

always #10 clk = ~clk; or  
always #10 clk \<= ~clk;

ps:no @clk condition

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![suneeldvsk](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/e79b87/32.png) [@suneeldvsk](https://verificationacademy.com/forums/u/suneeldvsk)\
**Post date:** [July 23, 2014, 11:18am UTC](https://verificationacademy.com/forums/t/verilog-blocking-nonblocking-assignment-in-clk-generator-with-self-triggered/29734/3 "2014-07-23T11:18:18Z")

</div>

_In reply to [N Raghava](https://verificationacademy.com/forums/t/verilog-blocking-nonblocking-assignment-in-clk-generator-with-self-triggered/29734/2):_

In case of blocking, the compiler goes back to the start of the always block after successful execution of " #10 clk = ~clk;" and wait for the event which never occurs. Where as in case of non blocking, the compiler goes back to the start of always block before the assignment which is done in NBA region.
