This is going to be a short article on Mealy and Moore state machines. It is common to get asked which one would you prefer to build a state machine and why in an interview. I will cover their common characteristics and differences to help you decide which one you should prefer next time you are building something using state machines.
Mealy State Machine:
Mealy state machine output depends on present state and present inputs. Due to this, the outputs of a Mealy Machine can change asynchronously in response to any change in the inputs.
Mealy outputs allow an input to appear after the cycle has started. Hence, there is a possibility of propagating a glitch on Mealy output.
Due to the same reason mentioned in point 2, Mealy machines are hard to meet timing.
Mealy machine has output associated with inputs. For this reason, they generally need one less state as compared to Moore machine.
Mealy machines react faster to input, they generally react in the same clock cycle in which the input was seen.
Moore State Machine:
Moore state machine output depends only on present state.
There is less possibility of a glitch getting propagated to Moore output.
Moore machines have a full cycle to settle through the combinatorial logic and are therefore easier to meet required cycle times.
Moore has output associated with states. We need 1 extra state in Moore than in Mealy, because to generate output, we need to go to another state.
Moore machines react to input a cycle late.
This picture perfectly resonates my points for Mealy and Moore machines mentioned above.
Picture taken from Sunburst Design Paper
Conclusion:
You should not use Mealy machine unless absolutely necessary. It has far more cons than pros in comparison to Moore machines.
I would like to end this article with a question for you. What can you do to avoid propagating glitches in Mealy output?
Think about it. See you in the next article!