0

I need a function that will convert a signal (number) to string, in order to be able to display it on LCD. Unfortunately, I have to use Xilinx ISE 14.7 because Spartan 6 is not supported in Vivado, which does not support VHDL 2008.

Is there any alternative for to_string() function in VHDL 2002, or I have to implement my own function?

I can't use integer'image() on signals. For example:

signal counter : integer := 0;
integer'image(counter);

produces a compilation error: "Expression is not constant". I know there are a lot of options, for instance, converting the integer to BCD representation. I just want to know is there a simple and elegant solution to this problem.

Marko Gulin
  • 509
  • 3
  • 6
  • 19
  • 2
    You can write a normal VHDL function to transform the input data to a new output data. You can find an implementation in the [PoC Library](https://github.com/VLSI-EDA/PoC) in package [utils](https://github.com/VLSI-EDA/PoC/blob/release/src/common/strings.vhdl?ts=2#L413). – Paebbels Nov 06 '17 at 22:24
  • 2
    If the signals have type `integer`, of course you can use`integer'image` (at least in VHDL. I suppose it's possible that ISE doesn't support enough VHDL for that, though.) –  Nov 06 '17 at 22:28
  • 2
    Vivado does support vhdl 2008. Just not all of it. – JHBonarius Nov 07 '17 at 07:27
  • 2
    It's not hard to implement `function to_string (inp: std_logic_vector) return string is variable image_str: string (1 to inp'length); alias input_str: std_logic_vector (1 to inp'length) is inp; begin for i in input_str'range loop image_str(i) := character'VALUE(std_ulogic'IMAGE(input_str(i))); end loop; return image_str; end function;` IEEE Std 1076-2008, 5.3.2.4 Predefined operations on array types, 5.7 String representations. Or do you have specific types and representations in mind? –  Nov 07 '17 at 08:29
  • 1
    You can use `integer'image()` on signals. You can't use `image()` on non-scalar types (arrays, records). – Matthew Taylor Nov 07 '17 at 09:03
  • Thank you all for your answers. If I use `integer'image()` on a signal I get a compilation error: "Expression is not constant", even with the function proposed by @user1155120 – Marko Gulin Nov 07 '17 at 09:14
  • 1
    @JHBonarius It seems that Xilinx is really trying to make you use Altera products. ISE 14.7 is not supported on Windows 8/10, and it doesn't support VHDL 2008. On the other hand, Vivado doesn't support Spartan 6 chips, which were released in 2009! – Marko Gulin Nov 07 '17 at 09:20
  • See [Integer to String goes wrong in Synthesis (Width Mismatch)](https://stackoverflow.com/questions/20667051/integer-to-string-goes-wrong-in-synthesis-width-mismatch/20670059). 'image(x) doesn't return a value with fixed length for non-static values. to_signed/unsigned [integer return signed/unsigned] can work with static subtype parameters, they're in synthesis libs. Without to_string in a synthesis lib synthesis doesn't know the length relationship. A to_string would have to have a parameter with a static subtype indication and a static subtype as the return type mark to work. Doable. –  Nov 07 '17 at 10:27
  • @MarkoGulin 2009 is **8** years ago man! In that time I changed jobs 3 times, moved 2 times, changed girlfriend 4 times, married the last and we got a child together. You can switch to the Spartan-7 nowadays. – JHBonarius Nov 07 '17 at 11:40

0 Answers0