Menguasai $timeformat Verilog: Kontrol Presisi dan Tampilan
Direktif timescale Verilog menentukan satuan waktu dan presisi untuk simulasi.
Fungsi sistem Verilog $timeformat menentukan gaya pelaporan format specifier %t dalam pernyataan tampilan seperti $display dan $strobe.
Sintaks
$timeformat(<unit_number>, <precision>, <suffix_string>, <minimum field width>);
- unit_number adalah presisi waktu terkecil dari semua direktif
`timescale yang digunakan dalam kode sumber - precision mewakili jumlah digit pecahan untuk timescale saat ini
- suffix_string adalah opsi untuk menampilkan skala bersama dengan nilai waktu real
| Unit number | Time unit |
|---|
| -3 | 1ms |
| -6 | 1us |
| -9 | 1ns |
| -12 | 1ps |
| -15 | 1fs |
Contoh #1: 1ns/1ps
Berikut adalah contoh bagaimana $timeformat mempengaruhi format tampilan satuan waktu.
`timescale 1ns/1ps
module tb;
bit a;
initial begin
// Wait for some time - note that because precision is 1/1000 of
// the main scale (1ns), this delay will be truncated by the 3rd
// position
#10.512351;
// Display current time with default timeformat parameters
$display("[T=%0t] a=%0b", $realtime, a);
// Change timeformat parameters and display again
$timeformat(-9, 2, " ns");
$display("[T=%0t] a=%0b", $realtime, a);
// Remove the space in suffix, and extend fractional digits to 5
$timeformat(-9, 5, "ns");
$display("[T=%0t] a=%0b", $realtime, a);
// Here suffix is wrong, it should not be "ns" because we are
// setting display in "ps" (-12)
$timeformat(-12, 3, " ns");
$display("[T=%0t] a=%0b", $realtime, a);
// Correct the suffix to ps
$timeformat(-12, 2, " ps");
$display("[T=%0t] a=%0b", $realtime, a);
end
endmodule
Log Simulasi
xcelium> run
[T=10512] a=0
[T=10.51 ns] a=0
[T=10.51200ns] a=0
[T=10512.000 ns] a=0
[T=10512.00 ps] a=0
xmsim: *W,RNQUIE: Simulation is complete.
Contoh #2: 1ns/100ps
Berikut adalah contoh yang sama dari di atas dengan timescale yang berbeda.
`timescale 1ns/100ps
Log Simulasi
xcelium> run
[T=105] a=0
[T=10.50 ns] a=0
[T=10.50000ns] a=0
[T=10500.000 ns] a=0
[T=10500.00 ps] a=0
xmsim: *W,RNQUIE: Simulation is complete.
Contoh #3: 100ns/1ns
`timescale 100ns/1ns
#1 mewakili 100ns dan oleh karena itu #10 menghasilkan 1000ns
Log Simulasi
xcelium> run
[T=1051] a=0
[T=1051.00 ns] a=0
[T=1051.00000ns] a=0
[T=1051000.000 ns] a=0
[T=1051000.00 ps] a=0
xmsim: *W,RNQUIE: Simulation is complete.