ece
Sequential Circuits & FSM (Moore vs Mealy)
Flip-flops, counters and finite state machines — the classic 'design a 1011 sequence detector' whiteboard question.
QualcommTexas InstrumentsIntelSamsung
Key formulas
Q(n+1) = D
Characteristic equation D-FF: D flip-flop transparently stores next-state value at the clock edge — the workhorse of FSM synthesis.
Q(n+1) = J·Q' + K'·Q
Characteristic equation JK-FF: J=K=1 toggles, J=K=0 holds — JK is the 'universal' flip-flop used to derive T and D behaviour.
Cheat sheet
- ▸Latches are level-triggered; flip-flops are edge-triggered — the clock edge freezes the input window.
- ▸Moore output depends only on state (glitch-free, +1 clock latency); Mealy output depends on state + input (fewer states, faster).
- ▸Every FSM needs: state register, next-state logic (combinational), output logic, and a defined reset state.
- ▸Sequence detector design flow: draw the state diagram → encode states (binary/one-hot/Gray) → derive next-state equations → verify with a timing trace.
- ▸Counters: a mod-N counter has ⌈log₂N⌉ flip-flops and unused states — design them to safely return to the count sequence.
- ▸One-hot encoding uses one FF per state: simple decode logic, great for FPGAs; binary encoding minimises flip-flops.
Moore vs Mealy machine
| Aspect | Moore | Mealy |
|---|---|---|
| Output depends on | State only | State + current input |
| States needed | Usually more | Usually fewer |
| Output timing | Changes on clock edge (registered) | Can change with input (combinational) |
| Glitch risk | Low | Higher — outputs can ripple with inputs |
| Sequence-detector latency | Detects one cycle later | Detects in the same cycle |
Visual
Mealy 1011 detector (partial): S0 --1/0--> S1 --0/0--> S2 --1/0--> S3 --1/1--> S1 output z = 1 when input x=1 while in S3 (Mealy: same edge)
Top 4 campus interview questions
MCQ mastery quiz
1. A Moore machine's outputs can change…
2. How many flip-flops are needed for a mod-10 (decade) counter?
3. In a JK flip-flop with J=1, K=1, at the clock edge the output…
4. For FPGA implementations, one-hot encoding is often preferred because…