Draft preview. Lessons are being written and reviewed.

Digital Design / Module 6: Finite state machines

33. Moore and Mealy machines

Know the timing difference, not just the definition.

Lecture coming soon

See it move

The idea

The difference lies in what the output depends on.

MooreMealy
Output depends onState onlyState and current input
ResponseNext cycle, after the state changesSame cycle as the input
States neededOften moreOften fewer
Output glitchesDepends only on state logicInput glitches can pass through

What this means for timing

A Mealy output reacts in the same cycle as the input, which saves a cycle. The cost is a combinational path from input to output. This path joins with logic in the neighbouring blocks, and it can make timing harder. Inputs that wiggle also pass directly to the output.

A Moore output changes only after a state change, so it is steady for the whole cycle and easy to time, but it responds a cycle later.

Registered outputs

A common professional choice is a Mealy-style calculation with a register on the output. This is clean and -free, with Moore-like timing. Many teams require registered outputs at block boundaries.

Compare them directly

In the animation above, both machines detect the pattern 11. They watch identical inputs, but the Mealy machine responds one cycle sooner and uses only two states. The Moore machine needs a third state, whose whole purpose is to say "I have seen it".

Common mistake

Reciting only the definition. Interviewers follow up with: which is faster, which is safer, and how would each look on a waveform? Be ready to sketch the one-cycle difference and mention the combinational input-to-output path.

Key ideas

  • Moore output depends on state; Mealy on state and input.
  • Mealy can respond one cycle sooner, often with fewer states.
  • Registered outputs avoid glitches.

Lab: your code, animated

Your exercise

Design the same detector both ways, comparing timing.

Interview questions

coreWhich responds sooner?

basicWhat is the difference between a Moore and a Mealy machine, and what does that mean for when the output responds?

basicA machine detects two 1s in a row on a serial input. How many states does the Moore version need, and how many does the Mealy version need?

coreOn the 11 detector, the input over five cycles is 0, 1, 1, 1, 0, changing just after each clock edge. In which cycles is each output high?

coreA Mealy output's input arrives 6.0 ns after the clock edge from another block. The Mealy logic takes 1.5 ns, the logic in the receiving block 2.0 ns, and the capture flop's setup is 0.3 ns, on a 10 ns clock. Does it meet timing?

coreThis registers the Mealy output of the 11 detector. How does mealy_r's timing compare with the Moore machine?

assign mealy = seen & din;

always @(posedge clk) begin
  seen    <= din;
  mealy_r <= seen & din;
end

coreThe input to a Mealy machine has a brief glitch in the middle of a cycle. What happens to the Mealy and Moore outputs?

advancedA Moore machine with binary state encoding decodes an output from two state bits. Can that output still glitch, and how do you avoid it?

advancedBlock A has a Mealy output that feeds block B, and B has a Mealy output that feeds back into A. What can go wrong?

Practise these 9 questions with animations