【问题标题】:VHDL code errorVHDL代码错误
【发布时间】:2016-12-24 12:17:26
【问题描述】:

我有这个 VHDL 串行加法器的代码。我正在尝试让它工作,但我不断收到一条错误消息:

在 VHDL 文件中发现错误 -

第 17 行,错误:子类型指示中预期的索引约束

此错误指的是以下行:

signal state, next_state : integer range 0 to 3;

我不确定为什么会这样。有什么帮助吗?请在下面找到完整的代码。

library ieee;
use ieee.std_logic_1164.all;

entity adder is
 port(
 start : in std_logic;
 clk : in std_logic;
 a_out : out std_logic_vector(3 downto 0)
 );
end adder;

architecture behave of adder is
signal a, b : std_logic_vector(3 downto 0);
signal shift : std_logic;
signal Cin, Cout : std_logic;
signal sum_in : std_logic;
signal state, next_state : integer range 0 to 3;

begin
 sum_in <= a(0) xor b(0) xor Cin;
 Cout <= (Cin and a(0))or(Cin and b(0))or(a(0) and b(0));
 a_out <= a;

 process(state, start)
 begin
  case state is
   when 0 =>
   if start = '1' then shift <= '1'; next_state <= 1;
   else shift <= '0'; next_state <= 2; end if;
    when 1 => shift <= '1'; next_state <= 2;
    when 2 => shift <= '1'; next_state <= 3;
    when 3 => shift <= '1'; next_state <= 0;
   end case;

 end process;

 process(clk)
 begin
  if clk'event and clk = '0' then
   state <= next_state;
   if shift = '1' then
    a <= sum_in & a(3 downto 1);
    b <= b(0) & b(3 downto 1);
    Cin <= Cout;
   end if;
  end if;

 end process;

end behave;

【问题讨论】:

  • 您使用的是哪个工具?您的代码可以使用 ModelSim 很好地分析,也可以很好地使用 Quartus 13.1 进行分析和综合。
  • 在什么情况下(什么工具0?您的代码是有效的 VHDL 并进行分析。您似乎遇到了工具限制。请注意,如果不初始化 a 和 b,这在仿真过程中不会做任何有趣的事情。
  • 我正在使用 Edwinxp。它具有允许 VHDL 到原理图转换的功能。我正在尝试使用它,但无济于事..
  • 似乎是一个工具限制,它不接受受约束的整数标量。如果您从整数中删除约束并在您的案例语句中添加其他选项会发生什么?您还可以尝试枚举类型的状态和下一个状态。
  • 一开始你可以尝试用subtype integer_0_to_3 is integer range 0 to 3; signal state, next_state : integer_0_to_3;替换,但是如果它可以解决这个错误,在你尝试之前很难说。

标签: vhdl


【解决方案1】:

尝试将出现错误的行替换为:
signal state, next_state : integer is range 0 to 3;

如果您指定范围,那么您应该使用is range 而不是range

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多