debouncer.vhd
来自「This is a project about PWM. Application」· VHDL 代码 · 共 57 行
VHD
57 行
------------------------------------------------------------------------------ debouncer for buttons -- variable bounce window ("period")----------------------------------------------------------------------------library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity debouncer is port( clk: in std_logic; raw: in std_logic; period: in std_logic_vector(31 downto 0); debounced: out std_logic );end debouncer;architecture behavior of debouncer istype statetype is (standby, pressed, released);signal state: statetype := standby;signal count: std_logic_vector(31 downto 0);begin process begin wait until rising_edge(clk); case state is when standby => if (raw = '1') then state <= pressed; debounced <= '1'; count <= (others => '0'); end if; when pressed => if (count < period) then count <= count + 1; elsif (raw = '0') then count <= (others => '0'); state <= released; end if; when released => debounced <= '0'; if (count < period) then count <= count + 1; else state <= standby; end if; end case; end process;end behavior;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?