我正在用 VHDL 创建一个 ram 阅读器。 综合后,使用 report_utilization 命令显示推断出 3 个锁存器,我不想使用它们。
阅读综合 VHDL 文件,我发现信号 CURRENT_STATE 被推断为 3 个锁存器(我猜这是因为我在我的有限状态机中使用了 9 个状态)。
我是VHDL的新手,所以我不知道如何解决这个问题。
在下面的代码中,我删除了除 FSM 部分之外的所有内容,因为其余部分运行正常并且不会生成任何锁存器。
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
entity ram_reader is
port ( —… );
end ram_reader;
architecture Behavioral of ram_reader is
type state_type is (RST,s0, s1,s2, s3, s4,s5, s6, errore);
signal CURRENT_STATE, NEXT_STATE: state_type:= RST;
begin
process (i_clk,NEXT_STATE)
begin
if(i_clk='1') then
CURRENT_STATE <= NEXT_STATE;
end if;
if(i_clk'event and i_clk='1') then
case CURRENT_STATE is
when RST =>
if(i_rst = '1')then
NEXT_STATE <= RST;
elsif(i_rst = '0' and i_start = '0')then
NEXT_STATE <= s0;
elsif(i_rst = '0' and i_start = '1') then
NEXT_STATE <= s1;
else
NEXT_STATE <= errore;
end if;
when s0 =>
if(i_start= '0' and i_rst ='0')then
NEXT_STATE<= s0;
elsif(i_start= '1' and i_rst='0')then
NEXT_STATE <= s1;
elsif(i_rst = '1')then
NEXT_STATE <= RST;
else
NEXT_STATE <= errore;
end if;
when s1 =>
if(i_start = '1' and i_rst = '0') then
NEXT_STATE <= s2;
else NEXT_STATE <= RST;
end if;
when s2 =>
if (i_rst = '0' and i_start='1') then
NEXT_STATE <= s2;
elsif( i_rst='0' and i_start='0') then
NEXT_STATE <= s3;
else
NEXT_STATE <= RST;
end if;
when s3=>
NEXT_STATE <= s4;
when s4 =>
if( i_mem_data /= check or oldb0 /= b0 or oldb1 /= b1)then
NEXT_STATE <= s5;
else
NEXT_STATE <=RST;
end if;
when s5 =>
NEXT_STATE <= s6;
when s6 =
if(i_rst = '1') then
NEXT_STATE <= RST;
elsif( i_start ='1') then
NEXT_STATE <= s1;
elsif( i_start ='0') then
NEXT_STATE<= s0;
else
NEXT_STATE <= errore;
end if;
when errore =>
NEXT_STATE <= errore;
when others =>
NEXT_STATE <=RST;
end case;
end if;
end process;
end Behavioral;
我试图解决变量 CURRENT_STATE 和 NEXT_STATE,但没有任何结果。
以下“if 子句”不检查 i_clk 的边沿,而是检查级别('1')。这意味着在 i_clk='1' 期间,CURRENT_STATE 跟随 NEXT_STATE 的每次变化。这只能通过锁存器在硬件中实现:
if(i_clk='1') then
CURRENT_STATE <= NEXT_STATE;
end if;
这个问题很容易解决,因为你根本不需要这个“if clause”。在检查时钟边沿的“if 子句”中(if(i_clk'event and i_clk='1') then),您只需将“case CURRENT_STATE is”替换为“case NEXT_STATE is”。然后您可以从您的设计中删除信号 CURRENT_STATE(之后将 NEXT_STATE 重命名为 CURRENT_STATE 可能是个好主意)。