cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Newbie
Newbie
6,201 Views
Registered: ‎08-04-2009

Button debouncing: waiting for the user to release the key they pressed

I am making a basic volume control in verilog where the user can increase or decrease the volume by pressing and holding a button (for instance, if the user presses and holds down the "volume up" button, the volume counter will slowly increase, thus increasing the volume, as long as the button is pressed).  I understand that I must debounce my buttons for proper operation. 

 

I also have a "mute" button, where if the user presses the mute button once, the volume counter is set to 0 (thus, no sound will be coming out), and if the user presses the mute button again, the volume level will be set at the previous level before the initial mute button hit.  The mute button is a toggle between the "mute" state and the "sound back on" state.

 

--> If the user presses and then holds the mute button, my verilog code will keep toggling very rapidly between "mute" and "sound back on".  I don't want this to happen.  How can I write a synthesizable code block, where if the user holds the mute button down, only one toggle will happen no matter how long they hold the button down for?  [The user may hold the button down for a very long time - we don't know beforehand how long].   

 

 

0 Kudos
3 Replies
6,198 Views
Registered: ‎07-15-2008

Re: Button debouncing: waiting for the user to release the key they pressed

For the mute function I’d do this

   

I’d take the mute signal, div by two (just a flip flop), use that signal as a mux select, one side of the mux I’d set to data ‘0’ (mute) the other side I’d set to current volume.

  

It would be very easy to describe this circuit in VHDL, sorry I don’t do Verilog but I guess that you could easily describe this circuit in Verilog too.

 

 

   Kind Regards Bobster
0 Kudos
Highlighted
Anonymous
Not applicable
6,185 Views

Re: Button debouncing: waiting for the user to release the key they pressed

rtarbell, for the mute you have to use a SR latch(debouncing).

Once it is debounced, you can use a counter.

-->user keeps mute button pressed. The SR latch output stay high and is reset by your code (say after 1ms). Now, you count the SR latch output.

If it is 1 (odd) then mute, if 2 then unmute and reset counter.

 

 

    

 

 

0 Kudos
Highlighted
Voyager
Voyager
6,166 Views
Registered: ‎08-30-2007

Re: Button debouncing: waiting for the user to release the key they pressed

I think some simple code would work well for you...

 


reg     [1:0]   mute_pipe;
reg             muting = 1'b0;

always @(posedge clk)
    begin
    mute_pipe   <= {mute_pipe, debounced_mute_input};

    if (mute_pipe == 2'b01)
        muting  <= ~muting;
    end

 

 

John Providenza

0 Kudos