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

Clock Generator: Simple Clock Generation

Verilog Examples

Runnable example from the Verilog Clock Generator tutorial (Simple Clock Generation)

Open in IDE
testbench.v
`timescale 1ns/1ps

module tb;
  reg clk;

  // Style 1: initialize, then toggle every half period
  initial clk = 0;
  always #5 clk = ~clk;              // 10 ns period, 100 MHz

  // Style 2: the same clock in a single initial block
  // initial begin
  //   clk = 0;
  //   forever #5 clk = ~clk;
  // end
endmodule
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.