预用计数方式来达到除二,但是没有输出波型,请问要如何修正才确,谢谢
div2
module div2(clk, clkout, rst);
input clk,rst;
output clkout,cnt;
reg clkout;
reg [1:0]cnt;
wire rst;
always@(posedge clk or negedge rst) begin
if (rst)
cnt <= 0;
else if (cnt == 1)
cnt <= 0;
else
cnt <= cnt + 1;
end
endmodule
always@(posedge clk or negedge rst) begin
if (!rst)
clkout <= 0;
else if (cnt < 1)
clkout = 0;
else
clkout = 1;
end
end
-----------------------------
test_bench
module test_div2;
reg clk,rst;
wire clkout;
wire cnt;
div2 u(clk, clkout, rst,cnt);
initial begin
clk = 1'b1;
rst = 1'b0;
end
always #10 clk = ~clk;
endmodule
div2
module div2(clk, clkout, rst);
input clk,rst;
output clkout,cnt;
reg clkout;
reg [1:0]cnt;
wire rst;
always@(posedge clk or negedge rst) begin
if (rst)
cnt <= 0;
else if (cnt == 1)
cnt <= 0;
else
cnt <= cnt + 1;
end
endmodule
always@(posedge clk or negedge rst) begin
if (!rst)
clkout <= 0;
else if (cnt < 1)
clkout = 0;
else
clkout = 1;
end
end
-----------------------------
test_bench
module test_div2;
reg clk,rst;
wire clkout;
wire cnt;
div2 u(clk, clkout, rst,cnt);
initial begin
clk = 1'b1;
rst = 1'b0;
end
always #10 clk = ~clk;
endmodule