Imagine you wanted to convert integers to strings in VHDL to display on a VGA monitor. You can't use ieee 2008 standard though because you have to use xilinx ISE 14.7. I have the following code for converting an integer type to a string type but I get "Non-static loop limit exceeded" errors for the while loop and in the for loop:
-- convert integer to string using specified base
-- (adapted from Steve Vogwell's posting in comp.lang.vhdl)
function str(int: integer; base: integer) return string is
variable temp: string(1 to 10);
variable num: integer;
variable abs_int: integer;
variable len: integer := 1;
variable power: integer := 1;
begin
-- bug fix for negative numbers
abs_int := abs(int);
num := abs_int;
while num >= base loop -- Determine how many
len := len + 1; -- characters required
num := num / base; -- to represent the
end loop ; -- number.
for i in len downto 1 loop -- Convert the number to
temp(i) := chr(abs_int/power mod base); -- a string starting
power := power * base; -- with the right hand
end loop ; -- side.
-- return result and add sign if required
if int < 0 then
return '-'& temp(1 to len);
else
return temp(1 to len);
end if;
end str;
I 'solved' the errors by morphing it to be this monstrosity:
-- convert integer to string using specified base
-- (adapted from Steve Vogwell's posting in comp.lang.vhdl)
function str(int: integer; base: integer) return string is
variable temp: string(1 to 9);
variable num: integer;
variable abs_int: integer;
variable len: integer := 1;
variable power: integer := 1;
begin
-- bug fix for negative numbers
abs_int := abs(int);
num := abs_int;
for i in 0 to 100 loop
if (num >= base) then -- Determine how many
len := len + 1; -- characters required
num := num / base; -- to represent the
else -- number.
exit;
end if;
end loop ;
for i in 9 downto 1 loop -- Convert the number to
if (i <= len) then
temp(i) := chr(abs_int/power mod base); -- a string starting
power := power * base; -- with the right hand
else
exit;
end if;
end loop ; -- side.
-- return result and add sign if required
if int < 0 then
return '-'& temp(1 to len);
else
return temp(1 to len);
end if;
end str;
Is there a non-retarded way to convert integers to strings?
'image()
function and thestring
type (in its unconstraint form) for synthesis. This won't work. A little soft-processor seems most appropriate for a task like this (e.g. xilinx picoblaze). It can be done in FPGA logic too, but it won't be the best use of resources ever. – andrsmllr