HDLParsers:800 Type" **"与" **"的类型不相容

时间:2014-12-31 07:30:22

标签: vhdl xilinx xilinx-ise

entity address_decoder is
PORT(address : in STD_LOGIC_VECTOR ( 0 to 3 );
  decoded_address : out integer range 0 to 15);
end address_decoder;

architecture dataflow of address_decoder is
begin
PROCESS(address)
begin
    if address = "0000" then decoded_address <= '0';
    elsif address = "0001" then decoded_address <= '1';
    elsif address = "0010" then decoded_address <= '2';
    elsif address = "0011" then decoded_address <= '3';
    elsif address = "0100" then decoded_address <= '4';

这是即将发生的错误

错误:HDLParsers:800 decode_address类型与&#39; 0&#39;的类型不兼容。 错误:HDLParsers:800 decode_address类型与&#39; 1&#39;的类型不兼容。 错误:HDLParsers:800 decode_address类型与&#39; 2&#39;的类型不兼容。 错误:HDLParsers:800 decode_address类型与&#39; 3&#39;的类型不兼容。 错误:HDLParsers:800类型的decoding_address与&#39; 4&#39;的类型不兼容。

是因为address和decoding_address是两种不同的数据类型吗?关于如何摆脱这个错误的任何想法?

2 个答案:

答案 0 :(得分:1)

提供此答案是因为Stackoverflow上其他7次出现的ERROR:HDLParsers:800不涉及分配给整数类型的文字,而Morten认为对该问题的实际答案可能很有价值。与答案最接近的匹配问题(参见VHDL: Type of “variable” is incompatible with type of <=)涉及具有位串字面值的整数赋值目标。)

在这个if语句中(缺少并结束if):

if address = "0000" then decoded_address <= '0';
elsif address = "0001" then decoded_address <= '1';
elsif address = "0010" then decoded_address <= '2';
elsif address = "0011" then decoded_address <= '3';
elsif address = "0100" then decoded_address <= '4';

显示的if语句部分应如下所示:

if address = "0000" then decoded_address <= 0;
elsif address = "0001" then decoded_address <= 1;
elsif address = "0010" then decoded_address <= 2;
elsif address = "0011" then decoded_address <= 3;
elsif address = "0100" then decoded_address <= 4;

decode_address之间存在类型不匹配,它被声明为约束整数,范围为0到15,字符文字为'0','1','2','3'和'4'。

更正后的if语句端口将数字文字(与类型整数兼容)分配给decoding_address。请注意,所有五个值都在decode_address的范围约束内。

答案 1 :(得分:0)

除了@David Koontz回答,你可以使用case语句代替。

case address is when "0000" => decoded_address <= 0; when "0001" => decoded_address <= 1; when "0010" => decoded_address <= 2; when "0011" => decoded_address <= 3; when others => decoded_address <= 4; end case;

并且永远不会忘记涵盖所有条件。


顺便说一下,我不知道这是不是讲课,但你可以使用

decoded_address <= to_integer(unsigned(address));

当然你需要添加 use ieee.numeric_std.all