module divider(
input clk,
input rst_n,
input [2:0] divider_num, //0~7分别对应1~8分频 num[0]=0对应奇数分频
output out_clk
);
reg [2:0] cnt1;
reg clk_even;
//偶数分频
always @(posedge clk or negedge rst_n)begin
if(!rst_n||!divider_num[0])
cnt1<=3'd0;
else if(cnt1<(((divider_num+1)/2)-1)) //计到最终的数减1
cnt1<=cnt1+1;
else
cnt1<=3'd0;
end
always @(posedge clk or negedge rst_n)begin
if(!rst_n||!divider_num[0])
clk_even<=1'b0;
else if(cnt1==(((divider_num+1)/2)-1))
clk_even<=~clk_even;
end
//奇数分频
reg[2:0] cnt2,cnt3;
reg clk_odd1;
reg clk_odd2;
wire clk_odd;
always @(posedge clk or negedge rst_n)begin
if(!rst_n||divider_num[0])
cnt2<=3'd0;
else if(cnt2<(divider_num))
cnt2<=cnt2+1;
else
cnt2<=3'd0;
end
always @(posedge clk or negedge rst_n)begin
if(!rst_n||divider_num[0])
clk_odd1<=1'b0;
else if(cnt2<=(divider_num/2))
clk_odd1<=1'b
1~8分频
最新推荐文章于 2022-05-31 23:17:33 发布
本文详细介绍了如何使用FPGA技术实现数字信号的1到8分频功能,涵盖了设计思路、逻辑实现以及具体步骤,对于理解和掌握FPGA分频设计具有实践指导意义。
摘要由CSDN通过智能技术生成