Guest User

Untitled

a guest
Feb 27th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.28 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use ieee.std_logic_arith.all;
  4. use IEEE.std_logic_unsigned.all;
  5.  
  6. -- Uncomment the following library declaration if using
  7. -- arithmetic functions with Signed or Unsigned values
  8. use IEEE.NUMERIC_STD.ALL;
  9.  
  10. -- Uncomment the following library declaration if instantiating
  11. -- any Xilinx primitives in this code.
  12. --library UNISIM;
  13. --use UNISIM.VComponents.all;
  14.  
  15. entity counter is
  16. port(  clk_input:  in std_logic;
  17.   reset:  in std_logic;
  18.   enable:  in std_logic;
  19.   count:  out std_logic_vector(3 downto 0)
  20. );
  21. end counter;
  22.  
  23. architecture behav of counter is        
  24.  
  25. signal pre_count: std_logic_vector(3 downto 0);
  26. signal clk_divider : std_logic_vector(23 downto 0) := x"000000";
  27. signal slow_clk : std_logic;
  28.  
  29.  
  30.   begin
  31.  
  32.   clk_division : process (clk_input, clk_divider)
  33.     begin
  34.         if (clk_input = '1' and clk_input'event) then
  35.             clk_divider <= clk_divider + 1;
  36.         end if;
  37.         slow_clk <= clk_divider(23);
  38.         end process;
  39.  
  40.     counting: process(slow_clk, enable, reset)
  41.     begin
  42.    
  43.      if reset = '1' then
  44.         pre_count <= "0000";
  45.       elsif rising_edge(slow_clk) then
  46.         if enable = '1' then
  47.           pre_count <= pre_count + '1';
  48.         end if;
  49.       end if;
  50.     end process;  
  51.     count <= pre_count;
  52. end behav;
Advertisement
Add Comment
Please, Sign In to add comment