I have problem with this code in testbench because it gives me X for cout
, and I couldn't find the problem.
Three bit counter Verilog with enable:
`timescale 1ns/1ns
module three_bit_counter(output cout,input en,clk);
reg [2:0] w;
always@(negedge clk)begin
if (en)
w <= w + 1;
end
assign cout= w & en;
endmodule
And this is my testbench:
`timescale 1ns/1ns
module three_bit_counterTB();
reg en;
reg clk=1;
wire cout;
three_bit_counter tbc(cout,en,clk);
always #20 clk=~clk;
initial begin
#20 en=1;
#100;
$stop;
end
endmodule