如何在 VHDL 中延迟时间:等待
在前面的教程中,我们了解到可以将进程视为程序线程。我们还了解到 wait; 语句导致程序无限期暂停。但是有没有办法让程序等待任何其他时间值而不是永远?
如果我们删除 wait; 完全并尝试编译程序,编译器会抱怨无限循环。编译器所指的循环是进程循环 . VHDL 中的进程线程永远不会终止,它会在 begin 之间不断循环 和 end process; 陈述。必须有一个 wait 在进程循环内的某处声明。
这篇博文是基本 VHDL 教程系列的一部分。
而 wait; 将导致程序永远暂停,wait for 语句可用于将程序延迟任意时间。
wait for 的语法 语句为:wait for <time_value> <time_unit>;
其中<time_value> 是数字和 <time_unit> 是下列时间单位之一:
| fs | 飞秒 |
| ps | 皮秒 |
| ns | 纳秒 |
| 我们 | 微秒 |
| 毫秒 | 毫秒 |
| 秒 | 秒 |
| 分钟 | 分钟 |
| 小时 | 小时 |
运动
本教程视频将向您展示如何使用 wait for 将进程暂停给定时间的语句。
我们在本教程中创建的代码:
entity T02_WaitForTb is
end entity;
architecture sim of T02_WaitForTb is
begin
process is
begin
-- This is the start of the process "thread"
report "Peekaboo!";
wait for 10 ns;
-- The process will loop back to the start from here
end process;
end architecture;
当我们在 ModelSim 中按下运行按钮时,模拟器控制台的输出:
VSIM 2> run # ** Note: Peekaboo! # Time: 0 ns Iteration: 0 Instance: /t02_waitfortb # ** Note: Peekaboo! # Time: 10 ns Iteration: 0 Instance: /t02_waitfortb # ** Note: Peekaboo! # Time: 20 ns Iteration: 0 Instance: /t02_waitfortb ...
分析
在这个例子中,我们使用了 10 ns ,表示 10 纳秒。当使用以 MHz 时钟频率运行的数字逻辑时,您通常会使用纳秒增量。
当我们在模拟器中运行代码时,它会打印出“Peekaboo!”每 10 ns 发送到控制台。因为这是一个模拟,所以 report 语句耗时为零,循环也是如此。
外卖
- 进程线程将在
wait for处暂停 确切的指定时间 wait以外的所有语句 语句的仿真时间为零
转到下一个教程 »
VHDL