Reputation: 65
logic index : unsigned(9 downto 0) ;
type fft_data is array (3 downto 0) of unsigned(16 downto 0);
signal tmp,signal fmax_data :fft_data;
tmp = fmax_data(to_integer(index(9)));
Above part of the code gives following compilation error; "subprogram call or operator argument type mismatch 87"
if I do following modification it works.
logic index : unsigned(9 downto 0) ;
type fft_data is array (3 downto 0) of unsigned(16 downto 0);
signal tmp,signal fmax_data :fft_data;;
tmp = fmax_data(to_integer(index(**9 downto 9**)));
Can anyone please explain what is the difference between above two implementation? I am using vhdl-93 std and ncvhdl. Thank you
Upvotes: 4
Views: 425
Reputation: 166
In numeric_std
, the to_integer
function is only defined for unsigned
and signed
type.
Unsigned is derived from std_logic
as type UNSIGNED is array ( NATURAL range <> ) of STD_LOGIC;
When you use to_integer(index(9))
you are passing index(9)
which is of type std_logic
.
When you use to_integer(index(9 downto 9))
you are passing a range of index
which is of size 1, however, it is an unsigned
type.
You can also create your custom function if you want. To convert std_logic
to integer
.
function to_integer (ARG : std_logic)
return integer is
begin
if ARG = '1' OR ARG = 'H' then
return 1;
else
return 0;
end if;
end function to_integer;`
OR wrap around to_integer
function to_integer (ARG : std_logic)
return integer is
variable t : unsigned(0 downto 0) := "0";
begin
t(0) := ARG;
return to_integer(t);
end function to_integer;
Upvotes: 4