Verilog タイムスケール
Verilog シミュレーションは、時間の定義方法に依存します。これは、シミュレーターが時間に関する 1 の意味を知る必要があるためです。 `timescale
コンパイラ ディレクティブは、それに続くモジュールの時間単位と精度を指定します。
構文
`timescale <time_unit>/<time_precision>
// Example
`timescale 1ns/1ps
`timescale 10us/100ns
`timescale 10ns/1ns
time_unit time_precision の間の遅延とシミュレーション時間の測定値です シミュレーションで使用する前に遅延値を丸める方法を指定します。
同じ設計で異なる時間単位を使用するには、次のタイムスケール コンストラクトを使用します。設計の遅延仕様は合成可能ではなく、ハードウェア ロジックに変換できないことに注意してください。
`timescale
測定の基本単位と時間の精度- 時間単位と精度を表示する $printtimescale システム タスク
$time
と$realtime
システム関数は現在の時刻を返し、デフォルトのレポート形式は別のシステム タスク$timeformat
で変更できます .
キャラクター | ユニット |
---|---|
s | 秒 |
ミリ秒 | ミリ秒 |
私たち | マイクロ秒 |
ns | ナノ秒 |
ps | ピコ秒 |
fs | フェムト秒 |
これらの仕様の整数は、1、10、または 100 のいずれかであり、単位を指定する文字列は、上記の表に記載されている任意の値を取ることができます。
例 #1:1ns/1ns
// Declare the timescale where time_unit is 1ns
// and time_precision is also 1ns
`timescale 1ns/1ns
module tb;
// To understand the effect of timescale, let us
// drive a signal with some values after some delay
reg val;
initial begin
// Initialize the signal to 0 at time 0 units
val <= 0;
// Advance by 1 time unit, display a message and toggle val
#1 $display ("T=%0t At time #1", $realtime);
val <= 1;
// Advance by 0.49 time unit and toggle val
#0.49 $display ("T=%0t At time #0.49", $realtime);
val <= 0;
// Advance by 0.50 time unit and toggle val
#0.50 $display ("T=%0t At time #0.50", $realtime);
val <= 1;
// Advance by 0.51 time unit and toggle val
#0.51 $display ("T=%0t At time #0.51", $realtime);
val <= 0;
// Let simulation run for another 5 time units and exit
#5 $display ("T=%0t End of simulation", $realtime);
end
endmodule
最初の遅延ステートメントは #1 を使用します。これにより、シミュレーターは、`timescale
で 1ns に指定された 1 時間単位だけ待機します。 指令。 esecond delay ステートメントは、時間単位の半分未満の 0.49 を使用します。ただし、時間精度は 1 ns に指定されているため、シミュレータは 1 ns より小さくすることはできません。これにより、指定された遅延ステートメントが丸められ、0 ns が生成されます。したがって、2 番目の遅延はシミュレーション時間を進めることができません。
3 番目の遅延ステートメントは、時間単位 [hl]#0.5[/lh] のちょうど半分を使用し、シミュレーターは値を丸めて、時間単位全体を表す #1 を取得します。したがって、これは T=2ns で出力されます。
4 番目の遅延ステートメントは、時間単位の半分を超える値を使用し、丸められて表示ステートメントが T=3ns で出力されるようにします。
シミュレーションログncsim> run T=1 At time #1 T=1 At time #0.49 T=2 At time #0.50 T=3 At time #0.51 T=8 End of simulation ncsim: *W,RNQUIE: Simulation is complete.
シミュレーションは予想どおり 8 ns 実行されますが、波形の各ナノ秒の間に小さな分割がないことに注意してください。これは、時間の精度が時間単位と同じであるためです。
例 #2:10ns/1ns
唯一 前の例と比較してこの例で行われた変更は、タイムスケールが 1ns/1ns から 10ns/1ns に変更されたことです。したがって、時間単位は 10ns で、精度は 1ns です。
// Declare the timescale where time_unit is 10ns
// and time_precision is 1ns
`timescale 10ns/1ns
// NOTE: Testbench is the same as in previous example
module tb;
// To understand the effect of timescale, let us
// drive a signal with some values after some delay
reg val;
initial begin
// Initialize the signal to 0 at time 0 units
val <= 0;
// Advance by 1 time unit, display a message and toggle val
#1 $display ("T=%0t At time #1", $realtime);
val <= 1;
// Advance by 0.49 time unit and toggle val
#0.49 $display ("T=%0t At time #0.49", $realtime);
val <= 0;
// Advance by 0.50 time unit and toggle val
#0.50 $display ("T=%0t At time #0.50", $realtime);
val <= 1;
// Advance by 0.51 time unit and toggle val
#0.51 $display ("T=%0t At time #0.51", $realtime);
val <= 0;
// Let simulation run for another 5 time units and exit
#5 $display ("T=%0t End of simulation", $realtime);
end
endmodule
実際のシミュレーション時間は、#
を使用して指定された遅延を乗算することによって取得されます 時間単位で、精度に基づいて四捨五入されます。最初の遅延ステートメントは 10ns を生成し、2 番目の遅延ステートメントは 14.9 を生成し、15ns に丸められます。
3 番目のステートメントも同様に 5ns (0.5 * 10ns) を追加し、合計時間は 20ns になります。 4 番目のものはさらに 5ns (0.51 * 10) を追加して、合計時間を 25ns に進めます。
シミュレーションログncsim> run T=10 At time #1 T=15 At time #0.49 T=20 At time #0.50 T=25 At time #0.51 T=75 End of simulation ncsim: *W,RNQUIE: Simulation is complete.
波形の基本単位は数十ナノ秒で、精度は 1ns です。
例 #3:1ns/1ps
唯一 前の例と比較してこの例で行われた変更は、タイムスケールが 1ns/1ns から 1ns/1ps に変更されたことです。したがって、時間単位は 1ns で、精度は 1ps です。
// Declare the timescale where time_unit is 1ns
// and time_precision is 1ps
`timescale 1ns/1ps
// NOTE: Testbench is the same as in previous example
module tb;
// To understand the effect of timescale, let us
// drive a signal with some values after some delay
reg val;
initial begin
// Initialize the signal to 0 at time 0 units
val <= 0;
// Advance by 1 time unit, display a message and toggle val
#1 $display ("T=%0t At time #1", $realtime);
val <= 1;
// Advance by 0.49 time unit and toggle val
#0.49 $display ("T=%0t At time #0.49", $realtime);
val <= 0;
// Advance by 0.50 time unit and toggle val
#0.50 $display ("T=%0t At time #0.50", $realtime);
val <= 1;
// Advance by 0.51 time unit and toggle val
#0.51 $display ("T=%0t At time #0.51", $realtime);
val <= 0;
// Let simulation run for another 5 time units and exit
#5 $display ("T=%0t End of simulation", $realtime);
end
endmodule
時間単位が新しい精度値 1ps に一致するようにスケーリングされていることを確認します。また、時間は最小の解像度 (この場合はピコ秒) で表されることに注意してください。
シミュレーションログncsim> run T=1000 At time #1 T=1490 At time #0.49 T=1990 At time #0.50 T=2500 At time #0.51 T=7500 End of simulation ncsim: *W,RNQUIE: Simulation is complete.
Verilog