Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.46 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date:    08:41:32 11/10/2010
  6. -- Design Name:
  7. -- Module Name:    tiktok - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library ieee;
  21. use ieee.std_logic_1164.ALL;
  22. use ieee.std_logic_arith.all;
  23. use ieee.std_logic_unsigned.all;
  24.  
  25. entity counter is
  26.     Port ( led   : inout std_logic_vector (7 downto 0);
  27.            clk   : in std_logic;
  28.               reset : in std_logic;
  29.               up    : in std_logic;
  30.               down  : in std_logic
  31.               );
  32. end counter;
  33.  
  34. architecture Behavioral of counter is
  35.     signal clkdiv : std_logic;
  36.     signal shift : std_logic;
  37. begin
  38.  
  39.     div: process(clk)
  40.         variable q1 : std_logic_vector(22 downto 0);
  41.     begin
  42.         if clk = '1' and clk'event then
  43.             q1 := q1 + '1';
  44.             if q1(22) = '1' then
  45.                 q1 := (others => '0');
  46.                 clkdiv <= not clkdiv;
  47.             end if;
  48.         end if;
  49.     end process div;
  50.  
  51.     P1: process(clkdiv, reset, up, down)
  52.     begin
  53.         if reset = '1' then
  54.             led <= (others => '0');
  55.         elsif clkdiv'event and clkdiv = '1' then
  56.             if (up xor down) = '1' then
  57.                 if up = '1' then
  58.                     led <= led + '1';
  59.                 else
  60.                     led <= led - '1';
  61.                 end if;
  62.             end if;
  63.         end if;
  64.     end process P1;
  65. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement