Re: vhdl code for debouncing push button




"Zhane" <me75@xxxxxxxxxxx> wrote in message
news:ab0ae7bc-b7a5-47bd-bc2e-33d350f3026a@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
are there any vhdl codes that are available for free to debounce the
pushbutton on my spartan 3E?

I require the push button to generate only 1 clock for 50mhz only upon
release.

I've gotten some code from the net but aint sure if it does what I
need....

==============================================================

library ieee;
use ieee.std_logic_1164.all;

entity debouncer is
port (clk,reset: in std_logic; -- clk frequency = 50Mhz
pb: in std_logic;
pb_debounced: out std_logic
);
end entity debouncer;

architecture rtl of debouncer is
signal count500000 : integer range 0 to 499999;
signal clk_100Hz: std_logic;
signal pb_sampled: std_logic;
begin

div_100Hz: process(clk,reset) is
begin
if reset ='1' then
clk_100Hz <= '0';
count500000 <= 0;
elsif rising_edge(clk) then
if count500000 = 499999 then
count500000 <= 0;
clk_100Hz <='1';
else
count500000 <= count500000 + 1;
clk_100Hz <='0';
end if;
end if;
end process div_100Hz;

debounce_pb: process(clk) is
begin
if rising_edge(clk) then
if clk_100Hz ='1' then
if pb = pb_sampled then
pb_debounced <= pb;
end if;
pb_sampled <= pb;
end if;
end if;
end process debounce_pb;

end architecture rtl;
==================================================

pls advise

There are a few methods of debouncing switches.

One way of thinking is what's the minimum period between switch operations,
then having a timer-counter to ensure that another swich operations can't
occur during this period.

constant integer max := xxxxx;

if reset then
timer_count = 0;
pb_debounced = '0';

else rising_edge(clk) then
if pb = '0' then
if timer_count = max then
pb_debounced <= '1';
timer_count <= 0;
else
timer_count <= 0;
end if;
else
if timer_count = max then
pb_debounced <= '1';
else
timer_count <= timer_count +1;
end if;
end if;
end if;

E&OE!


.


Quantcast