【发布时间】:2011-08-25 10:53:55
【问题描述】:
只是想知道我是否在 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 文件开始看起来非常混乱,我确信复制它一定是不好的做法并一遍又一遍地粘贴相同的东西。有更好的方法吗?
编辑:我可以为输出定义“默认”状态吗? IE 在所有进程之外将 b 设置为 1,然后仅在它为 0 的 case 语句中定义它是什么?这行得通吗?
【问题讨论】: