vhdl - VHDL 当变量立即取值并在过程结束时信号取值时,这意味着什么?
问题描述
我对实验室阅读中的一段感到困惑:阅读中的 片段
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.
我对变量立即取值和信号在处理后取值的含义感到困惑。他们还提到,变量出现在信号之前还是之后也会产生影响,但我不知道会产生什么影响。这是他们尝试实现的代码: 代码片段
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。
解决方案
我不认为“这意味着信号分配的顺序将改变代码的行为”这句话对您的用例来说是准确的。
考虑以下代码:
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
followedif then end if
会更好地理解为if then elsif then end if
. 然而,对于这里的可变情况,我们最终得到了该规则的一个有趣的例外。
推荐阅读
- elasticsearch - 通过 kubernetes-ingress 流利到 elasticsearch
- flutter - 使用 Flutter 在 RxDart 中等待 observable 完成
- python - lmfit - 最小化器不接受 scipy 最小化器关键字参数
- java - 在Processing中从X点到Y点绘制圆柱体
- ruby - Sinatra 和 post datamapper 关联
- javascript - 无法保存第一次单击的状态
- haskell - 接受 3 个字符串的函数,其中第一个是 3rd 的一部分,并用第二个字符串更改 3rd 中的第一个字符串
- powershell - 需要在 CSV 中为多个主机运行脚本
- sql - sql表涨价
- python - 我正在尝试从 URL 列表中解析信息,但我的代码每次都解析相同的页面