Re: vhdl code for debouncing push button
- From: Frank Buss <fb@xxxxxxxxxxxxx>
- Date: Sun, 27 Jul 2008 17:07:07 +0200
Zhane wrote:
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;
Usually every unsychronized external input should be latched. A switch
doesn't change very often, so the probality to cause problems is very low,
but I would add another signal, something like this:
debounce_pb: process(clk) is
begin
if rising_edge(clk) then
if clk_100Hz ='1' then
if pb_latched = pb_sampled then
pb_debounced <= pb_latched;
end if;
pb_sampled <= pb_latched;
pb_latched <= pb;
end if;
end if;
end process debounce_pb;
The rest of the code looks ok. It filters single spikes, which are shorter
than 20ms and filters any bouncing sequence shorter than 10ms. I would add
a generic parameter for specifying the clock frequency to make the entity
more resuable.
--
Frank Buss, fb@xxxxxxxxxxxxx
http://www.frank-buss.de, http://www.it4-systems.de
.
- References:
- vhdl code for debouncing push button
- From: Zhane
- vhdl code for debouncing push button
- Prev by Date: Re: vhdl code for debouncing push button
- Next by Date: Cyclone III passive serial config issue
- Previous by thread: Re: vhdl code for debouncing push button
- Next by thread: Re: vhdl code for debouncing push button
- Index(es):