当我学习如何在VHDL中表达有限状态机时,它采用了双进程架构.一个进程处理时钟/复位信号,另一个进程处理更新状态和输出的组合逻辑.一个例子如下.
我已经看到这种风格受到批评(例如,参见这个问题的评论和答案),但从未详细说明.我想知道这背后是否存在客观(ish)原因.
是否有技术原因可以避免这种风格?Xilinx的合成器似乎将其检测为状态机(您可以在输出中看到它并验证转换),但其他人是否在努力解决它,或者生成质量差的实现?
这不是惯用的VHDL吗?记住要避免基于意见的答案; 如果它不是惯用的,是否有广泛使用的教学资源或参考使用不同的风格?习惯风格也可以存在,因为,例如.有一些错误很容易用正确的风格捕获,或者因为代码结构可以更好地表达问题域,或者出于其他原因.
(请注意,我不是要求定义或演示不同的样式,我想知道是否有客观原因要特别避免双过程实现.)
一些示例可以在Free Range VHDL(p89)中找到.这是一个非常简单的例子:
library ieee;
use ieee.std_logic_1164.all;
-- Moore state machine that transitions from IDLE to WAITING, WAITING
-- to READY, and then READY back to WAITING each time the input is
-- detected as on.
entity fsm is
port(
clk : in std_logic;
rst : in std_logic;
input : in std_logic;
output : out std_logic
);
end entity fsm;
architecture fsm_arc of fsm is
type state is (idle, waiting, ready);
signal prev_state, next_state : state;
begin
-- Synchronous/reset process: update state on clock edge and handle
-- reset action.
sync_proc: process(clk, rst)
begin
if (rst = '1') then
prev_state <= idle;
elsif (rising_edge(clk)) then
prev_state <= next_state;
end if;
end process sync_proc;
-- Combinatorial process: compute next state and output.
comb_proc: process(prev_state, input)
begin
case prev_state is
when idle =>
output <= '0';
if input = '1' then
next_state <= waiting;
else
next_state <= idle;
end if;
when waiting =>
output <= '1';
if input = '1' then
next_state <= ready;
else
next_state <= waiting;
end if;
when ready =>
output <= '0';
if input = '1' then
next_state <= waiting;
else
next_state <= ready;
end if;
end case;
end process comb_proc;
end fsm_arc;
Run Code Online (Sandbox Code Playgroud)
(请注意,我现在无法访问合成器,因此可能会出现一些错误.)
我总是推荐单进程状态机,因为它避免了两类与初学者非常相似的基本错误:
不太重要的是,组合过程降低了模拟效率.
不太客观,我发现它们更容易阅读和维护; 它们需要更少的锅炉板,我不必保持灵敏度列表与逻辑同步.
小智 0
参考文献中有对此的详细描述。[1]如下。首先,FSM 被分为 3 类(第一次这样做),然后对每一类进行彻底检查,并提供许多完整的示例。您可以在第 107-115 页找到 1 类(常规)有限状态机问题的确切答案;第 185-190 页适用于 2 类(定时)机器;第 245-248 页介绍了 3 类(递归)状态机。Moore 和 Mealy 版本的模板分别在三个类别中进行了详细描述。
[1] V. Pedroni,硬件中的有限状态机:理论与设计(使用 VHDL 和 SystemVerilog),麻省理工学院出版社,2013 年 12 月。
| 归档时间: |
|
| 查看次数: |
3443 次 |
| 最近记录: |