2013-09-26 64 views
0

它顯示一個錯誤: 錯誤:Xst:787 - 「E:/tumama/tytyty.vhd」第54行:索引值< 4>不在範圍內數組。通用二進制灰色,灰色二進制轉換器,邏輯錯誤

它是一個「通用」代碼,我的嵌入信號A有5位n 我只想用4位來轉換一個案例。所以,我有4位Y中 的意見是對的併發代碼

,但我不明白 感謝

library IEEE; 
    use IEEE.STD_LOGIC_1164.ALL; 



entity FirstTermExamen is 

    Generic (n: natural := 4); 

    Port (Num : in STD_LOGIC_VECTOR (n-1 downto 0); 
      Sel : in STD_LOGIC; 
      Y : out STD_LOGIC_VECTOR (n-1 downto 0) 
      ); 

end FirstTermExamen; 

architecture Behavioral of FirstTermExamen is 

    signal A: STD_LOGIC_VECTOR (n downto 0); 

begin 

-- --Secuencial Description 
-- Binary_Gray : process(A, Num, Sel) 
--  begin 
-- 
-- --Initial conditions 
-- A(0) <= Num(0); 
-- A(1) <= Num(0) xor Num(1); 
-- 
-- for i in 1 to n-1 loop 
--   if Sel = '1' then A(i+1) <= Num(i) xor Num(i+1); 
--   else    A(i+1) <= A(i) xor Num(i+1); 
--   
--   end if; 
--  
-- end loop; 
-- 
-- for j in 0 to n loop 
--   Y(j)<= A(j); 
--   
--  end loop; 
-- 
--end process Binary_Gray; 

    --Concurrent Description 
    A(0) <= Num(0); 
    A(1) <= Num(0) xor Num(1); 


    Binary_Gray: 
    for i in 1 to n-1 generate 
     begin 
      A(i+1) <= Num(i) xor Num(i+1) when Sel = '1' else 
        A(i) xor Num(i+1); 

     end generate; 

    output: 
     for j in 0 to n generate 
     begin 
      Y(j)<= A(j); 

     end generate; 

end Behavioral; 

回答

2

當你的循環索引i達到值N-1,那麼您嘗試訪問Num(n)。但是,Num僅限於(n-1 downto 0)的範圍。

一個數字的例子是對於n = 4,因爲是默認情況下:
您生成從1至3 i值,但訪問Num(i+1),因此Num(4)。但是,如上所述,Num僅在3 downto 0範圍內定義。