【问题标题】:HDLParsers:800 Type of "**" is incompatible with type of "**"HDLParsers:800 “**”类型与“**”类型不兼容
【发布时间】:2014-12-31 20:08:03
【问题描述】:
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';

这是即将发生的错误

ERROR:HDLParsers:800 decoded_address 类型与“0”类型不兼容。 错误:HDLParsers:800 decoded_address 类型与“1”类型不兼容。 错误:HDLParsers:800 decoded_address 类型与“2”类型不兼容。 错误:HDLParsers:800 decoded_address 类型与“3”类型不兼容。 ERROR:HDLParsers:800 decoded_address 类型与“4”类型不兼容。

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

【问题讨论】:

  • 这不是因为 address 和 decoded_address 是不同的类型,而是因为 decoded_address 和 '1'、'2'、'3' 和 '4' 是不同的类型:你试图将一个字符分配给一个整数信号。
  • 去掉'0'、'1'、'2'、'3'和'4'中的单引号。 decoded_address 的类型是整数,您尝试为其分配字符文字。改为分配与 decoded_address 的范围约束兼容的数字文字。一般来说,在 XST 之前在 ISIM 或 Modelsim 中分析设计规范是一种很好的工作实践,其中错误消息有时可能缺乏此条的清晰性。
  • @DavidKoontz:您的评论解决了问题中的确切问题,因此将其发布为答案而不是评论不是更好,这样其他人就可以看到问题有答案,然后它可能会被正确关闭?
  • 您的组件正在对二进制编码的数字进行简单的类型转换。这可以重写为一行:decoded_address &lt;= to_integer(unsigned(address)); 所以如果你的组件现在只有一行代码,你应该省掉它。
  • 删除单引号确实有帮助。谢谢

标签: vhdl xilinx xilinx-ise


【解决方案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 语句端口将数字文字(与整数类型兼容)分配给 decoded_address。请注意,所有五个值都在 decode_address 的范围约束内。

【讨论】:

    【解决方案2】:

    除了@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 &lt;= to_integer(unsigned(address));

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

    【讨论】:

      猜你喜欢
      • 2022-01-11
      • 1970-01-01
      • 2022-01-22
      • 1970-01-01
      • 1970-01-01
      • 2011-03-31
      • 2018-08-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多