Search code examples
vhdlxilinxxilinx-ise

HDLParsers:800 Type of "**" is incompatible with type of "**"


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';

This is the error which is coming

ERROR:HDLParsers:800 Type of decoded_address is incompatible with type of '0'. ERROR:HDLParsers:800 Type of decoded_address is incompatible with type of '1'. ERROR:HDLParsers:800 Type of decoded_address is incompatible with type of '2'. ERROR:HDLParsers:800 Type of decoded_address is incompatible with type of '3'. ERROR:HDLParsers:800 Type of decoded_address is incompatible with type of '4'.

Is it because the address and decoded_address are two different data types? Any idea on how to get rid of this error ?


Solution

  • This answer is provided because the other 7 occurrences of ERROR:HDLParsers:800 on Stackoverflow don't involve literals assigned to integer types, and Morten thinks an actual answer to the question may be valuable. The closest matching question with an answer (See VHDL: Type of “variable” is incompatible with type of <=) involves an integer assignment target with a bit string literal value).

    In this if statement (missing and end 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';
    

    The if statement portion shown should look like:

    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;
    

    There's a type mismatch between decode_address which is declared as a constrained integer with a range of 0 to 15 and the character literals '0', '1', '2', '3' and '4'.

    The corrected if statement port assigns numeric literals (which are compatible with type integer) to decoded_address. Note that all five values fall within the range constraint of decode_address.