Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.50 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date:    16:36:31 11/22/2016
  6. -- Design Name:
  7. -- Module Name:    counterImp - 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_arith.all;
  23. use ieee.std_logic_unsigned.all;
  24.  
  25. ---- Uncomment the following library declaration if instantiating
  26. ---- any Xilinx primitives in this code.
  27. --library UNISIM;
  28. --use UNISIM.VComponents.all;
  29.  
  30. entity counterImp is
  31.     Port ( x : in  STD_LOGIC :='0';
  32.               clock: in std_logic :='0';
  33.               output : out std_logic_vector(3 downto 0));
  34. end counterImp;
  35.  
  36. architecture Behavioral of counterImp is
  37.  
  38. signal z : std_logic_vector(3 downto 0) :="1001";
  39. signal count : integer range 0 to 1025:= 0;
  40.  
  41. begin
  42.  
  43. output <= z;
  44. process (clock)
  45.     begin
  46.         if(rising_edge(clock)) then
  47.             count <= count + 1;
  48.             if (count = 1024) then
  49.                 count <= 0;
  50.             end if;
  51.             if (count = 0) then
  52.                 if (x = '0') then
  53.                     if (z = "1001") then
  54.                         z <= "0000";
  55.                     else
  56.                         z <= z + 1;
  57.                     end if;
  58.                 else
  59.                     if (z = "0000") then
  60.                         z <= "1001";
  61.                     else
  62.                         z <= z - 1;
  63.                     end if;
  64.                 end if;        
  65.             end if;
  66.         end if;
  67. end process;
  68. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement