Advertisement
thibthibaut

TP 3 Level 3

Nov 21st, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.61 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date:    09:55:25 11/21/2014
  6. -- Design Name:
  7. -- Module Name:    Counter - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22. use ieee.std_logic_unsigned.all;
  23.  
  24. -- Uncomment the following library declaration if using
  25. -- arithmetic functions with Signed or Unsigned values
  26. use IEEE.NUMERIC_STD.ALL;
  27.  
  28. -- Uncomment the following library declaration if instantiating
  29. -- any Xilinx primitives in this code.
  30. --library UNISIM;
  31. --use UNISIM.VComponents.all;
  32.  
  33. entity Counter is
  34.     Port ( Reset : in  STD_LOGIC;
  35.            CLK : in  STD_LOGIC;
  36.               Enable : in STD_LOGIC;
  37.            S : out  STD_LOGIC_VECTOR(25 downto 0));
  38. end Counter;
  39.  
  40. architecture Behavioral of Counter is
  41.  
  42. signal Add : STD_LOGIC_VECTOR(25 downto 0);
  43. signal Reg : STD_LOGIC_VECTOR(25 downto 0);
  44. signal Mux1, Mux2 : STD_LOGIC_VECTOR(25 downto 0);
  45. signal Cmp : STD_LOGIC;
  46.  
  47. begin
  48.  
  49. Reg <= "00000000000000000000000000" when Reset = '0' else Mux2 when rising_edge(CLK);
  50.      
  51. Add <= Reg + "0000000000000000000000001";
  52.  
  53. Mux1 <= Add when Cmp = '0' else "00000000000000000000000000" when Cmp = '1';
  54.  
  55. Mux2 <= Reg when Enable = '0' else Mux1 when Enable = '1';
  56.  
  57. Cmp <= '1' when Add > "0000000000000000000001000" else '0';
  58.  
  59. S <= Mux2;
  60.  
  61. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement