Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.std_logic_unsigned.all;
  4.  
  5. entity UDcounter16bit is
  6. port ( D : in std_logic_vector(15 downto 0);
  7. Resetn, LE, Dir, Clk: in std_logic;
  8. Q : out std_logic_vector(15 downto 0) );
  9. end UDcounter16bit;
  10.  
  11. architecture behavior of UDcounter16bit is
  12. signal Qtmp : std_logic_vector(16 downto 0);
  13. begin
  14. Q <= Qtmp;
  15. process(Clk, Resetn)
  16. begin
  17. if (Resetn = '0') then -– asynchronous reset
  18. Qtmp <= (others => '0');
  19. elsif (Clk'event and Clk = '1') then
  20. if (LE = '1') then Qtmp <= D -- load value
  21. else
  22. case Dir is
  23. when '0' => –- count up
  24. Qtmp <= Qtmp + 1;
  25. when '1' => –- count down
  26. Qtmp <= Qtmp - 1;
  27. when others => Qtmp <= Qtmp;
  28. end case;
  29. end if;
  30. end if;
  31. end process;
  32. end behavior;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement