Verilog: Timing Controls

Last modified 2014-03-30

Sini

Table of content
  1. Timing Controls
  2. Delay Based Timing Control
  3. Regular Delay Control
  4. Intra-assignment Delay Control
  5. Zero Delay Control
  6. Event Based Timing Control
  7. Regular event control
  8. Named Event Control
  9. Event OR control
  10. Level Sensitive Timing Control

Timing Controls

Timing control statements are required in simulation to advance time. The time at which procedural statements will get executed shall be specified using timing controls. Delay based, event based and level sensitive timing controls are available in Verilog. Each of these are discussed below.

Delay Based Timing Control

In this, timing control is achieved by specifying waiting time to execution, when the statement is encountered. The sybmol "#" is used to specify the delay. There are 3 ways, delay based timing control can be specified.

Event Based Timing Control

In this, execution of a statement or a block of a statement is controlled by an event. Regular, named and event OR control are different types of event based controls.

Level Sensitive Timing Control

This waits for a certain condition to be true. In the below example, it waits for xor-ctrl bits to be 1, and then do the assignment to out.

module levelcontrol(in,ctrl,out);

input [31:0] in; input [2:0] ctrl; output [31:0] out;

reg [31:0] out;

always begin wait (^ctrl) #2 out = in + 100; end endmodule

module testlevelcontrol; reg [31:0] in; reg [2:0] ctrl; wire [31:0] out;

levelcontrol ec(in,ctrl,out);

initial begin in = 32'd25; ctrl = 3'b100;

#10 in = 'd50; ctrl = 3'b101;

#10 in = 'd30; ctrl = 3'b001;

#10 in = 40; ctrl = 3'b011;

#10 in = 0; ctrl = 3'b100; end

initial begin $monitor($time,"in=%0d, ctrl=%b out=%0d\n",in,ctrl,out); #50 $finish; end

endmodule

/*

Simulation Result ncsim> run 0in=25, ctrl=100 out=x

2in=25, ctrl=100 out=125

10in=50, ctrl=101 out=125

12in=50, ctrl=101 out=150

20in=30, ctrl=001 out=150

22in=30, ctrl=001 out=130

30in=40, ctrl=011 out=130

32in=40, ctrl=011 out=140

40in=0, ctrl=100 out=140

42in=0, ctrl=100 out=100

Simulation complete via $finish(1) at time 50 NS + 0 ./levelsensitive.v:43 #50 $finish;

*/