构建VHDL时钟触发进程实战指南
大多数VHDL设计采用时钟逻辑——通常称为同步或时序逻辑。时钟进程仅在主时钟沿激活,无论其他输入信号如何变化。
时钟逻辑的基本元件是触发器。本教程聚焦带负复位的正沿触发触发器。见下图原理图:
作为采样保持器件,触发器在时钟上升沿捕获输入值并保持该值,直到下一个上升沿或复位信号置位。
注意: 本文属基础VHDL教程系列。
所有时钟进程同步触发并同时采样输入。时钟建立离散时间步,允许设计师将复杂逻辑划分为清晰的周期级事件。
触发器或其阵列也称寄存器。
时钟进程敏感性列表通常仅含时钟信号,因进程仅在时钟沿唤醒。其他输入对触发无影响。
下面是带同步复位的时钟进程可复用模板:
process(Clk) is begin if rising_edge(Clk) then if nRst = '0' then <reset all output signals here> else <main logic here> end if; end if; end process;
练习
配套视频教程演练创建VHDL时钟进程。
测试平台代码
触发器最终测试平台:
library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity T17_ClockedProcessTb is end entity; architecture sim of T17_ClockedProcessTb is constant ClockFrequency : integer := 100e6; -- 100 MHz constant ClockPeriod : time := 1000 ms / ClockFrequency; signal Clk : std_logic := '1'; signal nRst : std_logic := '0'; signal Input : std_logic := '0'; signal Output : std_logic; begin -- The Device Under Test (DUT) i_FlipFlop : entity work.T17_FlipFlop(rtl) port map( Clk => Clk, nRst => nRst, Input => Input, Output => Output); -- Clock generation Clk <= not Clk after ClockPeriod / 2; -- Testbench sequence process is begin -- Release the DUT from reset nRst <= '1'; wait for 20 ns; Input <= '1'; wait for 22 ns; Input <= '0'; wait for 6 ns; Input <= '1'; wait for 20 ns; -- Apply reset nRst <= '0'; wait; end process; end architecture;
触发器模块
带负复位的正沿触发器实现:
library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity T17_FlipFlop is port( Clk : in std_logic; nRst : in std_logic; -- Negative reset Input : in std_logic; Output : out std_logic); end entity; architecture rtl of T17_FlipFlop is begin -- Flip‑flop with synchronized reset process(Clk) is begin if rising_edge(Clk) then if nRst = '0' then Output <= '0'; else Output <= Input; end if; end if; end process; end architecture;
波形观察
在ModelSim运行仿真并放大时间线,波形清晰显示输出仅在时钟上升沿更新:

分析
输出仅在时钟上升沿变化。发生在两个上升沿间的任何输入跃变——如~45ns处开始的负脉冲——不被捕获,因触发器仅在沿采样。
下面动画形象展示输入、时钟、输出关系:

关键观察:
- 20ns处同步于时钟的单周期输入脉冲在输出产生延迟响应。
- 仿真中事件以零时间步(delta周期)发生。因触发器在同一delta周期读输入更新输出,捕获的是沿前输入值。
实践中触发器要求输入在时钟沿前后短时间内稳定——称建立和保持时间。综合工具将VHDL转网表时自动处理这些约束。
深入了解仿真时间步见Delta周期详解。
要点
- 带同步复位的时钟进程敏感性列表仅含时钟。
- 用
if rising_edge(Clk)保证严格在时钟上升沿激活。 - 同步设计中所有状态变化发生在有效时钟沿。
准备测试知识?参加基础VHDL测验–第3部分或继续下一教程。
VHDL