OpenCores
URL https://opencores.org/ocsvn/System09/System09/trunk

Subversion Repositories System09

[/] [System09/] [trunk/] [rtl/] [System09_Digilent_Atlys/] [btn_debounce.vhd] - Blame information for rev 185

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 185 davidgb
----------------------------------------------------------------------------
2
--      btn_debounce.vhd -- Button Debouncer
3
----------------------------------------------------------------------------
4
-- Author:  Sam Bobrowicz
5
--          Copyright 2011 Digilent, Inc.
6
----------------------------------------------------------------------------
7
--
8
----------------------------------------------------------------------------
9
--      This component is used to debounce signals generated by external push
10
-- buttons. It is designed to independently debounce 5 Push button signals.
11
-- Debouncing is done by only registering a change in a button state if 
12
-- it remains constant for 2^16 clock cycles. 
13
--                                      
14
-- Port Descriptions:
15
--
16
--   BTN_I - The input button signals
17
--    CLK  - Behavior is optimized for a 100 MHz clock
18
--   BTN_O - The debounced button signals
19
--                                                                                      
20
----------------------------------------------------------------------------
21
--
22
----------------------------------------------------------------------------
23
-- Revision History:
24
--  08/08/2011(SamB): Created using Xilinx Tools 13.2
25
----------------------------------------------------------------------------
26
 
27
library IEEE;
28
use IEEE.STD_LOGIC_1164.ALL;
29
use IEEE.std_logic_unsigned.all;
30
 
31
entity btn_debounce is
32
    Port ( BTN_I : in  STD_LOGIC_VECTOR (4 downto 0);
33
           CLK : in  STD_LOGIC;
34
           BTN_O : out  STD_LOGIC_VECTOR (4 downto 0));
35
end btn_debounce;
36
 
37
architecture Behavioral of btn_debounce is
38
 
39
constant CNTR_MAX : std_logic_vector(15 downto 0) := (others => '1');
40
 
41
signal btn0_cntr : std_logic_vector(15 downto 0) := (others => '0');
42
signal btn1_cntr : std_logic_vector(15 downto 0) := (others => '0');
43
signal btn2_cntr : std_logic_vector(15 downto 0) := (others => '0');
44
signal btn3_cntr : std_logic_vector(15 downto 0) := (others => '0');
45
signal btn4_cntr : std_logic_vector(15 downto 0) := (others => '0');
46
 
47
signal btn0_reg : std_logic := '0';
48
signal btn1_reg : std_logic := '0';
49
signal btn2_reg : std_logic := '0';
50
signal btn3_reg : std_logic := '0';
51
signal btn4_reg : std_logic := '0';
52
 
53
begin
54
 
55
btn0_debounce_process : process (CLK)
56
begin
57
        if (rising_edge(CLK)) then
58
                if (btn0_cntr = CNTR_MAX) then
59
                        btn0_reg <= not(btn0_reg);
60
                end if;
61
        end if;
62
end process;
63
 
64
btn0_counter_process : process (CLK)
65
begin
66
        if (rising_edge(CLK)) then
67
                if ((btn0_reg = '1') xor (BTN_I(0) = '1')) then
68
                        if (btn0_cntr = CNTR_MAX) then
69
                                btn0_cntr <= (others => '0');
70
                        else
71
                                btn0_cntr <= btn0_cntr + 1;
72
                        end if;
73
                else
74
                        btn0_cntr <= (others => '0');
75
                end if;
76
        end if;
77
end process;
78
 
79
btn1_debounce_process : process (CLK)
80
begin
81
        if (rising_edge(CLK)) then
82
                if (btn1_cntr = CNTR_MAX) then
83
                        btn1_reg <= not(btn1_reg);
84
                end if;
85
        end if;
86
end process;
87
 
88
btn1_counter_process : process (CLK)
89
begin
90
        if (rising_edge(CLK)) then
91
                if ((btn1_reg = '1') xor (BTN_I(1) = '1')) then
92
                        if (btn1_cntr = CNTR_MAX) then
93
                                btn1_cntr <= (others => '0');
94
                        else
95
                                btn1_cntr <= btn1_cntr + 1;
96
                        end if;
97
                else
98
                        btn1_cntr <= (others => '0');
99
                end if;
100
        end if;
101
end process;
102
 
103
btn2_debounce_process : process (CLK)
104
begin
105
        if (rising_edge(CLK)) then
106
                if (btn2_cntr = CNTR_MAX) then
107
                        btn2_reg <= not(btn2_reg);
108
                end if;
109
        end if;
110
end process;
111
 
112
btn2_counter_process : process (CLK)
113
begin
114
        if (rising_edge(CLK)) then
115
                if ((btn2_reg = '1') xor (BTN_I(2) = '1')) then
116
                        if (btn2_cntr = CNTR_MAX) then
117
                                btn2_cntr <= (others => '0');
118
                        else
119
                                btn2_cntr <= btn2_cntr + 1;
120
                        end if;
121
                else
122
                        btn2_cntr <= (others => '0');
123
                end if;
124
        end if;
125
end process;
126
 
127
btn3_debounce_process : process (CLK)
128
begin
129
        if (rising_edge(CLK)) then
130
                if (btn3_cntr = CNTR_MAX) then
131
                        btn3_reg <= not(btn3_reg);
132
                end if;
133
        end if;
134
end process;
135
 
136
btn3_counter_process : process (CLK)
137
begin
138
        if (rising_edge(CLK)) then
139
                if ((btn3_reg = '1') xor (BTN_I(3) = '1')) then
140
                        if (btn3_cntr = CNTR_MAX) then
141
                                btn3_cntr <= (others => '0');
142
                        else
143
                                btn3_cntr <= btn3_cntr + 1;
144
                        end if;
145
                else
146
                        btn3_cntr <= (others => '0');
147
                end if;
148
        end if;
149
end process;
150
 
151
btn4_debounce_process : process (CLK)
152
begin
153
        if (rising_edge(CLK)) then
154
                if (btn4_cntr = CNTR_MAX) then
155
                        btn4_reg <= not(btn4_reg);
156
                end if;
157
        end if;
158
end process;
159
 
160
btn4_counter_process : process (CLK)
161
begin
162
        if (rising_edge(CLK)) then
163
                if ((btn4_reg = '1') xor (BTN_I(4) = '1')) then
164
                        if (btn4_cntr = CNTR_MAX) then
165
                                btn4_cntr <= (others => '0');
166
                        else
167
                                btn4_cntr <= btn4_cntr + 1;
168
                        end if;
169
                else
170
                        btn4_cntr <= (others => '0');
171
                end if;
172
        end if;
173
end process;
174
 
175
BTN_O <= btn4_reg & btn3_reg & btn2_reg & btn1_reg & btn0_reg;
176
 
177
end Behavioral;
178
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.