如何设置 200MHz 系统时钟?
How can I set 200MHz system clock?
我正在尝试以这种方式设置系统时钟:
`timescale 5 ns/1 ns
然后:
initial begin
forever #0.5 clk = ~clk;
end
但是,我收到错误 Unexpected char '5'
?为什么? “5”有什么问题?例如 10 个有效。
另一种可行但不优雅的方法:
`timescale 1 ns/1 ns
和
initial begin
forever #2.5 clk = ~clk;
end
有人有更好的解决方案吗?
来自 IEEE 1800-2017,第 22.7 节:
The time_unit argument specifies the unit of measurement for times and
delays. The time_precision argument specifies how delay values are
rounded before being used in simulation. The time_precision argument
shall be at least as precise as the time_unit argument; it cannot
specify a longer unit of time than time_unit.
The integers in these arguments specify an order of magnitude for the
size of the value; the valid integers are 1, 10, and 100.
我认为您误解了 timescale 指令的用途。它用于指定模拟的时间单位和时间精度,而不是用于指定时钟周期。
顺便说一句:您可以从 IEEE 免费下载 IEEE 1800-2017。 (Accelera 支付。)我建议你这样做。可读性很强。
`timescale
指令中 5 ns
的问题在于,根据 IEEE 标准,它是非法语法。只允许 1、10 和 100。
但是,您的其他代码示例也存在问题:
`timescale 1 ns/1 ns
forever #2.5 clk = ~clk;
这不会产生 200MHz 的时钟。它产生一个 166MHz 的时钟。您指定了 1ns 的时间精度,这意味着小数延迟将被四舍五入。在这种情况下。 2.5 向上舍入为 3,这意味着您最终得到的周期为 6ns,而不是 5ns。您可以通过将以下代码添加到您的测试台来看到这一点:
initial $monitor($realtime, "\tclk=%b", clk);
那么你会看到clk
的周期是6ns:
0 clk=0
3 clk=1
6 clk=0
9 clk=1
12 clk=0
15 clk=1
实现 200MHz 时钟的一种方法是使用 100ps 的精度:
`timescale 1 ns / 100 ps
forever #2.5 clk = ~clk;
我正在尝试以这种方式设置系统时钟:
`timescale 5 ns/1 ns
然后:
initial begin
forever #0.5 clk = ~clk;
end
但是,我收到错误 Unexpected char '5'
?为什么? “5”有什么问题?例如 10 个有效。
另一种可行但不优雅的方法:
`timescale 1 ns/1 ns
和
initial begin
forever #2.5 clk = ~clk;
end
有人有更好的解决方案吗?
来自 IEEE 1800-2017,第 22.7 节:
The time_unit argument specifies the unit of measurement for times and delays. The time_precision argument specifies how delay values are rounded before being used in simulation. The time_precision argument shall be at least as precise as the time_unit argument; it cannot specify a longer unit of time than time_unit. The integers in these arguments specify an order of magnitude for the size of the value; the valid integers are 1, 10, and 100.
我认为您误解了 timescale 指令的用途。它用于指定模拟的时间单位和时间精度,而不是用于指定时钟周期。
顺便说一句:您可以从 IEEE 免费下载 IEEE 1800-2017。 (Accelera 支付。)我建议你这样做。可读性很强。
`timescale
指令中 5 ns
的问题在于,根据 IEEE 标准,它是非法语法。只允许 1、10 和 100。
但是,您的其他代码示例也存在问题:
`timescale 1 ns/1 ns
forever #2.5 clk = ~clk;
这不会产生 200MHz 的时钟。它产生一个 166MHz 的时钟。您指定了 1ns 的时间精度,这意味着小数延迟将被四舍五入。在这种情况下。 2.5 向上舍入为 3,这意味着您最终得到的周期为 6ns,而不是 5ns。您可以通过将以下代码添加到您的测试台来看到这一点:
initial $monitor($realtime, "\tclk=%b", clk);
那么你会看到clk
的周期是6ns:
0 clk=0
3 clk=1
6 clk=0
9 clk=1
12 clk=0
15 clk=1
实现 200MHz 时钟的一种方法是使用 100ps 的精度:
`timescale 1 ns / 100 ps
forever #2.5 clk = ~clk;