Substatemachine

前端 未结 2 1713
悲哀的现实
悲哀的现实 2021-01-16 10:36

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:

  1. Summarize them

相关标签:
2条回答
  • 2021-01-16 10:59

    One good solution is to build 2 FSMs:
    - the main FSM and
    - the sub-FSM(s).

    Both FSMs communicate via a handshake protocol.

    For example the main FSM enters state TWO. While doing so, the sub-FSM starts its processing, triggered by a signal from main-FSM. When FSM TWO completes, it triggers an signal back to the main FSM, which goes to state TREE.

    Using this "pattern" allows you to connect as many FSMs as needed. Some tasks like waiting or address counting can be outsourced into counters, which are just special FSMs.

    0 讨论(0)
  • 2021-01-16 11:03

    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.

    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...

    0 讨论(0)
提交回复
热议问题