Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. library IEEE;
  2. use ieee.std_logic_1164.all;
  3.  
  4. entity count is
  5. generic (
  6. n: integer := 16
  7. );
  8. port (
  9. clear : in std_logic;
  10. clk : in std_logic;
  11. tc : out std_logic;
  12. q : out std_logic_vector (n-1 downto 0)
  13. );
  14. end count;
  15.  
  16. architecture comport of count is
  17. begin
  18. process(clk,clear)
  19. variable valor : std_logic_vector(n-1 downto 0);
  20. variable co : std_logic_vector(n-1 downto 0);
  21. variable total : std_logic := '1';
  22. variable numb: integer := 0;
  23. begin
  24.  
  25. if (clear = '1') then
  26. for numb in 0 to (n-1) loop
  27. valor(numb) := '0';
  28. end loop;
  29. elsif(rising_edge(clk)) then
  30. for numb in 0 to (n-1) loop
  31. if (numb=0) then
  32. co(numb) := valor(numb) and '1';
  33. valor(numb) := valor(numb) xor '1';
  34. else
  35. co(numb) := valor(numb) and co(numb-1);
  36. valor(numb) := valor(numb) xor co(numb-1);
  37. end if;
  38. end loop;
  39. end if;
  40.  
  41. for numb in 0 to (n-1) loop
  42. total := total and valor(numb);
  43. end loop;
  44. q <= valor;
  45. tc <= total;
  46. end process;
  47. end comport;
  48.  
  49. ------------------------------------------------------------------------------------------------
  50.  
  51. library IEEE;
  52. use ieee.std_logic_1164.all;
  53.  
  54. entity contador is
  55. generic (
  56. gen : integer := 4
  57. );
  58.  
  59. port (
  60. CLEAR : in std_logic;
  61. C: in std_logic;
  62. Q : out std_logic_vector (gen-1 downto 0);
  63. TC : out std_logic
  64. );
  65. end contador;
  66.  
  67. architecture rtl of contador is
  68. component count is
  69. generic (
  70. n: integer := 16
  71. );
  72. port (
  73. clear : in std_logic;
  74. clk : in std_logic;
  75. tc : out std_logic;
  76. q : out std_logic_vector (n-1 downto 0)
  77. );
  78. end component;
  79.  
  80. begin
  81. r1 : count
  82. generic map(
  83. n => gen
  84. )
  85.  
  86. port map (
  87. clear => CLEAR,
  88. clk => C,
  89. q => Q,
  90. tc => TC
  91. );
  92. end rtl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement