1 | ----------------------------------------------------------------------------------
|
---|
2 | -- Company:
|
---|
3 | -- Engineer:
|
---|
4 | --
|
---|
5 | -- Create Date: 13:42:35 01/08/2010
|
---|
6 | -- Design Name:
|
---|
7 | -- Module Name: debouncer - Behavioral
|
---|
8 | -- Project Name:
|
---|
9 | -- Target Devices:
|
---|
10 | -- Tool versions:
|
---|
11 | -- Description:
|
---|
12 | --
|
---|
13 | -- Dependencies:
|
---|
14 | --
|
---|
15 | -- Revision:
|
---|
16 | -- Revision 0.01 - File Created
|
---|
17 | -- Additional Comments:
|
---|
18 | --
|
---|
19 | ----------------------------------------------------------------------------------
|
---|
20 | library IEEE;
|
---|
21 | use IEEE.STD_LOGIC_1164.ALL;
|
---|
22 | use IEEE.NUMERIC_STD.ALL;
|
---|
23 |
|
---|
24 | ---- Uncomment the following library declaration if instantiating
|
---|
25 | ---- any Xilinx primitives in this code.
|
---|
26 | --library UNISIM;
|
---|
27 | --use UNISIM.VComponents.all;
|
---|
28 |
|
---|
29 | entity debouncer is
|
---|
30 | Generic ( WIDTH : INTEGER := 17);
|
---|
31 | Port ( clk : in STD_LOGIC;
|
---|
32 | -- rst : in STD_LOGIC;
|
---|
33 | trigger_in : in STD_LOGIC;
|
---|
34 | trigger_out : out STD_LOGIC := '0');
|
---|
35 | end debouncer;
|
---|
36 |
|
---|
37 | architecture Behavioral of debouncer is
|
---|
38 |
|
---|
39 | signal counter : STD_LOGIC_VECTOR(WIDTH-1 downto 0) := (others => '0');
|
---|
40 | signal int_trigger : std_logic := '0';
|
---|
41 | signal temp_trig : std_logic_vector(1 downto 0) := "00";
|
---|
42 | signal trigger_flag : std_logic := '0';
|
---|
43 | signal temp_signal : std_logic := '0';
|
---|
44 |
|
---|
45 | begin
|
---|
46 |
|
---|
47 | debounce_proc: process (clk)
|
---|
48 | begin
|
---|
49 | -- if (rst = '1') then
|
---|
50 | -- counter <= (others => '0');
|
---|
51 | -- trigger_out <= '0';
|
---|
52 | -- elsif rising_edge(clk) then
|
---|
53 | if rising_edge(clk) then
|
---|
54 | if (trigger_in = '1') then
|
---|
55 | if (unsigned(counter) = 2**WIDTH-1) then
|
---|
56 | int_trigger <= '1';
|
---|
57 | counter <= (others => '1');
|
---|
58 | else
|
---|
59 | counter <= std_logic_vector(unsigned(counter) + to_unsigned(1,WIDTH));
|
---|
60 | end if;
|
---|
61 | else
|
---|
62 | if (unsigned(counter) = 0) then
|
---|
63 | int_trigger <= '0';
|
---|
64 | counter <= (others => '0');
|
---|
65 | else
|
---|
66 | counter <= std_logic_vector(unsigned(counter) - to_unsigned(1,WIDTH));
|
---|
67 | end if;
|
---|
68 | end if;
|
---|
69 | end if;
|
---|
70 | end process debounce_proc;
|
---|
71 |
|
---|
72 | shaping_proc : process (clk)
|
---|
73 | begin
|
---|
74 | -- if (rst = '1') then
|
---|
75 | -- trigger_out <= '0';
|
---|
76 | -- trigger_flag <= '0';
|
---|
77 | -- temp_signal <= '0';
|
---|
78 | -- elsif rising_edge(clk) then
|
---|
79 | if rising_edge(clk) then
|
---|
80 | -- temp_trig <= temp_trig(2 downto 0) & trigger_in;
|
---|
81 | -- trigger_out <= not temp_trig(3) and temp_trig(2);
|
---|
82 | temp_trig <= temp_trig(0) & int_trigger;
|
---|
83 | temp_signal <= not temp_trig(1) and temp_trig(0);
|
---|
84 | trigger_out <= temp_signal and not trigger_flag;
|
---|
85 | if (int_trigger = '0') then
|
---|
86 | trigger_flag <= '0';
|
---|
87 | end if;
|
---|
88 | if (temp_signal = '1') then
|
---|
89 | trigger_flag <= '1';
|
---|
90 | end if;
|
---|
91 | end if;
|
---|
92 | end process shaping_proc;
|
---|
93 |
|
---|
94 |
|
---|
95 | end Behavioral;
|
---|
96 |
|
---|
97 |
|
---|