FPGA Intellectual Property
PCI Express*, Networking and Connectivity, Memory Interfaces, DSP IP, and Video IP
6670 Discussions

Problem with integer variable and vector range

Altera_Forum
Honored Contributor II
1,315 Views

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.
0 Kudos
7 Replies
Altera_Forum
Honored Contributor II
508 Views

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.
0 Kudos
Altera_Forum
Honored Contributor II
508 Views

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

0 Kudos
Altera_Forum
Honored Contributor II
508 Views

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;
0 Kudos
Altera_Forum
Honored Contributor II
508 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
508 Views

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.

0 Kudos
Altera_Forum
Honored Contributor II
508 Views

Ok, so can you help me with an alternative solution?

0 Kudos
Altera_Forum
Honored Contributor II
508 Views

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
0 Kudos
Reply