|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
本帖最后由 quantumdot 于 2014-7-7 18:49 编辑
奇数、偶数50%占空比分频很容易,点5分频是处理小数分频,比如3.5,7.5,23.5等,相比整数分频稍微复杂一点
- module Divclkp5(clk,tg_clk,rst);
- input clk,rst;
- output tg_clk;
- reg tg_clk;
- reg[23:0]counter,counter2;
- wire clk1;
- reg temp_tgp;
- parameter countN=11; //(2n+1)/2=clkin/clkout N=2n+1,n>=2
- always@(posedge clk or posedge rst)
- begin
- if(rst)
- counter<=24'b0;
- else if(counter>(countN-2))
- counter<=24'b0;
- else
- counter<=counter+1'b1;
- end
- //(countN-1)/2:(countN+1)/2
- always@(*)
- begin
- if(counter>(countN-3)/2)//counter odd
- temp_tgp<=1'b0;
- else
- temp_tgp<=1'b1;
- end
- //new clk
- assign clk1=clk^temp_tgp;
- //repeat count
- always@(posedge clk1 or posedge rst)
- begin
- if(rst)
- counter2<=24'b0;
- else if(counter2>(countN-3)/2)
- counter2<=24'b0;
- else
- counter2<=counter2+1'b1;
- end
- //注意Duty的调整,这里绝不会出现50%的情况
- //if N<9 <--(countN-5)/2) else <--(countN-1)/4
- always@(*)
- begin
- if(countN<9)
- begin
- if(counter2>(countN-5)/2)
- tg_clk<=1'b0;
- else
- tg_clk<=1'b1;
- end
- else
- begin
- if(counter2>(countN-1)/4)
- tg_clk<=1'b0;
- else
- tg_clk<=1'b1;
- end
- end
- endmodule
复制代码
首先将分频数*2进行奇数分频,不需要占空比为50%,然后与原时钟xor得到新时钟,再用新时钟重计数
最后再来调整占空比
例如5.5分频
貌似1.5分频不适用,大家可以多多发言 |
|