The word time in VHDL
Asked Answered
N

2

5

I am new to VHDL. There is a line, given below:

constant TIME_DELTA : time := 100 ns;

What is this word time in the line? Is it data type just like integer? As I searched VHDL help around internet, many people use it, but no body discusses any thing about it. I searched books as well, but no use. Can some body explain how is this keyword time is used?

Nankeen answered 30/8, 2018 at 7:44 Comment(8)
It's a datatype: csee.umbc.edu/portal/help/VHDL/types.htmlIntertype
Just to be clear... time is NOT synthesizable. It's only for simulation code.Kibler
It's not a keyword. See IEEE Std 1076-2008 15.10 Reserved words. It's an identifier (15.4 Identifiers) and from context it's the name of a type. The meaning of an identifier depends on visibility (12.3), this one comes from a use clause (12.4) which is unfortunately (for you) in this case implicit (13.2) for package STANDARD (16.3). Finding a free reference ("Use of the STANDARD package is implicitly assumed by every VHDL simulator and compiler and need not to be explicitly declared by the 'use' clause.") is a bit iffy.Edmundedmunda
@Kibler It depends on what you do with the constant of type time. If you use it to calculate a counter threshold for example, it is of course synthesizable. Using it in a wait statement will in deed not be synthesizable.Hepler
@Hepler what do you mean to calculate a counter threshold? Do you just mean using it in place of an integer?Kibler
@Kibler Suppose you have a constant of type time defining your clock period. And you have a constant/generic of type time defining some timeout condition. You can use both time constant in your code to calculate how much clock cycles need to pass until the timeout condition is reached and use that values as an counter threshold. The threshold itself will of course be an interger. I just wanted to make clear that you can write synthesizable code with time constants, it just depends on how you use them :)Hepler
@Kibler you can use time in synthesis. You can even define more physical types like frequency, baudrate or memory and create an arithmetic and conversions for such types. The PoC-Library offers a physical package with such types, operations, conversions and helper functions.Reis
@Hepler you're right I did forget about that possible use case. Thanks for the explanation.Kibler
B
5

Time is a Predefined physical types

IEEE Std 1076™-2008 :

5.2.4.2 Predefined physical types

The only predefined physical type is type TIME. The range of TIME is implementation dependent, but it is guaranteed to include the range –2147483647 to +2147483647. It is defined with an ascending range. All specifications of delays and pulse rejection limits shall be of type TIME. The declaration of type TIME appears in package STANDARD in Clause 16.

By default, the primary unit of type TIME (1 fs) is the resolution limit for type TIME. Any TIME value whose absolute value is smaller than this limit is truncated to zero (0) time units. An implementation may allow a given elaboration of a model (see Clause 14) to select a secondary unit of type TIME as the resolution limit. Furthermore, an implementation may restrict the precision of the representation of values of type TIME and the results of expressions of type TIME, provided that values as small as the resolution limit are representable within those restrictions. It is an error if a given unit of type TIME appears anywhere within the design hierarchy defining a model to be elaborated, and if the position number of that unit is less than that of the secondary unit selected as the resolution limit for type TIME during the elaboration of the model, unless that unit is part of a physical literal whose abstract literal is either the integer value zero or the floating-point value zero.

I understand it, on the simulator side, as an integer value which represents the time with a resolution of the primary limit (1fs for example).
It can be expressed in your code with real values representation with bigger time with a bigger timescale :

-- time1 and time2 are equal
signal time1 : time := 1000.125 ms;
signal time2 : time := 1000125 us;
Bader answered 30/8, 2018 at 7:57 Comment(1)
Overall a good effort. (1fs for example) 5.2.4.1 "physical_literal ::= [ abstract_literal ] unit_name", both a primary unit and secondary unit name are identifiers. 15.3 Lexical elements, separators, and delimiters At least one separator is required between an identifier or an abstract literal and an adjacent identifier or abstract literal. Modelsim not withstanding. Also the trade mark is for a particular font for 1076 excluding italics. It only shows up in three places in the LRM.Edmundedmunda
M
4

time is just a datatype. In your case, constant TIME_DELTA : time := 100 ns; could be used as a delay in a signal assignment, for example:

architecture some_arch of some_ent is
    constant TIME_DELTA: time := 100 ns;
begin
    dclk <= clk after TIME_DELTA;
end some_arch;
Mesoglea answered 30/8, 2018 at 14:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.