Question

My compiler is giving me these errors:

# Error: COMP96_0305: SUBONE_MODULE_VHDL.vhd : (93, 23): Cannot find function "TO_INTEGER" for these actuals.

# Error: COMP96_0138: SUBONE_MODULE_VHDL.vhd : (93, 23): The index types in the reference to the array object are incompatible with its range type.**

library IEEE;
use IEEE.STD_LOGIC_1164.all;

use IEEE.NUMERIC_STD.all;


entity SUBONE_MODULE_VHDL is
 port(
     addr : in STD_LOGIC_VECTOR(4 downto 0);
     clk : in STD_LOGIC;
     dout : out STD_LOGIC_VECTOR(4 downto 0)
     );
end SUBONE_MODULE_VHDL;


architecture SUBONE_MODULE_VHDL of SUBONE_MODULE_VHDL is     

type ROM_Array is array (0 to 31) 
of std_logic_vector(4 downto 0);


constant Content: ROM_Array := (
    0 => "10011",       -- Suppose ROM has 
    1 => "00000",       -- prestored value
    2 => "00001",       -- like this table
    3 => "00010",               --
    4 => "00011",       --
    5 => "00100",               --
    6 => "00101",       --
    7 => "00110",               --
    8 => "00111",               --
    9 => "01000",               --
   10 => "01001",       --
   11 => "01010",           --
   12 => "01011",           --
   13 => "01100",       --
   14 => "01101",       --
   15 => "01110",       --
   16 => "01111",       --
   17 => "01110",       --
   18 => "01110",       --
   19 => "01110",       --
   20 => "01110",       --
   21 => "00000",       --
   22 => "00001",       --
   23 => "00010",       --
   24 => "00011",       --
   25 => "00100",       --
   26 => "00101",       --
   27 => "00110",       --
   28 => "00111",       --
   29 => "01000",       --
   30 => "01001",       --
   31 => "01010",       --
 OTHERS => "00000"
);       

begin
    process(clk, addr) 
    variable addr : integer := 0;   
    begin
        if( clk'event and clk = '1' ) then
            dout <= Content(TO_INTEGER(addr));
        end if;
    end process;

end SUBONE_MODULE_VHDL;

No correct solution

OTHER TIPS

The port addr is a std_logic_vector and can not be cast directly to integer. cast it to unsigned or signed first:

dout <= Content(TO_INTEGER(SIGNED(addr)));

EDIT: There is also a conflict with the variable named addr and the port of same name. Therefore, renaming the variable to e.g. addr_var will fix the problem. In this case no type cast is necessary.

variable addr_var : integer := 0;
...
dout <= Content(addr_var);

Which of the two solutions is the right one for you depends on which addr you intented to use while accessing CONTENT.

Generally, reusing the exact same name for ports, signals or variables is a bad idea.

There is a name clash between "addr" (the integer variable, for which TO_INTEGER is obviously not defined) and "addr" (the port) which is a "bag of bits" and as such, again has no TO_INTEGER method. If the latter were Unsigned (or Signed) types from numeric_std, or you cast the STD_LOGIC_VECTOR to unsigned, then you would have something numeric on which TO_INTEGER would work.

My preference would be to eliminate the variable "addr" and to make the "addr" port Unsigned, or even Natural (a non-negative form of Integer).

Incidentally, "addr" need not (and should not) be part of the process sensitivity list.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top