# Use floating values in VHDL code

Assume I want to have a continous sine signal as input to my VHDL code. The values will be of type float since it will take on non-integer values for example: 10.5 mA.

How do I manage these numbers in my VHDL code?

I have tried to use: type Voltage_Level is range -5.5 to +5.5; as an example but it did not work since i couldn't import signed vector into Voltage_level since Voltage_level must be represented as a signal.

I would appreciate if someone could help with these kind of issues? What is the most easiest way to deal with this?

The basic problem is when I input non-integer values, say 10.5 and try to use the same value as input the FPGA outputs a rounded integer, in this case 10. So it seems that I can use VHDL only when i deal with integers and bit vectors, which is very limiting use scenario. Especially for people like me that work a lot with various kinds of signals.

• 10.5 mA is 1050 µA. Voilà! An integer. Or, you might choose to think of it as 21 half milliamperes, or 42 quarter milliamperes. Also, both integers. The solution to your problem could just be a matter of choosing the right scale factor. – Solomon Slow Dec 11 '17 at 18:21
• Rather than hacking things to make integers fit (which is viable but maybe ugly) you can use the synthesisable fixed point (or floating point) libraries in VHDL-2008. If it's simulation only, just declare subtype Voltage_level is real range -5.5 to 5.5; – Brian Drummond Dec 11 '17 at 18:38
• @SolomonSlow Just a slight mistake: 10.5 mA is 10500 µA not 1050µA, that'd be 1.05 mA. – ArtificialSoul Jan 21 at 12:32