<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

EEPW首頁(yè) > 嵌入式系統 > 設計應用 > 用FPGA邏輯消抖動(dòng)

用FPGA邏輯消抖動(dòng)

作者: 時(shí)間:2023-12-26 來(lái)源:電子森林 收藏

我們將一個(gè)開(kāi)關(guān)連接到上,連接方式如下圖:機械開(kāi)關(guān)的問(wèn)題就是有抖動(dòng),每次按一下開(kāi)關(guān),你會(huì )得到下面的信號:

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

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

我們可以用的計數器來(lái)記錄按鍵的次數,并通過(guò)數碼管顯示出來(lái): 上電的時(shí)候,一起是好的:

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

顯然不對。

那如何解決呢? 一種方式是添加一個(gè)R/C濾波器,再跟一個(gè)施密特觸發(fā)器之后送給,當然還有更簡(jiǎn)單的方式,就是在FPGA內部進(jìn)行消抖動(dòng)。 FPGA擅長(cháng)簡(jiǎn)單的運算,讓我們使用FPGA中的計數器來(lái)查看按下或釋放按鈕的時(shí)間。只有當計數器達到最大值時(shí),我們才確定按鈕已經(jīng)改變了狀態(tài)。

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

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

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



關(guān)鍵詞: FPGA 消除抖動(dòng)

評論


相關(guān)推薦

技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>