debouncer.vhd

来自「描述:LED示范、按钮及开关、视频输出、键入、含Xilinx PicoBlaze」· VHDL 代码 · 共 44 行

VHD
44
字号
--component used to debounce an input signal
--the signal must be stable while the component counts
--from 0 to 2^wait_period to be propagated to the output port
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity Debouncer is
	 generic ( wait_period: positive := 10);
    Port ( CLK : in std_logic;
           SIG_IN : in std_logic;
           SIG_OUT : out std_logic);
end Debouncer;

architecture Behavioral of Debouncer is

signal counter: std_logic_vector(wait_period downto 0);
signal old_in_value: std_logic;

begin

	process (CLK)
	begin
		if (CLK'event) and (CLK='1') then			
			if (SIG_IN = old_in_value) then
				--if the input signal is stable, we have two possibilities:
				--either we are ready to propagate it to the output port
				--or we increment the counter waiting for it
				if (counter(wait_period) = '1') then
					SIG_OUT <= old_in_value;
				else
					counter <= counter + '1';
				end if;	
			else 
				--input has changed, reset the counter to 0
				counter <= (others => '0');
				old_in_value <= SIG_IN;
			end if;
		end if;
	end process;

end Behavioral;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?