Ready-to-run snippets

Code Examples

Ready-to-run Verilog, SystemVerilog, and UVM examples. Click any to open it live in the IDE.

← All examples

Interview Questions Set 7: How to generate two different clocks in testbench ?

Verilog Examples

Runnable example from the Verilog Interview Questions Set 7 tutorial (How to generate two different clocks in testbench ?)

Open in IDE
testbench.v
module tb;
  
  reg clk1;
  reg clk2;

  initial begin
    clk1 = 1'b0;
    forever #10 clk1 = ~clk1; // 50% duty cycle, period of 20 time units
  end

  initial begin
    clk2 = 1'b0;
    forever #5 clk2 = ~clk2; // 50% duty cycle, period of 10 time units
  end
  
  // Rest of the testbench code  
endmodule
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.