【发布时间】:2018-12-12 17:42:36
【问题描述】:
我正在用 VHDL 编写 FSM。具体来说,它是一个同步序列检测器,它在输入中输入一个 8 位数字和一个“第一个”,该“第一个”必须仅在序列的第一个数字期间为“1”。输出由解锁和警告组成:如果序列 (36, ...) 正确,则解锁 = '1',或者如果序列错误,则警告 = '1' 或 first = '1' 不在第一个数字期间顺序。
在 VHDL 中,我使用两个进程,一个同步的,一个不同步。第二个的简化版是:
state_register_p : process(clk)
begin
if (clk'EVENT and clk = '1') then
if(rst = '0') then
current_state <= S0;
errors_num <= "00";
five_cycles <= "000";
first_error <= '1';
else
current_state <= next_state;
if correct = '0' then
errors_num <= errors_num + "01";
else
errors_num <= "00";
end if;
end if;
end if;
end process state_register_p;
combinatorial_logic_p : process(current_state, num_in, first)
begin
unlock <= '0';
warning <= '0';
case (current_state) is
when S0 =>
if (to_integer(unsigned(num_in)) = 36) and (first = '1') then
next_state <= S1;
else
next_state <= S0;
when S1 =>
correct <= '0';
if (to_integer(unsigned(num_in)) = 19) and (first = '0') and errors_num /= "11" then
next_state <= S2;
elsif first = '1' or errors_num = "11" then
next_state <= S6;
else
next_state <= S0;
end if;
when S2 =>
correct <= '0';
if (to_integer(unsigned(num_in)) = 56) and (first = '0') then
next_state <= S3;
elsif first = '1' then
next_state <= S6;
else
next_state <= S0;
end if;
when S3 =>
correct <= '0';
if (to_integer(unsigned(num_in)) = 101) and (first = '0') then
next_state <= S4;
elsif first = '1' then
next_state <= S6;
else
next_state <= S0;
end if;
when S4 =>
correct <= '0';
if (to_integer(unsigned(num_in)) = 73) and (first = '0') and (to_integer(unsigned(five_cycles)) = 5) then
next_state <= S5;
correct <= '1';
elsif first = '1' then
next_state <= S6;
else
next_state <= S0;
end if;
when S5 =>
correct <= '1';
if to_integer(unsigned(num_in)) = 36 and (first = '1') then
next_state <= S1;
else
next_state <= S0;
end if;
unlock <= '1';
when S6 =>
correct <= '0';
next_state <= S6; -- default, hold in current state
warning <= '1';
end case;
end process combinatorial_logic_p;
通过在线阅读,我知道在摩尔机器中,下一个状态仅取决于当前状态,因此输出仅在时钟沿发生变化,而在 Mealy 中,它也取决于输入,因此当输入发生变化时其输出可能会发生变化(即,不一定在时钟沿)。 .
在我的敏感度列表中,我使用 current_state 和 2 个输入(num_in 和 first),所以可以说我在描述 Mealy 机器还是它仍然是 Moore 机器,因为我正在等待下一个上升沿来更新输出?
我仍然认为是摩尔,但我不确定。谢谢
【问题讨论】:
-
这是一个 Mealy 状态机,如果输出
unlock或warning取决于任何输入num_in或first,并且输出的摩尔状态机仅取决于 @ 987654327@。这个figure 有一个很好的介绍。但是,您的代码没有显示输出是如何驱动的,假设它们不是微不足道的 0,所以请更新代码...但是您现在可能可以自己确定答案 ;-) -
谢谢@MortenZilmer。我的怀疑与许多书说在 Mealy 机器中输出可能不会在上升沿发生变化有关,但我的情况并非如此,因为输出更新是由此处未显示的过程完成的,即同步的。但是在你的图中说输出是异步的......编辑:添加了其余的代码