--
-- AutoIncrement-Adresszähler mit WEN-Erzeugung
--
-- Generated by KCPSM3 Assembler 25Jan2009-15:35:03. 
--
-- Standard IEEE libraries
--
library ieee;
  use ieee.std_logic_1164.all;
  use ieee.std_logic_unsigned.all;
  use ieee.numeric_std.all;
--
-- The Unisim Library is used to define Xilinx primitives. It is also used during
-- simulation. The source can be viewed at %XILINX%\vhdl\src\unisims\unisim_VCOMP.vhd
--  
--library unisim;
--use unisim.vcomponents.all;
--
--
entity COUNT_LC is
    Port (	LCADDR : out std_logic_vector(18 downto 0);
				SYSCLK : in std_logic;
				LCRST : in std_logic;
				LCINCR : in std_logic;
				LCENA : out std_logic;
				WEN : out std_logic
			); 
    end COUNT_LC;

architecture behave of COUNT_LC is

signal 		delay_count	: std_logic_vector (2 downto 0 );
signal 		addr_count	: std_logic_vector (18 downto 0);
signal 		write_ena 	: std_logic;
signal 		lcinc_del 	: std_logic;

begin
	LCADDR <= addr_count;
	WEN <= not write_ena;

	addr_counter : process (write_ena, LCRST )
	-- Adresszähler für Auto-Increment
	begin
		if LCRST = '1' then
			addr_count <= (others =>'0');
		elsif (write_ena'event and write_ena = '0') then
			addr_count<= addr_count+1;
		end if;
	end process;
		
	write_pulse : process (LCINCR,SYSCLK,LCRST)
	-- Schreibimpuls für langsames SRAM auf 80 ns verlängern 
	begin
		if LCRST = '1' then
			write_ena <= '0';
			delay_count <= (others =>'0');
			LCENA<='0';
		else
			if (SYSCLK'event and SYSCLK = '1') then
				lcinc_del<=LCINCR; -- zusätzliche Setup-Zeit
				if (LCINCR ='1') then -- Counter-Freigabe sofort
					LCENA<='1';
				end if;
				if (write_ena='1') or (lcinc_del ='1') then -- Impuls und Zähler starten
					if delay_count(2) = '1' then
						write_ena <= '0';				
						delay_count <= (others =>'0');
					else
						write_ena <= '1';				
						delay_count <= delay_count+1;
					end if;
				end if;
			end if;		
		end if;
	end process;

end behave;
