分频器的编写

来源:百度知道 编辑:UC知道 时间:2024/06/17 04:05:58
那位大侠能帮小妹编写一个把24MHZ的时钟脉冲用VHDL程序分频得到1HZ的时钟脉冲啊!小妹将不胜感激啊!等到急用!!

module fp (clk_in,reset,clk_out1,clk_out2);

parameter L1=666;

parameter L2=400000;
input clk_in,reset;
output clk_out1,clk_out2;
integer count1;
integer count2;
reg clk_out1,clk_out2;
always @(posedge clk_in)
begin
if(!reset) //复位
count1=0;
else
begin
if(count1<(L1))
begin
count1=count1+1;
if(count1<(L1/2))
clk_out1= 1;
else
clk_out1=0;
end
else
count1=0;
end
end

always @(posedge clk_in)
begin
if(!reset)
count2=0;
else
begin
if(count2<(L2))
begin
count2=count2+1;
if(count2<(L2/2))
clk_out2= 1;
else
clk_out2=0;
end
else
count2=0;
end
end
endmodule