Advertisement
Staryy

Counter2

Dec 15th, 2019
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 0.83 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4.  
  5. entity COUNTER is
  6.     Port (
  7.         clk, reset : in std_logic;
  8.         up_down: inout std_logic;
  9.         q1 : out std_logic_vector ( 3 downto 0)
  10.     );
  11. end COUNTER;
  12.  
  13. architecture Behavioral of COUNTER is
  14.    
  15.     begin
  16.         process (clk, reset )
  17.         variable temp1 : integer := 0;
  18.         begin
  19.         if(reset = '1') then
  20.             temp1 := 0;
  21.             up_down <= '1';
  22.         else if(clk' event and clk = '1') then
  23.                
  24.                     if(up_down = '1') then
  25.                         if (temp1 = 15) then
  26.                             up_down <= '0';
  27.                         else
  28.                             temp1 := temp1 + 1;
  29.                         end if;
  30.                     else
  31.                         if(temp1 = 0) then
  32.                             up_down <= '1';
  33.                         else
  34.                             temp1 := temp1 -1;
  35.                         end if;
  36.                        
  37.                     end if;
  38.         end if;
  39.        
  40.         q1 <= std_logic_vector(to_unsigned(temp1, q1'length));
  41.         end process;
  42. end architecture Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement