问题描述
我有一个有 5 个状态的 FSM.其中 3 个是通过子 FSM(UML 模式)设计的.为了在 VHDL 中实现,恕我直言,有两种方法可以做到这一点:
I have a FSM with 5 states. 3 of them are designed via sub-FSM(UML Pattern).For implementation in VHDL there are 2 ways, imho, to do that:
将它们总结为一个,这样我就有了一个包含子 FSM 的文档和一个包含一个大 FSM 的产品.
Summarize them into one, so I have a documentation with sub-FSM's and a product with one big FSM.
建立一个包含所有状态的 FSM.对于每个具有子 FSM 的状态,构建一个独立的 FSM,其中包含来自大状态的使能信号.
Build one FSM with all states. For every state which have a sub-FSM build a standalone FSM with enable signals from the big one.
这不是什么更好的问题,我认为两种方式都有其优点和缺点.但是对于 VHDL 实现,哪种方式更干净"?
This is no question about what's better, I think both ways have their advantages and disadvantages. But which way is more "clean" for VHDL implementation?
type my_big_one is (ONE,TWO_one, TWO_two, THREE_one, THREE_two, FOUR,FIVE);
对比
type my_one is (ONE, TWO, THREE, FOUR, FIVE);
type two_fsm is (TWO_one, TWO_two);
type three_fsm is (THREE_one, THREE_two);
推荐答案
分层 FSM 也是一个可行的解决方案;例如
Hierarchical FSMs are also a workable solution; for example
type main_state is (ONE, TWO, THREE, FOUR, FIVE);
type inner_state is (inner_one, inner_two);
signal main : main_state;
signal inner : inner_state;
...
case main is
when ONE => something_simple;
main <= TWO;
inner <= inner_one; -- reset inner SM
when TWO => case inner is
when inner_one => ...
when inner_two => ...
end case;
when THREE => case inner is ...
如果走极端,这将变得难以控制.但是,如果内部状态机相对简单,那么这会比三个单独的状态机以及它们的握手更清晰、更简洁,除了同步之外别无他用.
Taken to extremes this becomes unmanageable. But if the inner state machines are relatively simple, this can be clearer and less cluttered than three separate state machines along with their handshaking, which serves no purpose other than synchronisation.
我有时会使用这种模式,例如 SM 必须向 UART 发送一系列消息,而内部"状态处理驱动 UART 的细节(可能带有消息中字符的计数器).
I sometimes use this pattern where for example the SM has to send a sequence of messages to a UART, and the "inner" state deals with the details of driving the UART (perhaps with a counter for characters in the message).
我不会教条化哪个整体上更好的解决方案,这取决于上下文...
I wouldn't be dogmatic about which is a better solution overall, that depends on the context...
这篇关于子状态机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!