标题: 基于FPGA的奇数分频占空比50% veilog程序 [打印本页]

作者: pceng    时间: 2022-6-14 14:07
标题: 基于FPGA的奇数分频占空比50% veilog程序
一、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

三、仿真时序



作者: heicad    时间: 2024-1-23 01:04
好资料,51黑有你更精彩!!!




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1