Advertisement
Staryy

Counter

Dec 15th, 2019
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 0.78 KB | None | 0 0
  1. entity UPDOWN_COUNTER is
  2.  
  3.     Port(
  4.         clk : int std_logic;  /* clock input*/
  5.         reset : in std_logic; /*  reset input*/
  6.         up_down : in std_logic /*  counting up or down*/
  7.         counter : out std_logic_vector ( 3 downto 0)
  8.     );
  9.        
  10. end UPDOWN_COUNTER
  11.  
  12. architecture Behavioral of UPDOWN_COUNTER is
  13.  
  14.     signal counter_updown: std_logic_vector ( 3 downto 0 );
  15.    
  16.     begin
  17.         process(clk,reset)
  18.             begin
  19.                 if ( reset = '1' ) then
  20.                
  21.                     counter_updown <= "0000";
  22.                    
  23.                 elsif (clk'event and clk = '1') then
  24.                    
  25.                     if(up_down = '1') then
  26.                    
  27.                         counter_updown <= counter_updown + 1;
  28.                    
  29.                     else
  30.                    
  31.                         counter_updown <= counter_updown - 1;
  32.                    
  33.                     end if;
  34.                    
  35.                 end if;
  36.            
  37.         counter <= counter_updown; 
  38.        
  39.         end process;
  40.        
  41.        
  42. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement