2015-02-08 167 views
0

我宣佈一個矩陣,這樣在我的TOP文件的信號:傳遞一個二維數組(2D)的功能VHDL

type scanImage is array (0 to 7,0 to 7) of std_logic_vector(2 downto 0); 
signal image_matrix : scanImage; 

現在,我想上面的信號發送到功能它計算矩陣中不是「000」的單元的數量。

我的包看起來像這樣:


library IEEE; 
use IEEE.std_logic_1164.all; 
use IEEE.std_logic_unsigned.all; 
use IEEE.std_logic_arith.all; 
use IEEE.NUMERIC_STD.ALL; 
USE IEEE.NUMERIC_BIT.ALL; 


PACKAGE my_pack IS 

type double_array is array (0 to 7,0 to 7) of std_logic_vector(2 downto 0); 

--------------------square calculation declaration-------------------------- 
function square_calculation(matrix : double_array) return integer; 


--------------------------------------------------------------------- 
function square_calculation(matrix : double_array) return integer IS 
variable tmp: integer range 0 to 64; 
begin 
    tmp:=0; 
    for i in 0 to 7 loop 

      for j in 0 to 7 loop 
       if matrix(i,j)/="000" then 
        tmp:=tmp+1; 
       end if; 
      end loop; 

end loop; 
return tmp; 

end function square_calculation; 


END my_pack; 

compilizing後我得到這個錯誤: 錯誤(10476):在vision_ctrl.vhd VHDL錯誤(112):識別符的類型「 image_matrix double_array‘型

感謝您幫助我」不與它作爲使用同意’。

+0

**我必須使用類型聲明如上:類型scanImage是std_logic_vector的陣列(0〜7,0〜7)(2 DOWNTO 0);不能用另一種方式 – axcelenator 2015-02-08 10:17:42

+0

在我的頂部,我通過這樣的矩陣:square <= square_calculation(image_matrix); – axcelenator 2015-02-08 10:19:39

回答

3

兩個數組scanImagedouble_array不是相同類型;恰好恰好以相同的方式宣佈。

所以申報image_matrix同類型double_array,而不是做一個新的類型scanImage

signal image_matrix : my_pack.double_array; 

然後你可以用my_pack.square_calculationimage_matrix說法。