首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当变量立即取值,而信号在过程结束时取值,这意味着什么?

当变量立即取值,而信号在过程结束时取值,这意味着什么?
EN

Stack Overflow用户
提问于 2021-08-21 00:36:51
回答 1查看 87关注 0票数 0

我对我实验室里的一段话感到困惑:Snippet from reading

代码语言:javascript
复制
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

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-23 04:35:58

我不认为“这意味着信号赋值的顺序将改变代码的行为”这句话对你的用例来说是准确的。

考虑以下代码:

代码语言:javascript
复制
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;

上面创建的硬件与以下内容相同:

代码语言:javascript
复制
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;

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

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

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

代码语言:javascript
复制
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;

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

代码语言:javascript
复制
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。然而,对于这里的变量情况,我们最终得到了该规则的一个有趣的例外。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68869278

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档