Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. entity vores_counter is
  5. generic(
  6. N: integer; -- antal bits der skal repr�sentere det tal man skal t�lle til.
  7. M: integer -- Tal man t�ller til
  8. );
  9. port(
  10. count : in std_logic;
  11. reset : in std_logic;
  12. max_tick: out std_logic;
  13. q: out std_logic_vector(N-1 downto 0)
  14. );
  15. end vores_counter;
  16.  
  17. architecture arch of vores_counter is
  18. signal r_reg: unsigned(N-1 downto 0);
  19. signal r_next: unsigned(N-1 downto 0);
  20. begin
  21. -- register
  22. process(count ,reset)
  23. begin
  24. if (reset='1') then
  25. r_reg <= (others=>'0');
  26. elsif (count'event and count='1') then
  27. r_reg <= r_next;
  28. end if;
  29. end process;
  30. -- next-state logic
  31. r_next <= (others=>'0') when r_reg=(M-1) else
  32. r_reg + 1;
  33. -- output logic
  34. q <= std_logic_vector(r_reg);
  35. max_tick <= '1' when unsigned(r_reg)=(M-1) else '0';
  36. end arch;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement