In this blog we are going to see different types of clock generation.
Method 1:
By using always method we can generate clk. Always block is executed in the active event region and program block is executed in reactive event region. Always block runs forever eventhough the program block ends. So always block is not suitable for program block. By using forever the same behavior can be achieved in program block.
module TB;
bit clk=0;
always #5ns clk=~clk;
initial begin
#10000ns $finish;
end
endmodule
(or)
module TB;
bit clk=0;
always begin
#5ns clk=0;
#5ns clk=1;
end
initial begin
#10000ns $finish;
end
endmodule
Method 2:
By using forever loop we can generate clk.
module TB;
bit clk=0;
initial begin
forever #5ns clk=~clk;
end
initial begin
#10000ns $finish;
end
endmodule
Method 3:
By using for-loop we can generate clk pulses
module TB;
bit clk=0;
initial begin
for( bit i=0;i<=1;i++) begin //Here for loop runs forever. This is the tricks here
#5ns clk=~clk;
end
initial begin
#10000ns $finish;
end
endmodule
Method 4:
By using while loop
module TB;
bit clk=0;
initial begin
while(1) begin
#5ns clk=~clk;
end
end
initial begin
#10000ns $finish;
end
endmodule
Method 5:
By using do while loop
module TB;
bit clk=0;
initial begin
do begin
#5ns clk=~clk;
end while(1)
end
initial begin
#10000ns $finish;
end
endmodule
Note:
for active region always loop and for reactive region forever loop is better solution for clk generation in TB.
Hope this section will be useful to everyone !!!
Giving feedback is more precious than writing an article!!! 😊😊😊😊😊
Always welcome both positive and negative feedback's !!!
Feel free to post any queries related SV and UVM
"Share your knowledge. It is the way to achieve immortality"
-Dalai Lama
"Boss See who done the mistakes, Leaders see what is the mistake"
Choose your own way !!!!
Good examples with explanation.Thanks for sharing.
ReplyDeleteGood work!! Keep Going.
ReplyDeleteThanks for the feedback!!!!
ReplyDelete