首页 > 解决方案 > 无条件 WAIT 语句对 VHDL 中进程的影响

问题描述

wait关于以无条件语句结尾的 VHDL 过程,我有一些不明白的地方。为了说明我的问题,我需要比较以下 2 个片段:

片段1:

library ieee;
use ieee.std_logic_1164.all;

entity foo is
end entity;

architecture sim of foo is
  signal clk : std_logic := '0';
  signal s   : std_logic;

begin
  clk <= not clk after 10 ns;

  -- driver1
  s <= '0';

  -- driver2
  process (clk) is
  begin
    s <= clk;
  end process;
end architecture;

信号 s 有双重分配:Driver1 将信号 s 驱动为“0”,而 driver2 交替将其驱动为“0”和“1”。正如我们在波形图上看到的,当 clk 为“0”时,生成的 s 为“0”(绿色段),但当 clk 为“1”时,生成的 s 为“X”(红色段)。 在此处输入图像描述 =>我理解这种行为,那没问题。

如果我通过将 driver1 更改为以无条件wait指令结束的进程来稍微修改此代码:

片段2:

library ieee;
use ieee.std_logic_1164.all;

entity foo is
end entity;

architecture sim of foo is
  signal clk : std_logic := '0';
  signal s   : std_logic;

begin
  clk <= not clk after 10 ns;

  -- driver1
  -- s <= '0';
  process 
  begin
    s <= '0';
    wait;
  end process;

  -- driver2
  process (clk) is
  begin
    s <= clk;
  end process;
end architecture;

令人惊讶的是,对我来说,snipet 2 产生了与 snipet 1 相同的波形。我的理解是,带有最终“无条件”wait语句的进程内的指令将永远停止,这意味着它们的代码在第一次执行运行后将处于非活动状态。但如果情况确实如此,我希望 snipet 2 中的 driver1 在第一次运行后处于非活动状态,并且从那时起 driver2 仍然是信号 s 的唯一活动驱动程序,始终为其分配 clk 的替代 '1' 和 '0'。

为什么不是这样?

标签: vhdl

解决方案


当您在流程中分配信号时,会为该信号创建一个驱动程序,从它分配的那一刻到模拟结束。所以在这里,两个代码片段在功能上是等效的,您从时间 0 创建 driver1,从第一个时钟创建 driver2。


推荐阅读