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

42 lines
665 B
Coq
Raw Permalink Normal View History

2022-04-19 13:42:43 +00:00
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