找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2954|回复: 0
收起左侧

FPGA几种特殊分频方式

[复制链接]
ID:104287 发表于 2016-1-31 23:42 | 显示全部楼层 |阅读模式
 

1半整数分频占空比不为50%

//说明:设计的史上最好用的半整数分频占空比不为50%,包含设计思路

module div_5(clk,clk_div,cnt1,cnt2,temp1,temp2);//N+0.5

input clk;

output clk_div;

output reg[31:0]cnt1,cnt2;

output reg temp1,temp2;

initial begin temp1=0;temp2=1;end   //首先进行初始化,temp1=0;temp2=1

parameter N=5;  //设定分频系数为N+0.5

always @(posedge clk)  //temp1上升沿跳变

begin

if(cnt1==2*N)  //2*N

begin cnt1[31:0]<=32'd0;end

else begin cnt1[31:0]<=cnt1[31:0]+32'd1;end

if(cnt1==32'd0) begin temp1<=1;end   //高电平时间为N+1;

if(cnt1==N+1) begin temp1<=0;end   //低电平时间为N;

end

always@(negedge clk)  //temp2下降沿跳变

begin

if(cnt2==2*N)  //2*N

begin cnt2[31:0]<=32'd0;end

else begin cnt2[31:0]<=cnt2[31:0]+32'd1;end

if(cnt2==32'd0) begin temp2<=0;end     //低电平时间为N;

if(cnt2==N) begin temp2<=1;end    //高电平时间为N+1;

end

assign clk_div=temp1&&temp2;  //逻辑与

endmodule

//如果要进行N+0.5分频

//思路:总的来说要进行N+1+N=2N+1次分频

//在时钟的上升沿和下降沿都进行跳变

//上升沿进行占空比为N+1N的时钟temp1;

//下降沿进行占空比为NN+1的时钟temp2;

//最后div=temp1&&temp2 即可得到所需要的半整数分频

 

2、奇数分频占空比为50%

//说明:奇数分频。

module div_5(clk,clk_div,cnt1,cnt2,temp1,temp2);//

input clk;

output clk_div;

output reg[31:0]cnt1,cnt2;

output reg temp1,temp2;

parameter N=5;  //设定分频系数

always @(posedge clk)

begin

if(cnt1==N-1)  //N-1进行N计数

begin cnt1[31:0]<=32'd0;end

else begin cnt1[31:0]<=cnt1[31:0]+32'd1;end

if(cnt1==32'd0) begin temp1<=1;end   //

if(cnt1==(N-1)/2) begin temp1<=0;end   //当计数到(N-1)/2时翻转

end

always@(negedge clk)

begin

if(cnt2==N-1)  //N-1

begin cnt2[31:0]<=32'd0;end

else begin cnt2[31:0]<=cnt2[31:0]+32'd1;end

if(cnt2==32'd0) begin temp2<=1;end     //;

if(cnt2==(N-1)/2) begin temp2<=0;end    //当计数到(N-1)/2时翻转;

end

assign clk_div=temp1||temp2;  //逻辑或

endmodule


 

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表