【问题标题】:Generic Binary-Gray, gray-binary converter, logic error通用二进制-灰度、灰度-二进制转换器、逻辑错误
【发布时间】:2013-09-26 00:14:23
【问题描述】:

它显示了一个错误: 错误:Xst:787 -“E:/tumama/tytyty.vhd”第 54 行:索引值 不在数组范围内。

它是一个“通用”代码,我的嵌入信号 A 有 5 位 n 我只想在一个案例中使用 4 位进行转换。所以我在 Y 中有 4 位 cmets 用于并发代码

但我不明白 谢谢

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;

【问题讨论】:

    标签: vhdl gray-code


    【解决方案1】:

    当您的循环索引 i 达到值 n-1 时,您正在尝试访问 Num(n)。但是,Num 仅针对(n-1 downto 0) 的范围定义。

    一个数字示例是 n=4,这是您的默认情况:
    您为 i 生成从 1 到 3 的值,但访问 Num(i+1),因此访问 Num(4)。但是,如上所述,Num 仅定义在3 downto 0 范围内。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-28
      • 2013-12-16
      • 1970-01-01
      • 1970-01-01
      • 2022-01-05
      • 1970-01-01
      • 2023-01-30
      • 2014-01-01
      相关资源
      最近更新 更多