【发布时间】:2019-07-08 16:22:23
【问题描述】:
请看一下这个简单状态机的示例代码:
entity Top is
Port ( Clock : in STD_LOGIC;
Reset : in STD_LOGIC;
TREADY : out STD_LOGIC
);
end Top;
architecture Behavioral of Top is
type STATE_t is (S0, S1, S2);
signal CurrentState : STATE_t := S0;
signal TREADY_Int : STD_LOGIC := '0';
begin
-- Transit network
process(Clock, Reset, CurrentState)
variable NextState : STATE_t;
begin
if(rising_edge(Clock)) then
case CurrentState is
when S0 =>
if(Reset = '1') then
NextState := S0;
else
NextState := S1;
end if;
when S1 =>
NextState := S2;
when S2 =>
NextState := S1;
end case;
end if;
CurrentState <= NextState;
end process;
-- Output network
process(CurrentState)
begin
if(CurrentState = S0) then
TREADY_Int <= '0';
elsif(CurrentState = S1) then
TREADY_Int <= '1';
elsif(CurrentState = S2) then
TREADY_Int <= '0';
end if;
end process;
TREADY <= TREADY_Int;
end Behavioral;
合成向我显示以下警告:
[Synth 8-327] inferring latch for variable 'TREADY_Int_reg'
当我将输出网络的最后一个条件更改为时,警告消失
else
TREADY_Int <= '0';
end if;
锁也不见了
那么为什么第一个版本中输出状态机的最后一个条件会导致锁存器呢?为什么else 不是elsif()?在我看来,这两个表达式是相等的,因为状态机只有三个状态,所以在处理所有其他状态时,else 和elsif(<ThirdState>) 应该是相同的。但是这里好像我的理解是错误的。
【问题讨论】:
-
不,我不这么认为。链接的主题讨论了使用 STD_LOGIC 的 if 条件期间的错误,其中用户没有处理所有情况(STD_LOGIC 有 9 个状态)并且没有时钟,因此锁存器非常正常。本主题讨论在处理所有状态的时钟状态机中锁存器的更新。
-
没有。 IEEE Std 1076-2008 16.8 Standard synthesis packages, 16.8.2 Interpretation of the standard logic types, 16.8.2.2 The STD_LOGIC_1164 values。第一个综合结果在 TREADY_int 上有一个锁存器与具有 9 个枚举值的基本类型 std_ulogic 无关。
-
你是对的,对不起。
标签: vhdl state-machine