找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3724|回復: 0
打印 上一主題 下一主題
收起左側

FPGA幾種特殊分頻方式

[復制鏈接]
跳轉到指定樓層
樓主
ID:104287 發(fā)表于 2016-1-31 23:42 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
 

1、半整數(shù)分頻占空比不為50%

//說明:設計的史上最好用的半整數(shù)分頻占空比不為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;  //設定分頻系數(shù)為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 即可得到所需要的半整數(shù)分頻

 

2、奇數(shù)分頻占空比為50%

//說明:奇數(shù)分頻。

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;  //設定分頻系數(shù)

always @(posedge clk)

begin

if(cnt1==N-1)  //N-1進行N計數(shù)

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   //當計數(shù)到(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    //當計數(shù)到(N-1)/2時翻轉;

end

assign clk_div=temp1||temp2;  //邏輯或

endmodule


 

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表