VHDL中按键消抖的一种方法--延时性消抖

来源:互联网 发布:什么是网络平台 编辑:程序博客网 时间:2024/06/05 16:13

VHDL中按键消抖的一种方法--延时性消抖

在本例子中,input是按键的输入,output是消抖之后的按键输出

是clk经历8个上升沿之后就让output输出一个CLK周期的高电平!

本程序实例测试好用


library ieee;
use ieee.std_logic_1164.all;


entity PWlock is
port(clk: in std_logic;
input: in std_logic;
output: out std_logic
);
end PWlock;


architecture one of PWlock  is
signal a:std_logic;
signal count:integer range 0 to 9;
begin
process(clk)
begin
if input='0' then 
count<=0;
elsif (clk'event and clk='1') then
if count=9 then 
count<=count;    --like while(1) in the C program

else
count<=count+1;
end if;
end if; --for elsif

if count=8 then 
a<='0';
else
a<='1';
end if;

end process;
output<=a;
end one;