1 | library IEEE;
|
2 | use IEEE.std_logic_1164.all;
|
3 | use IEEE.numeric_std.all;
|
4 |
|
5 | entity debounce_fsm is
|
6 | generic( MAX_CNT : integer := 40);
|
7 | port( clk, rst, taster : in std_logic;
|
8 | debounced : out std_logic);
|
9 | end entity debounce_fsm;
|
10 |
|
11 | architecture behavorial of debounce_fsm is
|
12 |
|
13 | signal countval : integer range 0 to MAX_CNT := 0;
|
14 | signal ts : std_logic := '0'; -- einsynchronisierter Taster
|
15 |
|
16 | begin
|
17 |
|
18 |
|
19 | counter : process (clk)
|
20 | begin
|
21 | if rising_edge(clk) then
|
22 | ts <= taster; -- Taster erst mal einsynchronisieren
|
23 |
|
24 | if ts = '0' then -- wenn low -> Zähler und Ausgang zurücksetzen
|
25 | countval <= 0;
|
26 | debounced <= '0';
|
27 | else -- wenn high ->
|
28 | if countval < MAX_CNT then -- zählen
|
29 | countval <= countval + 1;
|
30 | else -- und begrenzen
|
31 | countval <= 0;
|
32 | debounced <= ts; -- wenn Endstand erreicht --> Tasterpegel zum Ausgang übernehmen
|
33 | end if;
|
34 | end if;
|
35 | end if;
|
36 | end process counter;
|
37 |
|
38 | end behavorial;
|