I am trying to divide the input clock by two; the output clock should be half the frequency of the input clock.
module clk_div(in_clk, out_clk, rst);
input in_clk;
input rst;
output out_clk;
reg out_clk;
always @(posedge in_clk) begin
if (!rst) begin
out_clk <= 1'b0;
end
else
out_clk <= ~out_clk;
end
endmodule
The testbench is:
module dd;
// Inputs
reg clk_in;
reg reset;
// Outputs
wire clk_out;
// Instantiate the Unit Under Test (UUT)
clk_div uut (
.clk_in(clk_in),
.reset(reset),
.clk_out(clk_out)
);
always #10 clk_in =~clk_in ;
initial begin
// Initialize Inputs
clk_in = 0;
reset = 0;
#100;
reset = 1;
end
endmodule
The output waveform shows only the input clock being generated. No matter what I try, the output clock waveform would not come. Is this code correct for clock division by two?