VHDL 当变量立即取值而信号在过程结束时取值是什么意思?

VHDL What does it mean when variable take a value immediately and signal take their value at the end of the process?

我对实验室阅读中的一段感到困惑: Snippet from reading

Recall that variables like rst_meta take on their value immediately, whereas signals 
take on their assignment when the process suspends in this case, at the process sensitivity
list. This implies that the ordering of the signal assignments will change the  behavior of
the code. 

我对变量立即取值和信号在处理后取值的含义感到困惑。他们还提到,变量出现在信号之前还是之后也会有所不同,但我不知道会产生什么影响。 这是他们试图实现的代码: Code snippet

entity reset_bridge is
    Port ( clk_dst : in STD_LOGIC;
           rst_in : in STD_LOGIC;
           rst_out : out STD_LOGIC);
end reset_bridge;

architecture Behavioral of reset_bridge is
    --signal rst_meta : std_logic;
begin
    process (clk_dst,rst_in)
        variable rst_meta : std_logic;
    begin
        if rst_in = '1' then
            rst_meta := '1';
            --rst_meta <= '1';
            rst_out  <= '1';
        elsif rising_edge(clk_dst) then
            --rst_meta <= '0';
            rst_out <= rst_meta;
            rst_meta := '0';
        end if;
    end process;

end Behavioral;

编辑: 读数是关于亚稳态的,他们试图实现的电路是双 FF。

Link to image

我认为“这意味着信号分配的顺序将改变代码的行为”这句话对于您的用例来说并不准确。

考虑以下代码:

architecture Forward of AFewFlipFlops is
    signal r1, r2, r3: std_logic;
begin
    process (clk_dst)
    begin
        if rising_edge(clk_dst) then
            r1 <= A_in ;
            r2 <= r1 ;
            r3 <= r2 ;
            rst_out  <= r3;
        end if;
    end process;

以上创建了与以下相同的硬件:

architecture Reverse of AFewFlipFlops is
    signal r1, r2, r3: std_logic;
begin
    process (clk_dst)
    begin
        if rising_edge(clk_dst) then
            rst_out  <= r3;
            r3 <= r2 ;
            r2 <= r1 ;
            r1 <= A_in ;
        end if;
    end process;

OTOH,如果 r1、r2 和 r3 是变量,那么架构 Reverse 将产生与基于信号的架构相同的结果,但 Forward 不会 - 它只会创建 1 个触发器。这不是由于信号的顺序,而是由于变量的顺序。

如果我们考虑一个稍微不同的电路,那么我们可以看到一个变量是不变的(只要我们用它来创建组合逻辑),这里信号排序很重要。

在架构 JunkySignalCode 中,如果我们更改条件 Add1 和 Add2 的顺序,那么我们会影响结果,因为这里最后执行的信号分配获胜。

architecture JunkySignalCode of JunkyMath is
    signal A : unsigned(7 downto 0) ;
begin
    process (clk_dst,rst_in)
    begin
       if rising_edge(clk_dst) then
         if rst_in = '1' then
             A <= (others => '0') ;
         else
           if Add1 = '1' then 
             A <= A + 1 ; 
           end if ; 
           if Add2 = '1' then 
             A <= A + 2 ; 
           end if ; 
         end if;
       end if;
    end process;

OTOH,在架构JunkyVariableCode中,如果我们改变条件Add1和Add2的顺序,那么结果确实是一样的。

architecture JunkyVariableCode of JunkyMath is
    signal A : unsigned(7 downto 0) ;
begin
    process (clk_dst,rst_in)
      variable ATemp : unsigned(7 downto 0) ; 
    begin
       if rising_edge(clk_dst) then
         if rst_in = '1' then
            ATemp  := (others => '0') ;
         else
           if Add1 = '1' then 
             ATemp  := ATemp + 1 ; 
           end if ; 
           if Add2 = '1' then 
             ATemp  := ATemp + 2 ; 
           end if ; 
         end if;
         A <= ATemp ; 
       end if;
    end process;

我看到的一个普遍性是,时钟进程中的每个信号分配总是会创建一个触发器。时钟进程中的变量赋值可能会或可能不会创建触发器,具体取决于赋值的顺序。

在 JunkyMath 中,大多数情况下,if then end if 后跟 if then end if 会更好地理解为 if then elsif then end if。然而,对于此处的可变情况,我们最终对该规则有一个有趣的例外。