You are on page 1of 3

Timeunit and Timeprecision in SystemVerilog

Within a design element, such as a module, program or interface, the time precision specifies how
delay values are rounded before being used in simulation.

The time precision is relative to the time units. If the precision is the same as the time units, then
delay values are rounded off to whole numbers (integers). If the precision is one order of magnitude
smaller than the time units, then delay values are rounded off to one decimal place.

For example, if the time unit specified is 1ns and the precision is 100ps, then delay values are
rounded off to one decimal place (100ps is equivalent to 0.1ns). Thus, a delay of 2.75ns would be
rounded off to 2.8ns.

The time unit and time precision can be specified in the following two ways:
— Using the compiler directive `timescale
— Using the keywords timeunit and timeprecision

Here in this post, we will go in details of second way (timeunit and timeprecision).

The time precision may also be declared using an optional second argument to the timeunit keyword
using the slash separator. For example:

efining the timeunit and timeprecision constructs within the design element removes the file order
dependency problems with compiler directives.

There shall be at most one time-unit and one time-precision for any module, program, package, or
interface definition or in any compilation-unit scope. This shall define a time scope.

The timeunit and timeprecision declarations shall precede any other items in the current time scope.
i.e. timeunit and timeprecision shall be declared either inside module, program, package, interface or
after any item in any compilation-unit scope.

The timeunit and timeprecision declarations can be repeated as later items, but must match the
previous declaration within the current time scope.

If a timeunit is not specified within a module, program, package, or interface definition, then the time
unit shall be determined using the following rules of precedence:
1. If the module or interface definition is nested, then the time unit shall be inherited from the
enclosing module or interface (programs and packages cannot be nested).
2. Else, if a `timescale directive has been previously specified (within the compilation unit), then
the time unit shall be set to the units of the last `timescale directive.
3. Else, if the compilation-unit scope specifies a time unit (outside all other declarations), then
the time unit shall be set to the time units of the compilation unit.
4. Else, the default time unit shall be used.

The global time precision, also called the simulation time unit, is the minimum of,
 All the timeprecision statements,
 All the time precision arguments to timeunit declarations, and
 The smallest time precision argument of all the `timescale compiler directives in the design.

`timescal
e 1ps/1ps

module mod1 (output logic [1:0] a);


timeunit 1ns;
timeprecision 1ps;

task print();
a = 0;
#5; // 5 ns = 5000 ps
a ++;
#1.1234; // 5 ns + 1.123 ns = 6.123 ns = 6123 ps
a ++;
endtask : print
endmodule : mod1

module mod2 (output logic [1:0] b);


//timeunit 10ns/10ps;
timeunit 10ns;
timeprecision 10ps;

task print();
b = 0;
#5; // 50 ns = 50000 ps
b ++;
#1.123; // 50 ns + 10.123 ns = 60.123 ns = 60123 ps
// Not 60120 ps, because 'global time precision' is the minimum of
// all the timeprecision statements,
// all the time precision arguments to timeunit declarations, and
// the smallest time precision argument of all the `timescale compiler
directives in the design.
// Here smallest precision is 1 ps
b ++;
endtask : print
endmodule : mod2

interface intf();
logic [1:0] a;
logic [1:0] b;
logic [1:0] c = 0;
endinterface : intf

module top();
intf if1 ();
mod1 M1 (if1.a);
mod2 M2 (if1.b);

initial begin
M1.print();
end

initial begin
M2.print();
end

initial begin
#5; // 5 ps
if1.c ++;
#1.123; // 5 + 1 ps = 6 ps
if1.c ++;
end

initial begin
$monitor("%t, a=%b, b=%B, c=%b", $realtime, if1.a, if1.b, if1.c);
end
endmodule : top

//Output:
// 0, a=00, b=00, c=00
// 5, a=00, b=00, c=01
// 6, a=00, b=00, c=10
// 5000, a=01, b=00, c=10
// 6123, a=10, b=00, c=10
// 50000, a=10, b=01, c=10
// 61230, a=10, b=10, c=10

You might also like