Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Module: Debouncer

Problem Statement

When a button is pressed, mechanical contacts may cause the signal to "bounce" (i.e., generate multiple transitions or glitches) before settling into a stable state. The task is to implement a debouncing circuit that filters out these glitches and provides a clean signal indicating a valid button press.

Module Name: debouncer

Parameters

Parameter Comment
CLK_FREQ_MHZ Frequency of the clk_i signal in MHz.
GLITCH_TIME_NS Maximum expected duration for which bounce (glitches) can be observed, in nanoseconds.

Signal Descriptions

Signal Name Direction Width Comment
clk_i input 1 Clock signal.
key_i input 1 Button signal (0 - pressed, 1 - not pressed).
key_pressed_stb_o output 1 Strobe (pulse) for one clock cycle, indicating a valid button press.

Explanation of the Code

  1. Debouncing Logic:

    • The button input key_i is synchronized using two flip-flops (key1 and key2) to mitigate metastability issues that arise due to asynchronous input signals.
    • The signal key2 represents the debounced signal, which is delayed by two clock cycles.
  2. Glitch Filtering:

    • The GLITCH_CLKS parameter is calculated by multiplying the glitch time (GLITCH_TIME_NS) in nanoseconds by the clock frequency (CLK_FREQ_MHZ) in MHz, and dividing by 1000 to convert nanoseconds into clock cycles.
    • The counter cnt increments each clock cycle when the button is pressed (~key2). If the button is released or the strobe signal (key_pressed_stb_o) is asserted, the counter resets to zero.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages