用Bresenham演算法在FPGA上實現小數分頻器

來源:互聯網
上載者:User

最近朋友問了一個問題,輸入時鐘是33MHz,要分出一路2.048MHz的時鐘來,要求相位抖動儘可能小。我想到可以用電腦圖形學中繪製直線的Bresenham演算法來解決,獲得成功。

輸入時鐘是33000kHz,輸出時鐘是2048kHz,好比從原點畫一條到(33000,2048)的直線,用輸入時鐘驅動畫筆在 x 方向的運動,那麼對應的 y 方向的運動就是輸出時鐘。

Verilog代碼如下:

module  divider(clk_in, clk_out, nrst);
  input  clk_in,  nrst;
  output clk_out;
  reg    clk_out;

  parameter input_freq = 33000;   // both in kHz
  parameter output_freq = 2048;
 
  reg[16:0] err;          // change to 18 bits if necessary, look down
 
  always @(posedge clk_in or negedge nrst)
  begin
    if (nrst == 1'b0) begin
      clk_out <= 1'b0;
      err <= (output_freq << 2) - input_freq;
    end
    else begin
      if (err[16] == 1'b0) begin  // also change here !!! (if change the former)
        err <= err - (input_freq << 1) + (output_freq << 2);
        clk_out <= !clk_out;
      end
      else begin
        err <= err + (output_freq << 2);
      end
    end
  end
 
endmodule

這是一個同步時序電路,在 clk_in 的每個上升沿判斷 clk_out 是否翻轉,設 clk_in 的周期是T,
那麼 clk_out  的邊沿抖動小於T。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.