stankovic96

[PSDS] Dec.Counter from 0 to 9

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