前者是2分频,后者是20分频。
//--------------- the first one ------------------
module code1(
rst_n,
clk,
clk_out
);
input rst_n;
input clk;
output clk_out;
reg clk_out;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
clk_out <= 1'b0;
else
clk_out <= ~clk;
end
endmodule
//--------------------- the seconde one -------------------------
module code2(
rst_n,
clk,
clk_out
);
input rst_n;
input clk;
output clk_out;
reg clk_out;
reg [4:0] cnt;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
clk_out <= 1'b0;
cnt <= 5'b0;
end
else
begin
if(cnt==5'd19)
begin
cnt <= 5'd0;
clk_out <= ~clk_out;
end
else
begin
cnt <= cnt+5'd1;
end
end
end