Electrical Engineering Asked on November 26, 2021
For the purposes of simplifying a test bench, I would like to set various delays by changing numerical values at the top of the file. I’d like to do something like:
input_frequency : integer := 1000000;
...
constant t_per : time := (1. / input_frequency * 1000000000.) ns;
… which does not compile.
Right now I’m hardcoding:
constant t_per : time := 1000 ns;
I have not been able to get the upper example to work using the variable keyword either.
Is there a way around hardcoding times in VHDL?
For people coming here from google, this answer is useful for convert frequency to time in test benches:
CONSTANT freq : positive := 50E6;
CONSTANT CLKPERIOD : time := (real(1E9)/real(freq)) * 1 ns;
The real() typecast allow more precise values.
Answered by Miguel Risco-Castillo on November 26, 2021
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 'val(...)
and '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 -t 1fs
.
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.
Answered by Paebbels on November 26, 2021
multiply (or operate otherwise) by the time unit
constant t_per : time := (1 / input_frequency * 1000000000) * 1ns;
(or variations thereof)
Answered by CapnJJ on November 26, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP