How do you cast an integer as a time in VHDL?
multiply (or operate otherwise) by the time unit
constant t_per : time := (1 / input_frequency * 1000000000) * 1ns; (or variations thereof)
You can convert integer values to type time values. Each time value is represented as a position number on the number scale. Therefore, VHDL offers the attributes
'pos(...). Each integer unit represents one primary time unit. This primary unit is defined as femtosecond (fs). But many simulators like ModelSim chose a greater primary unit like picosecond (ps). You can set this minimum time resolution limit to femtoseconds with command line option
Converting integers to time:
constant myInt : integer := 10000; constant myTime : time := time'val(myInt);
This is equal to
10 ps, because it's 10,000 fs. You can convert back with attribute
'pos from a physical type value to a universal integer value.
The same can be achieved by multiplying time values with an integer, because package
std.standard contains operator overloads for
* to allow
time * integer and
integer * time operations.
constant myInt : integer := 5; constant myTime : time := 10 ns * myInt;
This results in 50 ns. Of cause there are more operators overloaded like division or modulo.
If you like to play more with type time or experience other physical type like frequency, have a look at the PoC Library and package PoC.physical.