Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.39 KB | None | 0 0
  1. LIBRARY ieee;
  2. USE ieee.std_logic_1164.ALL;
  3. USE ieee.numeric_std.ALL;
  4. ENTITY hello_world IS
  5.     GENERIC (
  6.         counterBitNb : POSITIVE := 18;
  7.         mode : INTEGER RANGE (0 TO 1) := 0
  8.     );
  9.     PORT (
  10.         clk        : IN std_logic;
  11.         switch     : IN std_logic;
  12.         led        : OUT std_logic;
  13.         led1       : OUT std_logic;
  14.         input      : IN std_ulogic;
  15.         debounced  : OUT std_ulogic;
  16.         reset      : IN std_ulogic
  17.     );
  18. END hello_world;
  19. ARCHITECTURE rtl OF hello_world IS
  20.     SIGNAL cnt : unsigned(24 DOWNTO 0);
  21.     SIGNAL cnt : unsigned(counterBitNb - 1 DOWNTO 0);
  22.     SIGNAL debounced_m0 : std_ulogic;
  23.     SIGNAL debounced_m1 : std_ulogic;
  24. BEGIN
  25.     counter : PROCESS(reset, clock)
  26.     BEGIN
  27.         IF reset = '1' THEN
  28.             cnt <= (OTHERS => '0');
  29.         ELSIF rising_edge(clock) THEN
  30.             IF mode = 0 THEN
  31.                 IF input = '1' THEN
  32.                     cnt <= (OTHERS => '1');
  33.                 ELSE
  34.                     IF cnt /= 0 THEN
  35.                         cnt <= cnt - 1;
  36.                     END IF;
  37.                 END IF;
  38.             ELSE
  39.                 IF input = '0' THEN
  40.                     cnt <= (OTHERS => '1');
  41.                 ELSE
  42.                     IF cnt /= 0 THEN
  43.                         cnt <= cnt - 1;
  44.                     END IF;
  45.                 END IF;
  46.             END IF;
  47.         END IF;
  48.     END PROCESS counter;
  49.     debounced_m0 <= '1' WHEN cnt /= 0
  50.                     ELSE '0';
  51.     debounced_m1 <= '1' WHEN cnt = 0
  52.                     ELSE '0';
  53.     debounced <= debounced_m0 WHEN mode = 0
  54.                  ELSE debounced_m1;
  55.     cnt <= cnt + 1 WHEN rising_edge(clk);
  56.     led <= cnt(22);
  57.     led1 <= debounced;
  58.     switch <= input;
  59. END rtl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement