I have made a counter module and I can't seem to grasp the execution order of initial block for both counter module and testbench module.
As far as I know, I thought in verilog, initial block would always be executed first.
In this case, I'll be executing testbench module and I am assuming initial block
for testbench_counter will be executed first.
Next, I thought counter module C would be executed and value for x_in would be updated to temp with no need for #1 delay in module C.
But without #1, or changing initial to always@(x_in) I see redline.
So the question is
would
initialblock for counter moduleCbe executed first even before theinitialblock for testbench?Why does it work if i use
always@(x_in)?
Thanks in advance.
Code for counter
`timescale 1ns/1ns
module counter(x_in,clk,y_out);
input [31:0] x_in;
input clk;
output [31:0] y_out;
reg [31:0] y_out;
reg [31:0] temp;
initial begin
#1 temp=x_in;
end
always@(posedge clk) begin
temp<=temp+1;
y_out<=temp;
end
endmodule
code for testbench
`timescale 1ns/1ns
module testbench_conter();
wire [31:0]y_out;
wire [31:0]temp;
reg [31:0]x_in;
reg clk;
counter C(x_in,clk,y_out);
always begin
#5 clk=~clk;
end
initial begin
clk=1'b0;
x_in=32'd0;
#0
#10000
$stop;
end
endmodule