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

Verilog Timescale

Verilog Timing & Delays

Verilog Timescale — a ready-to-run Verilog example.

Open in IDE
Related tutorial:
testbench.v
`ifdef NS10_NS1
	`timescale 10ns/1ns
`elsif NS1_PS1
	`timescale 1ns/1ps
`else
	`timescale 1ns/1ns
`endif

module tb;
  reg val;
  
  initial begin
    // Initialize the signal to 0 at time 0 units
    val <= 0;
 
    // Advance by 1 time unit, display a message and toggle val
    #1     $display ("T=%0t At time #1", $realtime);
    val <= 1;
 
    // Advance by 0.49 time unit and toggle val
    #0.49   $display ("T=%0t At time #0.49", $realtime);
    val <= 0;
 
    // Advance by 0.50 time unit and toggle val
    #0.50   $display ("T=%0t At time #0.50", $realtime);
    val <= 1;
 
    // Advance by 0.51 time unit and toggle val
    #0.51   $display ("T=%0t At time #0.51", $realtime);
    val <= 0;
 
    // Let simulation run for another 5 time units and exit
    #5 $display ("T=%0t End of simulation", $realtime);
  end
  
  initial begin
    $dumpvars;
    $dumpfile("dump.vcd");
  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.