我想知道如果我在VHDL中实现有限状态机,是否需要在每个可能的状态中说明所有输出?即使我知道某些输出不会从一个状态改变到另一个状态,并且我也知道状态的顺序也是相同的?
例如,在这个(强制)示例中:
entity test is
port (
clk : in std_logic;
a : in std_logic;
b: out std_logic;
c: out std_logic;
);
end test;
architecture Behavioral of test is
type executionStage is (s1,s2,s3);
signal currentstate, nextstate: executionStage;
begin
process (clk)
begin
if(rising_edge(clk)) then
currentstate <= nextstate;
else
currentstate <= currentstate;
end if;
end process;
process(currentstate)
begin
case currentstate is
when s1 =>
if (a = '1') then
b <= '1';
c <= '0';
else
b <= '1';
c <= '1';
end if;
nextstate <= s2;
when s2 =>
-- b doesnt change state from s1 to here, do I need to define what it is here?
if (a = '1') then
b <= '1';
c <= '1';
else
b <= '1';
c <= '0';
end if;
nextstate <= s3;
when s3 =>
if (a = '1') then
b <= '0';
c <= '0';
else
b <= '1';
c <= '1';
end if;
nextstate <= s1;
end case;
end process;
end Behavioral;
据我理解,如果我不这样做,那么就会创建锁存器?在像那个例子中这并不是什么大问题,但如果我的机器有超过10个输出和超过10个状态,则我的VHDL文件开始看起来非常混乱,而且我确定复制和粘贴相同的内容一定是不好的做法。有更好的方法吗?编辑:我可以为输出定义一个“默认”状态吗?例如,在所有进程之外将b设置为1,然后仅在它为0的情况下定义它在case语句中的值?那样行得通吗?
when
语句内部分配值是可能的,但在其中包含的if
语句之外。在when
语句中没有要求只有一个语句(这已经在您的代码中显而易见,因为您在if
语句之外分配了nextstate
)。 - Tomi Junnila