This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/Quartus/v5/jyh_4490_5_divider.v
2022-04-19 21:45:53 +08:00

42 lines
No EOL
665 B
Verilog

module jyh_4490_5_divider(clk_out,sel,clk,en);
input clk,sel,en;
output reg clk_out;
reg [14:0]counter=0;
localparam TARGET_4=2784; // ((1/4490)/(1/50M))/4
localparam TARGET_5=863; // ((1/14490)/(1/50M))/4
initial begin
clk_out=0;
end
always @(posedge clk)
if(en)
begin
counter<=counter+1;
if(sel)
begin
if(counter==TARGET_5)
begin
clk_out<=0;
end
if(counter==4*TARGET_5)
begin
clk_out<=1;
counter<=0;
end
end
else if(!sel)
begin
if(counter==TARGET_4)
begin
clk_out<=0;
end
if(counter==4*TARGET_4)
begin
clk_out<=1;
counter<=0;
end
end
end
endmodule