Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1.  
  2. library IEEE;
  3. use IEEE.STD_LOGIC_1164.ALL;
  4. use IEEE. STD_LOGIC_ARITH. ALL; -- use arithmetic
  5. use IEEE. STD_LOGIC_UNSIGNED. ALL;
  6.  
  7. entity counter is
  8. Generic(
  9. width:integer;
  10. reset_value:integer
  11. );
  12. Port(
  13. clk_i: in STD_LOGIC;
  14. reset_i: in STD_LOGIC;
  15. enable_i: in STD_LOGIC;
  16. data_o: out STD_LOGIC_VECTOR(width-1 downto 0)
  17. );
  18. end counter;
  19.  
  20. architecture Behavioral of counter is
  21. signal count: STD_LOGIC_VECTOR(width-1 downto 0);
  22. begin
  23. data_o <= count;
  24.  
  25. process(clk_i)
  26. begin
  27. if(clk_i'event and clk_i='1') then -- pozitivna fronta
  28. if(reset_i='1') then
  29. count <= (others => '0');
  30. else
  31. if (enable_i = '1') then
  32. if (count > reset_value ) then
  33. count <= (others => '0');
  34. else
  35. count <= count + 1;
  36. end if;
  37. else
  38. count <= count;
  39. end if;
  40. end if;
  41. end if;
  42. end process;
  43.  
  44. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement