2

Here is the code:

wait for 1 ns;

print("x is checked, last changed at " & time'image(x'last_event));
wait for 10 ns;
print("x is checked, last changed at " & time'image(x'last_event));
wait for 100 ns;
print("x is checked, last changed at " & time'image(x'last_event));
wait for 100 ns;
print("x is checked, last changed at " & time'image(x'last_event));
wait for 100 ns;
print("x is checked, last changed at " & time'image(x'last_event));

The print command is from VUnit. It just prints to stdout.

Here is the result:

# ** Note: (vsim-12125) Error and warning message counts have been reset to '0' because of 'restart'.
# ** Note: (vsim-8009) Loading existing optimized design _opt
# ** Note: (vsim-12126) Error and warning message counts have been restored: Errors=0, Warnings=2.
# x is checked, last changed at 1000 ps
# x is checked, last changed at 11000 ps
# x is checked, last changed at 11000 ps
# x is checked, last changed at 61000 ps
# x is checked, last changed at 61000 ps

The time values are printed in ps. What is the method to change the output to use a different time unit like ns or us? I could do this by writing my own function of course. However, there must be something that can be done via the tool settings or using VHDL attribute perhaps.

gyuunyuu
  • 1,933
  • 7
  • 31
  • 1
    Not sure about changing time unit dynamically. But the time unit can be set at simulation by passing time precision flag to `vsim -t ns ....` – Mitu Raj Jul 12 '22 at 14:32
  • 1
    @MituRaj That would work - however ... The issue is that to_string([time]) uses the simulator resolution as the unit. That is not too stable as you may need to run gate sims in ps. Hence, using `to_string([time], [time units]) ;` will serve you better. – Jim Lewis Jun 19 '23 at 14:16

1 Answers1

4

Use to_string (vhdl-2008) instead of 'image and specify the time units. Hence, for ns it is:

print("x is checked, last changed at " & to_string(x'last_event, 1 ns));
wait for 10 ns;
toolic
  • 5,637
  • 5
  • 20
  • 33
Jim Lewis
  • 894
  • 4
  • 10
  • Note: only use 1 with your preferred unit (1 ns) or completely exclude the number (ns). Don't try something like 10 ns. print(to_string(15 ns, 10 ns)) will give you an error in GHDL, 15 ns with Riviera-PRO and Active HDL, and 0.015 us in ModelSim!!! – lasplund Jul 12 '22 at 22:10
  • @lasplund Exciting stuff. – Jim Lewis Jul 12 '22 at 22:12