2015-05-21 25 views
1

我試圖使用RAM來讀/寫。我的地址是一個整數值,它應該是一個整數的內存。這是我的代碼在下面,但我不斷收到錯誤。RAM在VHDL中讀寫

這是從我的數據路徑中,地址選擇來自整數寄存器。

代碼:

library ieee; 
use ieee.std_logic_1164.all; 
use ieee.std_logic_arith.all; 
use ieee.std_logic_unsigned.all; 

entity Mem is 
generic( width: integer:=4; 
     depth: integer:=4; 
     addr: integer:=2); 
port( Clock:  in std_logic; 
    Enable:  in std_logic; 
    Read:  in std_logic; 
    Write:  in std_logic; 
    Read_Addr: in integer; 
    Write_Addr:  in integer; 
    Data_in: in integer; 
    Data_out: out integer 
); 
end Mem; 

-------------------------------------------------------------- 

architecture behav of Mem is 

type ram_type is array (0 to 31) of 
    integer; 
signal tmp_ram: ram_type; 

begin 

    -- Read Functional Section 
    process(Clock, Read) 
    begin 
    if (Clock'event and Clock='1') then 
     if Enable='1' then 
     if Read='1' then 
      -- buildin function conv_integer change the type 
      -- from std_logic_vector to integer 
      Data_out <= tmp_ram(conv_integer(Read_Addr)); 
     else 
      Data_out <= (Data_out'range => 'Z'); 
     end if; 
     end if; 
    end if; 
    end process; 

    -- Write Functional Section 
    process(Clock, Write) 
    begin 
    if (Clock'event and Clock='1') then 
     if Enable='1' then 
     if Write='1' then 
      tmp_ram(conv_integer(Write_Addr)) <= Data_in; 
     end if; 
     end if; 
    end if; 
    end process; 

end behav; 
---------------------------------------------------------------- 

錯誤:

Error (10514): VHDL aggregate error at Mem.vhd(41): can't determine type of aggregate -- found 0 possible types 

回答

2

錯誤代碼是:

if Read='1' then 
    -- buildin function conv_integer change the type 
    -- from std_logic_vector to integer 
    Data_out <= tmp_ram(conv_integer(Read_Addr)); 
else 
    Data_out <= (Data_out'range => 'Z'); -- Faulty line 
end if; 

Data_out是一個整數,而不是一個或std_logic_vector派生類型。因此,它沒有範圍(只有數組,std_logic_vector beeing被定義爲std_logic的數組)。此外,它不能取'Z'的值,因爲它不是std_logic; integers只能分配整數值。

如果需要Data_out成爲高阻抗時enable'1'read'0'如你所述,你需要你的記憶輸出使用std_logic_vectorsigned/unsigned

另外,如果你的目標是綜合,我應該勸你不要使用integers。按照VHDL標準,integers是32位。綜合工具可能優化網表並使用較少的位,但你不應該指望它。要麼限制您的integerssignal x: integer range -4 to 3)或使用signed/unsigned的範圍。

+0

如果我想使用雙打而不是整數?意味着64位。 –

+0

雙重意味着浮點數,所以我假設您的意思是四字,64位整數?它們不是以VHDL中的整數存在,你必須使用'signed/unsigned'或'std_logic_vector'。例如,'signal x:signed(63 downto 0)'。 –

+0

所以信號x:signed(63 downto 0)意味着64位的整數?如雙?是不是認爲二進制不是int? –