Verilog $timeformat Example - EDA Playground
Warning! This exercise has been opened in another tab; autosave has been disabled. Close this tab or refresh to reactivate.

 Languages & Libraries

 Tools & Simulators

 Examples

206


47
 
1
`timescale 1ns/1ps
2
3
module tb;
4
  bit   a;
5
  
6
  initial begin
7
    
8
    // Wait for some time - note that because precision is 1/1000 of
9
    // the main scale (1ns), this delay will be truncated by the 3rd
10
    // position
11
    #10.512351;
12
    
13
    // Display current time with default timeformat parameters
14
    $display("[T=%0t] a=%0b", $realtime, a);
15
    
16
    // Change timeformat parameters and display again
17
    $timeformat(-9, 2, " ns");
18
    $display("[T=%0t] a=%0b", $realtime, a);
19
    
20
    // Remove the space in suffix, and extend fractional digits to 5
21
    $timeformat(-9, 5, "ns");
22
    $display("[T=%0t] a=%0b", $realtime, a);
23
    
24
    // Here suffix is wrong, it should not be "ns" because we are
25
    // setting display in "ps" (-12) 
26
    $timeformat(-12, 3, " ns");
27
    $display("[T=%0t] a=%0b", $realtime, a);
28
    
29
    // Correct the suffix to ps
30
    $timeformat(-12, 2, " ps");
31
    $display("[T=%0t] a=%0b", $realtime, a);
32
  end
33
  
34
endmodule
35
36
/*
37
Simulation Log:
38
---------------
39
xcelium> run
40
[T=10512] a=0
41
[T=10.51 ns] a=0
42
[T=10.51200ns] a=0
43
[T=10512.000 ns] a=0
44
[T=10512.00 ps] a=0
45
xmsim: *W,RNQUIE: Simulation is complete.
46
47
*/
2
 
1
// Code your design here
2
1509 views and 0 likes     
A short description will be helpful for you to remember your playground's details
 
100:0