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

Level Sensitive UDP

Verilog Advanced Topics

Level Sensitive UDP — a ready-to-run Verilog example.

Open in IDE
Related tutorial:
design.v
primitive d_latch (q, clk, d);
	output 	q;
	input 	clk, d;
	reg  	q;
	
	table
		// clk 	d 		q 	q+
			1 	1 	:	? :	1;
			1 	0 	: 	? : 0;
			0 	? 	: 	? : -;
	endtable
endprimitive
testbench.v
module tb;
  reg clk, d;
  reg [1:0] dly;
  wire q;
  integer i;
  
  d_latch u_latch (q, clk, d);
  
  always #10 clk = ~clk;
  
  initial begin
    clk = 0;
    
    $monitor ("[T=%0t] clk=%0b d=%0b q=%0b", $time, clk, d, q); 
    
    #10;
    
    for (i = 0; i < 50; i = i+1) begin
      dly = $random;
      #(dly) d <= $random;
    end
    
    #20 $finish;
  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.