Epoch in VHDL
A common requirement in programs is getting the number of seconds, milliseconds, or nanoseconds since a specific reference point. In VHDL, we don’t have a built-in concept of Unix epoch, but we can simulate it using a custom function and the now
attribute.
In this VHDL example, we define a constant REFERENCE_TIME
as our “epoch” starting point. We then create a custom function get_elapsed_time
that calculates the time elapsed since this reference point in the specified unit.
In the main process, we:
- Simulate the passage of time using a
wait
statement. - Calculate the elapsed time in seconds, milliseconds, and nanoseconds using our custom function.
- Print the results using
report
statements.
To run this VHDL code, you would typically use a VHDL simulator. The exact commands may vary depending on your simulation environment, but it might look something like this:
Note that VHDL is primarily used for hardware description and simulation, so the concept of “running” a program is different from software languages. The simulation will run the process and report the results based on the simulated time progression.
Next, we’ll look at other time-related tasks in VHDL, such as creating and using custom time types and formats.