entity stable_key is
port(
clk:in std_logic;
key_in:in std_logic;
key_out:out std_logic
);
end stable_key;
architecture fun of stable_key is
signal cnt:integer range 0 to 1999999;
signal key,key_d:std_logic;
begin
process(clk)
begin
if clk'event and clk='1' then
if key/=key_in then
key_d<=key_in;
cnt<=0;
elsif cnt=1999999 then
key_out<=not key_d;
cnt<=0;
else
cnt<=cnt+1;
end if;
key<=key_in;
end if;
end process;
end;作者: zhengtn03 时间: 2013-5-11 20:41
module debounce(clk,key_i,key_o);
input clk;
input key_i;
output key_o;
parameter NUMBER = 10086000;
parameter NBITS = 24;
reg [NBITS-1:0] count;
reg key_o_temp;
reg key_m;
reg key_i_t1,key_i_t2;
assign key_o = key_o_temp;
always @ (posedge clk) begin
key_i_t1 <= key_i;
key_i_t2 <= key_i_t1;
end
always @ (posedge clk) begin
if (key_m!=key_i_t2) begin
key_m <= key_i_t2;
count <= 0;
end
else if (count == NUMBER) begin
key_o_temp <= key_m;
end
else count <= count+1;
end
endmodule 作者: gyth_lx 时间: 2013-5-14 16:20
记得以前看过一个巨精简的,直接以50Hz频率检测键盘按键,一般抖动是不响应的。。。作者: 7802848 时间: 2013-5-15 14:03
说实话,很烂作者: tennokoe 时间: 2013-5-15 15:14
这是条邪路啊……