Tuesday 8 August 2017

RAM 16 x 1024 - Using 'to_integer'




library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.numeric_STD.ALL;
entity RAM_16_x_1024 is
    Port ( Data_in : in  STD_LOGIC_VECTOR (15 downto 0);
           Address : in  STD_LOGIC_VECTOR (9 downto 0):="0000000000";
           Read_Write,clk : in  STD_LOGIC;
           Data_out : out  STD_LOGIC_VECTOR (15 downto 0));
end RAM_16_x_1024;
architecture Behavioral of RAM_16_x_1024 is
type ramm is array(2**(Address' length)-1 downto 0) of std_logic_vector(2**(Data_in' length)-1 downto 0);
signal temp:ramm;
begin
process(clk,Data_in)
begin
if clk='0' and clk'event then
if Read_Write='1' then
temp(to_integer(unsigned(Address)))<=Data_in;
end if;
end if;
end process;
Data_out<=temp(to_integer(unsigned(Address)));
end Behavioral;

No comments:

Post a Comment