// 偶数分频器示例,20分频即N=10,占空比50%
module Fre_div_even(
input clk,
input rst_n,
input [3:0] N, // N = 分频倍数/2
output reg clk_out
);
reg [3:0] cnt;
always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
cnt <= 4'b0;
clk_out <= 1'b0;
end
else
begin
if(cnt == N-1)
begin
clk_out <= ~clk_out;
cnt <= 4'b0;
end
else
begin
cnt <= cnt + 4'b1;
end
end
end
endmodule