4

I'm getting the following error in ModelSim:

Error: [..]/test1_toVectorAlignment_rtl.vhd(40): Ambiguous type in infix expression; t_RAMXx8 or ieee.std_logic_1164.STD_LOGIC_VECTOR.

ARCHITECTURE rtl OF test1_toVectorAlignment IS
type t_RAMXx8 is array (natural RANGE <>) of std_logic_vector(7 downto 0);
signal RAM28x8: t_RAMXx8(0 to 27);
BEGIN

...

    currentIq<=unsigned(RAM28x8(5)(4 downto 0) & RAM28x8(4));

...

END rtl;

Entity declaration:

ENTITY test1_toVectorAlignment IS

...

    currentIq: out unsigned(12 downto 0);

...

END test1_toVectorAlignment;

Can someone tell me with this information how I can solve this problem?

deinocheirus
  • 1,833
  • 5
  • 26
  • 44

1 Answers1

7

The problem sometimes with arrays of vectors is that the compiler doesn't know if you intend to concatenate two vectors into a single vector, or two vectors into a 2-vector array. You need to tell it what you're intending to concatenate as:

currentIq <= unsigned(std_logic_vector'(RAM28x8(5)(4 downto 0) & RAM28x8(4)));

In this case, since unsigned does not have any such ambiguity in the code you've posted, you could also get away with this shortcut:

currentIq <= unsigned(RAM28x8(5)(4 downto 0)) & unsigned(RAM28x8(4));

But the first method is safer, and better.

A little more explanation:

If you were assigning the result of that concatenation to a signal of type std_logic_vector, there would be no problem, as the concatenation result type would be unambiguous. The problem here specifically is that you are also typecasting in the same expression, so the compiler can't assume what "intermediate" type you wish to concatenate into, even if it's obvious to you that there's only one reasonable choice.

fru1tbat
  • 1,605
  • 9
  • 16
  • 1
    I've tried "type conversion" (without the apostrophe (') after std_logic_vector) instead of "type qualification" (with the apostrophe). Type conversion in this case didn't work. Do you know why that is? – deinocheirus Feb 20 '15 at 22:33
  • 2
    Casting/conversion is, more or less, "make this expression of type into this type". Qualification is "this expression has this type". See the difference? In the former, you're only changing whatever type the expression returns. In the latter, you're defining what the type of the expression *is*. – fru1tbat Feb 21 '15 at 14:22
  • 1
    I didn't ask the follow-up question properly, I'll try again sometime later. – deinocheirus Feb 21 '15 at 18:45
  • 1
    Maybe I didn't do a very good job of explaining - the reason a simple typecast doesn't work is that the compiler can't determine the expression type based on the typecast, i.e. what you're typecasting from. You could be typecasting from anything to `std_logic_vector`, as far as the compiler is concerned. Qualifying determines the type of the expression itself. Is the distinction clear? – fru1tbat Feb 21 '15 at 20:45