Advertisement
Guest User

Untitled

a guest
May 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.80 KB | None | 0 0
  1.  
  2. ----------------------------------------------------------------------------------
  3. -- Company:
  4. -- Engineer:
  5. --
  6. -- Create Date:    08:51:26 05/21/2018
  7. -- Design Name:
  8. -- Module Name:    counter_1k_dec - Behavioral
  9. -- Project Name:
  10. -- Target Devices:
  11. -- Tool versions:
  12. -- Description:
  13. --
  14. -- Dependencies:
  15. --
  16. -- Revision:
  17. -- Revision 0.01 - File Created
  18. -- Additional Comments:
  19. --
  20. ----------------------------------------------------------------------------------
  21. library IEEE;
  22. use IEEE.STD_LOGIC_1164.ALL;
  23. use ieee.STD_LOGIC_UNSIGNED.all;
  24.  
  25. -- Uncomment the following library declaration if using
  26. -- arithmetic functions with Signed or Unsigned values
  27. --use IEEE.NUMERIC_STD.ALL;
  28.  
  29. -- Uncomment the following library declaration if instantiating
  30. -- any Xilinx primitives in this code.
  31. --library UNISIM;
  32. --use UNISIM.VComponents.all;
  33.  
  34. entity rand_dec is
  35.     Port (  clk   : in  STD_LOGIC;
  36.             rand  : out  STD_LOGIC_VECTOR (15 downto 0));
  37. end rand_dec;
  38.  
  39. architecture Behavioral of rand_dec is
  40.  
  41. signal d2, d3, d4 : std_logic_vector(3 downto 0) := "0000";
  42. signal d1 : std_logic := "0001";
  43. signal bin_c : std_logic_vector(15 downto 0) := "0000000000000000";
  44.  
  45. begin
  46.  
  47. dec <= d1 & d2 & d3 & d4;
  48. bin <= bin_c;
  49.  
  50. process(clk)
  51.  
  52. begin
  53.  
  54.     if falling_edge(clk) then
  55.  
  56.         d4 <= d4 + 1;
  57.         if d4 = 9 then
  58.             d4 <= "0000";
  59.             d3 <= d3 + 1;
  60.             if d3 = 9 then
  61.                 d3 <= "0000";
  62.                 d2 <= d2 + 1;
  63.                 if d2 = 9 then
  64.                     d2 <= "0000";
  65.                     d1 <= d1 + 1;
  66.                     if d1 = 9 then
  67.                         d1 <= "0001";
  68.        
  69.                     end if;
  70.                 end if;
  71.             end if;
  72.         end if;
  73.            
  74.     end if;
  75. end process;
  76. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement