• <li id="00i08"><input id="00i08"></input></li>
  • <sup id="00i08"><tbody id="00i08"></tbody></sup>
    <abbr id="00i08"></abbr>
  • 新聞中心

    EEPW首頁 > 嵌入式系統 > 設計應用 > 用FPGA邏輯消抖動

    用FPGA邏輯消抖動

    作者: 時間:2023-12-26 來源:電子森林 收藏

    我們將一個開關連接到上,連接方式如下圖:機械開關的問題就是有抖動,每次按一下開關,你會得到下面的信號:

    本文引用地址:http://www.czjhyjcfj.com/article/202312/454265.htm

    這種信號很少碰到,多數情況是下面的這種:

    我們可以用的計數器來記錄按鍵的次數,并通過數碼管顯示出來: 上電的時候,一起是好的:

    如果按十次鍵,得到下面的結果:

    顯然不對。

    那如何解決呢? 一種方式是添加一個R/C濾波器,再跟一個施密特觸發器之后送給,當然還有更簡單的方式,就是在FPGA內部進行消抖動。 FPGA擅長簡單的運算,讓我們使用FPGA中的計數器來查看按下或釋放按鈕的時間。只有當計數器達到最大值時,我們才確定按鈕已經改變了狀態。

    PB是按鈕信號(在本例中為低電平有效)。它可能包含毛刺,并且對任何時鐘都是異步的,所以它基本上是不可用的。我們將使PB與時鐘(本例中為20MHz)同步,然后創建三個無毛刺、與時鐘同步的按鈕輸出。每個輸出都將是高電平有效的,并指示按鈕的不同狀態(按鈕狀態,剛剛按下,剛剛釋放)。

    module PushButton_Debouncer(
        input clk,
        input PB,  // "PB" is the glitchy, asynchronous to clk, active low push-button signal     
       
        // from which we make three outputs, all synchronous to the clock
        output reg PB_state,  // 1 as long as the push-button is active (down)
        output PB_down,  // 1 for one clock cycle when the push-button goes down (i.e. just pushed)
        output PB_up   // 1 for one clock cycle when the push-button goes up (i.e. just released)
        ); 
        
        // First use two flip-flops to synchronize the PB signal the "clk" clock domain
        reg PB_sync_0;  
        always @(posedge clk) PB_sync_0 <= ~PB;  // invert PB to make PB_sync_0 active high
        reg PB_sync_1;  
        always @(posedge clk) PB_sync_1 <= PB_sync_0; // Next declare a 16-bits counter
        reg [15:0] PB_cnt; // When the push-button is pushed or released, we increment the counter
        
        // The counter has to be maxed out before we decide that the push-button state has changed 
        wire PB_idle = (PB_state==PB_sync_1);
        wire PB_cnt_max = &PB_cnt;	// true when all bits of PB_cnt are 1's 
        always @(posedge clk)if(PB_idle)
        PB_cnt <= 0;  // nothing's going onelsebegin
        PB_cnt <= PB_cnt + 16'd1;  // something's going on, increment the counter
        if(PB_cnt_max) PB_state <= ~PB_state;  // if the counter is maxed out, PB changed!
        end 
        
        assign PB_down = ~PB_idle & PB_cnt_max & ~PB_state;
        assign PB_up   = ~PB_idle & PB_cnt_max &  PB_state;
        endmodule

    我們使用了一個16位計數器。如果使用20MHz的系統時鐘,則需要3ms才能達到最大值。從用戶的角度來看,3ms是很短暫的,但毛刺已經消失了。根據你的按鈕的毛刺程度和你的系統時鐘速度,你可能需要調整計數器的寬度。



    關鍵詞: FPGA 消除抖動

    評論


    相關推薦

    技術專區

    關閉
    主站蜘蛛池模板: 麻阳| 海兴县| 沧源| 宣化县| 永年县| 龙南县| 疏附县| 二连浩特市| 阳西县| 南安市| 巴塘县| 莱芜市| 淮南市| 贡觉县| 郁南县| 阿坝县| 宁陕县| 伽师县| 英山县| 肇州县| 佛学| 石首市| 美姑县| 江达县| 牡丹江市| 和政县| 石河子市| 三明市| 揭西县| 成武县| 元氏县| 汨罗市| 永定县| 锡林浩特市| 裕民县| 长子县| 白城市| 汨罗市| 达孜县| 房产| 成安县|