在嵌套的 If-Else 语句 (VHDL) 中推断 Latch

Inferring Latch in a nested If-Else statement (VHDL)

我的代码有一个推断锁存器的问题。我知道闩锁通常是由于未考虑输出的所有情况而引起的,但在这种情况下,我还没有看到任何涵盖此问题的在线示例。我在流程语句中有一个嵌套的 if-else 语句,如下所示。只是为了快速解释我在做什么,在启动重置后,reset_cnt 将变高并启动 sck 的计数过程,最多 24 个周期并重复自身,输出将增加。

clock_counter: process(reset, sck, counter, output, reset_cnt, reset_done)
begin
  if (reset = '1') then
    counter <= 0;
    output <= 1;
    reset_cnt <= 1;
    reset_done <= '1';
  else
    reset_done <= '1';   -- added to fix
    reset_cnt <= 1;      -- added to fix
    output <= output;          -- added to fix (didn't work)
    if (reset_cnt AND counter = 24) then
      counter <= 0;
      output <= output + 1;
    elsif (rising_edge(sck)) then
      counter <= counter + 1;
    end if;
  end if;
end process;

最初我遇到了 3 个锁存器的问题:reset_done、reset_cnt 和输出。我添加了一些代码行(旁边有注释的代码行)并且我能够删除 reset_done 和 reset_cnt 的闩锁。看起来我仍然得到 out 的推断锁存器,因为我在嵌套的 If 语句中使用它。我想:

output <= output;

可能有用,但我想不行。有谁知道如何修复这种闩锁?我应该提一下,我试过将它分成 2 个流程语句,并将其变成一个 case 语句,但这也没有用。非常感谢任何帮助或建议!

这段代码完全错误。很难修复,因为它在一个过程中结合了多个错误。

我会试着列举你的一些错误:

  1. 敏感列表不应使用 outputreset_done
  2. output <= output + 1;无法合成或将在模拟中产生死循环
  3. 你需要将组合逻辑和时序逻辑区分为两个过程
  4. reset_donereset_cnt 没用,因为它们总是 '1'
  5. reset_cnt 是一个整数,不能与表达式 counter = 24
  6. 中的布尔值进行 AND 运算
  7. 从不写output <= output;

我建议研究组合和顺序过程以及 VHDL 的编码模式。