Question

It shows me an error: ERROR:Xst:787 - "E:/tumama/tytyty.vhd" line 54: Index value <4> is not in Range of array .

Its a "generic" code, my embedded signal A has the 5 bits of n I only want to use 4 bits to convert in a case. So i have 4 bits in Y The comments are for the concurrent code

but i dont get it Thanks

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;
Était-ce utile?

La solution

When your loop index i reaches the value n-1 then you are trying to access Num(n). However, Num is only defined for the range of (n-1 downto 0).

A Numeric example would be for n=4, as is your default case:
You generate for i values from 1 to 3, but access Num(i+1), therefore Num(4). But, as stated above, Num is only defined in the range 3 downto 0.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top