Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

Problem with integer variable and vector range

My code:

Int is an Integer Variable

OutputNumber is a Std_logic_Vector Input

Int <= conv_integer(OutputNumber);

MyVector(37 downto (38-Int)) <= Temp(37 downto (38-Int));

Quartus Compiler Error:

Error (10454): VHDL syntax error: right bound of range must be a constant

PLEASE HELP ME.

7 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    The VHDL standard does not allow the right-hand side of downto expresions to contain a variable.

    Just use a constant instead of a Int Integer variable.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks for reply, but i don't know the value of Int. I must convert the "OutputNumber" input to know the value of Int.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    From your code snippet, it's not fully clear, what you want to achieve. If you want to copy a variable number of bits depending on another condition, you can use a for loop iteration scheme.

    for i in 0 to 37 loop
      if i >= 38 - int then
        MyVector(i) <= Temp(i);
      end if;
    end loop;
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hello,

    "OutputNumber" is a Std_logic_Vector(5 downto 0). It is a vector that store the number of output (eg.: "000000" means no outputs; "01010" means 10 outputs and so on....)

    The integer variable "Int" store the equivalent integer value: No outputs: Int:=0; 10 outputs: Int:=10 and so on.....

    "Temp" is a 38bit vector, but i need to copy only a range to "MyVector"

    Int <= conv_integer(OutputNumber);

    MyVector(37 downto (38-Int)) <= Temp(37 downto (38-Int));

    Quartus Compiler Error:

    Error (10454): VHDL syntax error: right bound of range must be a constant
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Amilcar has already explained, that your code isn't valid VHDL. Try as I suggested or use a similar construct according to VHDL syntax rules.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    FvM already gave you an alternative solution.

    One other solution would be:

    if (OutputNumber == "000000") then

    MyVector(37 downto (38-0)) <= Temp(37 downto (38-0)); <- This is wrong because your code was wrong

    end

    if (OutputNumber == "000001") then

    MyVector(37 downto (38-1)) <= Temp(37 downto (38-1));

    end

    if (OutputNumber == "000010") then

    MyVector(37 downto (38-2)) <= Temp(37 downto (38-2));

    end

    if (OutputNumber == "000011") then

    MyVector(37 downto (38-3)) <= Temp(37 downto (38-3));

    end

    if (OutputNumber == "000100") then

    MyVector(37 downto (38-4)) <= Temp(37 downto (38-4));

    end

    ...

    if (OutputNumber == "01010") then

    MyVector(37 downto (38-10)) <= Temp(37 downto (38-10));

    end

    There is no need to use conv_integer. And pleas use numeric_std instead of standard_arith