Xilinx VHDL 闩锁警告故障排除

Xilinx VHDL latch warning troubleshooting

Xilinx 正在为我编写的 VHDL 代码推断锁存器。我查找了造成这种情况的可能原因,发现这通常是由于 if 或 case 语句不完整造成的。我已经完成并确保包含 else 和 when others 语句,但我仍然收到警告。我相信这也影响了我正在从事的另一个项目,所以我想了解为什么会这样。

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity state_machine is
    port(trig, en: in std_logic; cstate,nstate: out std_logic_vector(0 to 2)); 
end state_machine;

architecture Behavioral of state_machine is
signal cstate_s,nstate_s: std_logic_vector(0 to 2);

begin
cstate <= cstate_s;
nstate <= nstate_s;

process(en, cstate_s)
begin
    if en = '1' then
        nstate_s <= "111";
        if cstate_s = "111" then
            nstate_s <= "011";
        elsif cstate_s = "011" then
            nstate_s <= "100";
        elsif cstate_s = "100" then
            nstate_s <= "101";
        elsif cstate_s = "101" then
            nstate_s <= "110";
        elsif cstate_s = "110" then
            nstate_s <= "111";
        else
            null;
        end if;
    else
        null;
    end if;
end process;

process(trig, nstate_s)
begin
    if rising_edge(trig) then
        cstate_s <= nstate_s;
    else
        null;
    end if;
end process;

end Behavioral;

WARNING:Xst:737 - Found 3-bit latch for signal . Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems.

为了在合成 组合 过程时不合成锁存器,在 beginend process; 之间必须没有路径,其中所有输出的过程没有分配。这叫做完成赋值。该过程的输出是任何 signal 在其中任何位置分配的。

你有这样的路径。当执行带有 null 语句的任何路径时,不会分配给第一个进程 (nstate_s) 的输出。因此,您将得到合成的锁存器。只使用 null 语句是没有意义的。如果您真的不关心在这些路径中为您的输出分配什么值,请将输出分配给 '-',这意味着 不关心 在 VHDL 中。

顺便说一下(假设 trig 是一个时钟),你的第二个过程不是组合的(它是 顺序的 )所以你不需要遵守完成作业;您的 else 分支是不必要的。