找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 3839|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

FPGA幾種特殊分頻方式

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:104287 發(fā)表于 2016-1-31 23:42 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
 

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

//說(shuō)明:設(shè)計(jì)的史上最好用的半整數(shù)分頻占空比不為50%,包含設(shè)計(jì)思路

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   //首先進(jìn)行初始化,temp1=0;temp2=1

parameter N=5;  //設(shè)定分頻系數(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   //高電平時(shí)間為N+1;

if(cnt1==N+1) begin temp1<=0;end   //低電平時(shí)間為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     //低電平時(shí)間為N;

if(cnt2==N) begin temp2<=1;end    //高電平時(shí)間為N+1;

end

assign clk_div=temp1&&temp2;  //邏輯與

endmodule

//如果要進(jìn)行N+0.5分頻

//思路:總的來(lái)說(shuō)要進(jìn)行N+1+N=2N+1次分頻

//在時(shí)鐘的上升沿和下降沿都進(jìn)行跳變

//上升沿進(jìn)行占空比為N+1N的時(shí)鐘temp1;

//下降沿進(jìn)行占空比為NN+1的時(shí)鐘temp2;

//最后div=temp1&&temp2 即可得到所需要的半整數(shù)分頻

 

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

//說(shuō)明:奇數(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è)定分頻系數(shù)

always @(posedge clk)

begin

if(cnt1==N-1)  //N-1進(jìn)行N計(jì)數(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   //當(dāng)計(jì)數(shù)到(N-1)/2時(shí)翻轉(zhuǎn)

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    //當(dāng)計(jì)數(shù)到(N-1)/2時(shí)翻轉(zhuǎn);

end

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

endmodule


 

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

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

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

快速回復(fù) 返回頂部 返回列表