VHDL代码错误
我用VHDL编写了一个串行加法器的代码。我试图让它工作,但我不断地得到一个错误,它说: 在VHDL文件中发现错误- 第17行,错误:子类型指示中预期有索引约束 此错误与以下行有关:VHDL代码错误,vhdl,Vhdl,我用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
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;
ieee库;
使用ieee.std_logic_1164.all;
实体加法器是
港口(
启动:在标准逻辑中;
clk:标准逻辑中;
输出:输出标准逻辑向量(3到0)
);
末端加法器;
介绍了加法器的结构特点
信号a、b:标准逻辑向量(3到0);
信号移位:标准逻辑;
信号Cin,Cout:std_逻辑;
信号和:标准逻辑;
信号状态,下一个状态:整数范围0到3;
开始
在中求和,试着用:
信号状态,下一个状态:整数范围为0到3代码>
如果指定范围,则应使用is-range
而不是range
您使用的工具是什么?您的代码可以很好地使用ModelSim进行分析,也可以很好地使用Quartus 13.1进行分析和合成。在什么上下文中(什么工具0?您的代码是有效的VHDL并进行分析。您似乎遇到了工具限制。请注意,如果不初始化a和b,这在模拟过程中不会产生任何有趣的效果。我正在使用Edwinxp。它有一个允许VHDL到原理图转换的函数。我正在尝试使用它,但没有任何效果。似乎是工具限制,我t不接受受约束的整数标量。如果从整数中删除约束并在case语句中添加其他选项,会发生什么情况?您还可以尝试为state和next state使用枚举类型。首先,您可以尝试替换为子类型integer\u 0\u到\u 3为整数范围0到3;信号状态,next\u状态:integer_0到3;
,但在您尝试之前,很难说它是否能解决该bug。