Timing Control in Verilog:
There are three constructs that controls the time in verilog. They are
- Edge based timing control
- Level based timing control
- Event based timing control
Above all constructs are not synthesize-able.
Edge based timing control:
- By using @(posedge or negedge) we can control the time.
- We can use it any where with in procedural block.
- It is blocking construct and it blocks until it see the posedge i.e., before this statement if posedge ocuurs then it will wait until it see the next posedge.
Example:
module tb;
reg x;
initial begin
x = 0;
#10 x = 1;
#10 x= 0;
end
initial begin
#50 @(posedge x);
$display("event based control");
end
endmodule
In above example posedge of x happens at 10th time unit and simulator is waiting for posedge from 50th time unit. So, simulator does n't see the posedge so $display statement will never be executed.
module tb;
reg x;
initial begin
x = 0;
#10 x = 1;
#10 x= 0;
end
initial begin
#5 @(posedge x);
$display("event based control");
end
endmodule
In above example posedge of x happens at 10th time unit and simulator is waiting for posedge from 5th time unit. So, simulator saw the posedge of x at 10th time unit and execute the $display statement at 10th time unit only.
Level based timing control:
- By using wait(<exp>) we can control the time.
- This is a blocking construct that blocks until the given expression becomes true .
- It is level based because even before the wait statement if the expression is true then wait statement is unblocked i.e., when ever wait statement sees the expression is true then it becomes unblocked.
Example:
module tb;
reg y;
initial begin
y = 0;
#20 y = 1;
#50 y = 0;
end
initial begin
wait(y);
$display($time, "level based control");
end
endmodule
Here simulator is waiting for y to trigger to 1 from 0 time unit and at 20th time unit y triggers to 1 then at 20th time unit $display statement is executed.
module tb;
reg y;
initial begin
y = 0;
#20 y = 1;
#50 y = 0;
end
initial begin
#75;
wait(y);
$display($time, "level based control");
end
endmodule
Here simulator is waiting for y to trigger to 1 from 75th time before that i.e., at 20th time unit y triggers to 1. So, simulator does n't saw the true value of y so it blocks $display statement until it sees y becomes true.
Event based timing control:
- event based control is mainly used for event synchronization.
- Here we can declare the variables as event type by using event keyword
- Event variables are not value holders they used to indicate the change in state.
- @ is used for waiting on event
- -> is used for triggering an event
- Here before waiting if triggering happens then it did n't see the change in state.
Example:
module tb;
module tb;
event z;
initial begin
#15;
->z;
end
initial begin
#10;
@z;
$display("event based control");
end
endmodule
Here simulator is waiting for event z to be triggered from 10th time unit and z is triggered at 15th time unit . So, $display is executed in 15th time unit.
module tb;
event z;
initial begin
#15;
->z;
end
initial begin
#20;
@z;
$display("event based control");
end
endmodule
Here simulator is waiting for event z to be triggered from 20th time unit but z is triggered in 15th time unit . So, simulator does n't see the triggering of event z so $display is not executed.
No comments:
Post a Comment