Structured procedures provide a means of modeling blocks of procedural statements.
always statement
initial statement
function
task
Functions and tasks are described in the section: Task and Functions.
The initial statement (Example 1) is executed only during a simulation run. The always procedural block statement (Example 2) is executed continuously during simulation, i.e. when the flow of program reaches the last statement in the block, the flow continues with the first statement in the block.
The always statement should contain at least one procedural timing control because otherwise it may hang the simulation.
Module definition can contain more than one initial or always statement.
Care must be taken when same reg type variables are used in multiple procedural blocks, initial or always. This is because these blocks run in parallel and changing or assigning to one variable affects the same variable in another parallel block.
Example 1
initial out = 1'b0;
initial begin
#10;
a = 1'b0;
#10;
a = 1'b1;
#10;
a = 1'bz;
end
Example 2
always @(posedge clk)
q = d;
always #10 clk = ~clk;
initial clk = 0;
initial repeat(20)#\10
clk=~clk;
The first initial statement sets clk to 0 at time 0, and the second initial block toggles the clk 20 times every 10 time units.
The always statement should contain at least one procedural timing control.
Powered by IXwebhosting |