Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.numeric_std.all;
  4.  
  5. entity debounce is
  6. port( clk, reset : in std_logic;
  7. sw : in std_logic;
  8. db_level, db_tick :out std_logic);
  9. end debounce;
  10.  
  11. architecture Behavioral of debounce is
  12. constant N: integer := 21;
  13. type state_type is (zero, wait0, one, wait1);
  14. signal state_reg, state_next: state_type;
  15. signal q_reg, q_next : unsigned (N-1 downto 0);
  16.  
  17. begin
  18. process (clk, reset)
  19. begin
  20. if reset = '1' then
  21. state_reg <= zero;
  22. q_reg <= (others => '0');
  23. elsif (clk'event and clk = '1') then
  24. state_reg <= state_next;
  25. q_reg <= q_next;
  26. end if;
  27. end process;
  28.  
  29. process (state_reg, q_reg, sw, q_next)
  30. begin
  31. state_next <= state_reg;
  32. q_next <= q_reg;
  33. db_tick <= '0';
  34. case state_reg is
  35. when zero =>
  36. db_level <= '0';
  37. if (sw='1') then
  38. state_next <= wait1;
  39. q_next <= (others=> '1');
  40. end if;
  41. when wait1 =>
  42. db_level <= '0';
  43. if (sw = '1') then
  44. q_next <= q_reg - 1;
  45. if (q_next=0) then
  46. state_next <= one;
  47. db_tick <= '1';
  48. end if;
  49. else state_next <= zero;
  50. end if;
  51.  
  52. when one =>
  53. db_level <= '1';
  54. if (sw='0') then
  55. state_next <= wait0;
  56. q_next <= (others=>'1');
  57. end if;
  58. when wait0 =>
  59. db_level <= '1';
  60. if (sw='0') then
  61. q_next <= q_reg - 1;
  62. if (q_next=0) then
  63. state_next <= zero;
  64. end if;
  65. else state_next <= one;
  66. end if;
  67. end case;
  68. end process;
  69.  
  70.  
  71.  
  72. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement