Verilog 奇數分頻

代碼:spa

module odd_div( );
parameter    DIV_PARA = 3;    //分頻係數,3即3分頻
parameter    DIV_PARA_2 = DIV_PARA >> 1;
reg             clk, rstn, clk_div_pos, clk_div_neg;
wire            clk_div_out;
reg        [31:0]    cnt;

initial begin
    clk <= 0;
    rstn <= 0;
    #50 rstn <= 1;
end

always begin
    #10 clk <= 0;
    #10 clk <= 1;
end

// 計數循環
always@(posedge clk or negedge rstn) begin
    if (!rstn) begin
        cnt <= 32'd0;
        end
    else
        if (cnt < (DIV_PARA-1))
            cnt <= cnt + 1;
        else
            cnt <= 0;
end
// 上升沿觸發
always@(posedge clk or negedge rstn) begin
    if (!rstn) begin
        clk_div_pos <= 0;
        end
    else begin
        if (cnt < DIV_PARA_2)
            clk_div_pos <= 1;
        else
            clk_div_pos <= 0;
        end
end
// 降低沿觸發
always@(negedge clk or negedge rstn) begin
    if (!rstn) begin
        clk_div_neg <= 0;
        end
    else begin
        if (cnt < DIV_PARA_2)
            clk_div_neg <= 1;
        else
            clk_div_neg <= 0;
        end
end
// 生成分頻信號
assign clk_div_out = clk_div_pos | clk_div_neg;    

endmodule

 

這個代碼比較簡單,並且爲了仿真方便,將dut和bench寫在一個模塊了。。。。.net

代碼設計思路來自這個帖子 https://blog.csdn.net/lt66ds/article/details/10035187設計

 

DIV_PARA參數設置分頻係數,MoldelSIm仿真圖以下3d

 

3分頻:code

DIV_PARA = 3blog

原時鐘週期20ns,分頻後的時鐘週期爲60ns,佔空比爲50%it

 

 

5分頻:class

DIV_PARA = 5module

原時鐘週期20ns,分頻後的時鐘週期爲100ns,佔空比爲50%sed

相關文章
相關標籤/搜索