用并发语句实现触发器

implementing a flip-flop with concurrent statement

VHDL编程中规定,对于组合电路,使用并发语句,而对于时序电路,并发语句和顺序语句都适用。现在的问题是:

如果我以并发形式编写顺序代码会怎样?比如我不用process,用when..else

写触发器
architecture x of y is
begin
   q <= '0' when rst=1 else
        d   when (clock'event and clock='1') else
        q;
end;

这是一个正确且可合成的代码吗?如果它是一个不正确的代码,那究竟有什么问题(除了语法错误)?

你说:"It is stated in VHDL programming that for combinational circuits, concurrent statements are used while for sequential circuits, both concurrent and sequential statements are applicable."。那明显是错的。您可以使用并发或顺序语句对组合代码和顺序代码进行建模。

使用并发语句对顺序逻辑建模是不常见的。 (我这么说是因为我在工作中看到了很多其他人的代码,但我几乎从来没有看到过)。然而,这是可能的。您的代码确实存在语法错误和更基本的错误。如您所料,此修改后的代码版本综合为具有异步高电平有效复位的上升沿触发触发器:

q <= '0' when rst='1' else
      d  when clock'event and clock='1';

语法错误是 rst=1 而不是 rst='1'。更根本的错误是您不需要 else q。这是不必要的,因为 VHDL 中的信号会保留先前分配的值,直到分配新值为止。因此,在 VHDL 代码建模时序逻辑中,永远 没有必要编写 q <= q(或其等价物)。在你的例子中,在 MCVE 我构建的 q 是一个输出,所以你的 else q 给出了语法错误,因为你无法读取输出。

这是 MCVE:

library IEEE;
use IEEE.std_logic_1164.all;

entity concurrent_flop is
  port (clock, rst, d : in  std_logic;
        q             : out std_logic);
end entity concurrent_flop;

architecture concurrent_flop of concurrent_flop is
begin
   q <= '0' when rst='1' else
         d  when clock'event and clock='1';
end architecture concurrent_flop;

我写了一个 MCVE 来检查我要说的是正确的。你也可以这样做。这样做是学习 VHDL 的好方法。 EDA Playground 通常是一个尝试东西的好地方(无耻的插件),但在这种情况下并不好,因为不能在 EDA Playground 上合成 VHDL。