gollub

dec_counter

Nov 4th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.13 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.std_logic_unsigned.all;
  4. use ieee.std_logic_arith.all;
  5.  
  6. entity dec_counter is
  7.     Port ( en : in STD_LOGIC;
  8.            reset : in STD_LOGIC;
  9.            clk : in STD_LOGIC;
  10.            q : out STD_LOGIC_VECTOR (3 downto 0);
  11.            pulse : out STD_LOGIC);
  12. end dec_counter;
  13.  
  14. architecture Behavioral of dec_counter is
  15.     signal count_s: std_logic_vector(3 downto 0) := (others => '0');
  16.     signal temp: std_logic;
  17. begin
  18.     cnt: process (clk) is
  19.     begin
  20.         if(clk'event and clk = '1') then
  21.             if(reset = '0') then
  22.                 if(en = '1') then    
  23.                     if(count_s < conv_std_logic_vector(9, 4)) then
  24.                         count_s <= count_s + 1;
  25.                         temp <= '0';
  26.                     else
  27.                         count_s <= (others => '0');
  28.                         temp <= '1';
  29.                     end if;    
  30.                 end if;
  31.              else
  32.                 count_s <= (others => '0');
  33.              end if;
  34.         end if;
  35.     end process;
  36.    
  37.     q <= count_s;
  38.     pulse <= temp;
  39.    
  40. end Behavioral;
Add Comment
Please, Sign In to add comment