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

QQ登錄

只需一步,快速開始

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

基于FPGA的奇數(shù)分頻占空比50% veilog程序

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
一、veilog程序:
module g_b
(
input clk ,
input rst_n,
output out_clk,
output reg out_clk1,
output reg out_clk2,
output reg [3 :0] cnt_1,
output reg [3 :0] cnt_2
);

parameter N = 3 ;


always @(posedge clk or negedge rst_n) begin
if(!rst_n)
        begin
                out_clk1 <= 0;
                cnt_1 <= 1;
        end
else
        begin
                if(out_clk1 == 0)
                        begin
                                if(cnt_1 == N/2+1)
                                        begin
                                                out_clk1 <= ~out_clk1;
                                                cnt_1 <= 1;
                                        end
                                else
                                cnt_1 <= cnt_1+1;

                        end
           else if(cnt_1 == N/2)
                        begin
                                out_clk1 <= ~out_clk1;
                                cnt_1 <= 1;
                end
                else
                        cnt_1 <= cnt_1+1;
        end
end

always @(negedge clk or negedge rst_n)
begin
        if(!rst_n)
                begin
                        out_clk2 <= 0;
                        cnt_2 <= 1;
                end
        else
                begin
                        if(out_clk2 == 0)
                                begin
                                        if(cnt_2 == N/2+1)
                                                begin
                                                        out_clk2 <= ~out_clk2;
                                                        cnt_2 <= 1;
                                                end
                                        else
                                                cnt_2 <= cnt_2+1;
                                end
                        else if(cnt_2 == N/2)
                                begin
                                        out_clk2 <= ~out_clk2;
                                        cnt_2 <= 1;
                                end
                        else
                                cnt_2 <= cnt_2+1;
                end
end

assign out_clk = out_clk1 | out_clk2;

endmodule



二、module仿真
`timescale 1ns / 1ps

module g_b_tb();

reg sys_clk ;
reg sys_rst_n;
wire out_clk ;
wire [3 :0] cnt_1;
wire [3 :0] cnt_2;
initial begin
sys_clk = 1'b0;
sys_rst_n = 1'b0;

#200
sys_rst_n = 1'b1;

end


always #10 sys_clk = ~sys_clk;

g_b u1(
.clk (sys_clk ),
.rst_n (sys_rst_n ),
.out_clk (out_clk ),
.out_clk1(out_clk1),
.out_clk2(out_clk2),
.cnt_1(cnt_1),
.cnt_2(cnt_2)
);

endmodule

三、仿真時(shí)序


評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

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

使用道具 舉報(bào)

沙發(fā)
ID:262 發(fā)表于 2024-1-23 01:04 | 只看該作者
好資料,51黑有你更精彩!!!
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

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