The provided 3-bit FSM reaches the correct states, but output Y remains HIGH after the required transition. Debug the output logic so that Y becomes HIGH only when X = 1 in State CHECK.
Observed Fault: Output Y is HIGH whenever the present state is DONE.
Expected Working: Output Y should be HIGH only when the present state is CHECK and X = 1.
Constraints
X and asynchronous active-LOW nRESET.State bus and Y.IDLE = 000, LOAD = 001, RUN = 010, CHECK = 011, and DONE = 100.Behavioral Reference
The transition label format is X / Y.

A Finite State Machine (FSM) is a sequential control circuit with a limited number of operating states. It remembers the present state and uses the inputs to choose the next state.
Example: a simple process controller.
IDLE → RUN → DONE
IDLE – waits for a start command.RUN – performs the operation.DONE – indicates completion.FSMs are widely used in controllers, sequence detectors, interfaces, and control logic.
The state register changes only at the active clock edge except when an asynchronous reset is asserted. Between active edges, it keeps the same state.
An FSM has three main blocks:

Key terms:
D flip-flops are normally used for the state register because the required next-state bit can be connected directly to the D input.
States are used for control. Use counters, registers, or flags to store values.
A state diagram shows how an FSM behaves. Each node represents a state, and each arrow shows when the FSM moves to another state.
Consider a 2-bit sequence generator controlled by CTR:
CTR = 0: 00 → 10 → 11 → 01 → 00
CTR = 1: 00 → 01 → 11 → 10 → 00
The state bits also form the generated 2-bit output sequence.
A state table gives the same information in tabular form. It shows the next state selected for every relevant present-state and input combination.
| Present State | CTR | Next State |
|---|---|---|
00 | 0 | 10 |
00 | 1 | 01 |
01 | 0 | 00 |
01 | 1 | 11 |
10 | 0 | 11 |
10 | 1 | 00 |
11 | 0 | 01 |
11 | 1 | 10 |
When several active-high inputs are 1 together, priority decides which input controls the transition.
Example priority:
FAULT > DONE > START
FAULT | DONE | START | Input Considered |
|---|---|---|---|
| 0 | 0 | 0 | None |
| 0 | 0 | 1 | START |
| 0 | 1 | X | DONE |
| 1 | X | X | FAULT |
Higher-priority inputs override lower-priority inputs.
In a Moore FSM, the output depends only on the present state.
Output = f(Present State)
Example: a 3-state process with output COMPLETE active only in state 10.

| Present State | Condition | Next State | COMPLETE |
|---|---|---|---|
00 | START=0 | 00 | 0 |
00 | START=1 | 01 | 0 |
01 | DONE=0 | 01 | 0 |
01 | DONE=1 | 10 | 0 |
10 | RESET=0 | 10 | 1 |
10 | RESET=1 | 00 | 1 |

Applications: process control, signalling, mode control, safety outputs.
In a Mealy FSM, the output depends on the present state and input.
Output = f(Present State, Input)
Example: a 3-state FSM with input X and output Z.
Output Z becomes 1 when State = 10 and X = 1

| Present State | X | Next State | Z |
|---|---|---|---|
00 | 0 | 00 | 0 |
00 | 1 | 01 | 0 |
01 | 0 | 10 | 0 |
01 | 1 | 01 | 0 |
10 | 0 | 00 | 0 |
10 | 1 | 01 | 1 |

Timing: Output can change immediately with the input.
Applications: sequence detection, handshaking, event detection, fast control decisions.
Hybrid FSM: An FSM containing both Moore-type and Mealy-type outputs is commonly called a hybrid FSM.
Example with six states:
A, B, C, D are reachable.
E and F are unreachable.
C and D are equivalent.
Consider this FSM:

| State | Output | X=0 | X=1 | Observation |
|---|---|---|---|---|
| A | 0 | B | C | Reachable |
| B | 1 | B | D | Reachable |
| C | 0 | A | C | Equivalent to D |
| D | 0 | A | D | Equivalent to C |
| E | 0 | E | F | Unreachable |
| F | 1 | F | E | Unreachable |
Reduction:
E and F.C and D.Reduced FSM:

Important: Fewer states do not always mean smaller or faster hardware.
State encoding assigns a binary bit pattern to each symbolic FSM state so that the state can be stored in flip-flops.
Binary encoding uses the minimum number of state bits.
Number of flip-flops = ceil(log2(Number of states))
For four states:
ceil(log2(4)) = 2 flip-flops
| State Name | Encoded Value |
|---|---|
| IDLE | 00 |
| LOAD | 01 |
| RUN | 10 |
| DONE | 11 |
Main benefit: low flip-flop count.
One-hot encoding uses one flip-flop for each state. Only one state bit is normally 1.
For five states:
Number of flip-flops = Number of states = 5
| State Name | Encoded Value |
|---|---|
| CLOSE | 00001 |
| OPENING | 00010 |
| OPEN | 00100 |
| CLOSING | 01000 |
| WAIT | 10000 |
One-hot encoding is commonly preferred in FPGA-oriented designs because state decoding and transition logic can be simple.
Gray encoding assigns codes so that selected adjacent states differ by only one bit.
For four states:
2 flip-flops are required.
| State Name | Encoded Value |
|---|---|
| IDLE | 00 |
| LOAD | 01 |
| RUN | 11 |
| DONE | 10 |
Main benefit: reduced state-bit switching on suitable transition paths.
| Feature | Binary | One-Hot | Gray |
|---|---|---|---|
| Definition | Minimum-bit state codes | One bit per state | Adjacent codes differ by one bit where possible |
| Logic | More decoding may be needed | Usually simple | Depends on transition structure |
| Advantage | Few flip-flops | Simple decoding | Lower switching on selected transitions |
| Limitation | Unused codes and more logic may occur | Uses more flip-flops | Not ideal for every FSM graph |
| When to Use | Compact implementation | FPGA-oriented control | Switching reduction is useful |
This example implements a four-state Moore FSM using binary encoding.
States:
IDLE → BUSY → DONE
↓
ERROR
Inputs:
runfaultOutputs:
success – 1 only in DONE.failure – 1 only in ERROR.Behavior:
IDLE: run=0 → stay in IDLE; run=1 → BUSY.BUSY: fault=1 → ERROR.BUSY: if fault=0, run=0 → stay in BUSY; run=1 → DONE.DONE: run=1 → stay in DONE; run=0 → IDLE.ERROR: return to IDLE only when run=0 and fault=0; otherwise remain in ERROR.
| State | Q1Q0 |
|---|---|
| IDLE | 00 |
| BUSY | 01 |
| DONE | 10 |
| ERROR | 11 |
Two D flip-flops are required.
For D flip-flops:
D1 = Q1+
D0 = Q0+
Q1 | Q0 | run | fault | Q1+ | Q0+ | D1 | D0 | success | failure |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 | 1 | 0 | 1 | 0 | 0 |
| 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 |
| 0 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 |
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
| 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 |
| 1 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
| 1 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 |
Rows use Q1Q0 = 00, 01, 11, 10.
Columns use run fault = 00, 01, 11, 10.
K-map for D1
Q1Q0 \ run fault | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
00 | 0 | 0 | 0 | 0 |
01 | 0 | 1 | 1 | 1 |
11 | 0 | 1 | 1 | 1 |
10 | 0 | 0 | 1 | 1 |
K-map for D0
Q1Q0 \ run fault | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
00 | 0 | 0 | 1 | 1 |
01 | 1 | 1 | 1 | 0 |
11 | 0 | 1 | 1 | 1 |
10 | 0 | 0 | 0 | 0 |
K-map for success
Q1Q0 \ run fault | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
00 | 0 | 0 | 0 | 0 |
01 | 0 | 0 | 0 | 0 |
11 | 0 | 0 | 0 | 0 |
10 | 1 | 1 | 1 | 1 |
K-map for failure
Q1Q0 \ run fault | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
00 | 0 | 0 | 0 | 0 |
01 | 0 | 0 | 0 | 0 |
11 | 1 | 1 | 1 | 1 |
10 | 0 | 0 | 0 | 0 |
D1 = Q0·fault + Q0·run + Q1·run
D0 = Q0·fault + Q0·Q1·run + Q0·Q1'·run' + Q1'·Q0'·run
success = Q1·Q0'
failure = Q1·Q0
An illegal state is a state-register code that was not assigned to any valid state.
Example with three valid states:
A = 00
B = 01
C = 10
11 = Illegal
The FSM should define a safe action if 11 occurs instead of leaving its behavior unknown.
A lock-up occurs when the FSM becomes trapped and cannot make required progress.
Example:
START → RUN ↔ WAIT
DONE is never reached.
The RUN-WAIT loop becomes a lock-up if no legal exit exists.
The reset state is the known and safe state entered after reset.
Example:
RESET → IDLE → RUN → DONE
With a synchronous reset, recovery occurs at the active clock edge. With an asynchronous reset, the state register changes as soon as reset is asserted. In both cases, reset must have clear priority over normal transitions.
State explosion occurs when too many states are created to represent counts, delays, or stored values.
Avoid:
WAIT0 → WAIT1 → WAIT2 → ... → WAIT63 → DONE
Prefer:
IDLE → WAIT → DONE
+
Counter
A safe FSM defines recovery from invalid operation.
Example:
IDLE → RUN → DONE
↑
Illegal State → SAFE → IDLE
During recovery, critical outputs should be driven to safe values.
External inputs may not be aligned with the FSM clock.
Conceptually:
Asynchronous Input → D Flip-Flop → FSM
A clocked flip-flop aligns the signal with the FSM clock, but one flip-flop alone does not provide reliable metastability containment.
For practical metastability-safe synchronization, asynchronous control inputs are commonly passed through a proper synchronizer, often two cascaded D flip-flops.
| Output Type | Main Benefit | Limitation |
|---|---|---|
| Combinational | Immediate response | Can glitch |
| Registered | Stable, clock-aligned output | Adds latency |
Example with a three-state controller:
IDLE → RUN → DONE
Done output can respond immediately to logic conditions.Done output changes only on a clock edge.Use registered outputs when stability is more important than immediate response.
A large FSM can be split when one group of states performs a separate function.
Monolithic example:

The execution states can be moved into a sub-FSM.

Partition when:
Start, Done, or Error status.The elevator door FSM controls opening, closing, obstacle handling, and a timed wait before reopening.
Circuit Requirements
The controller uses five states:
CLOSE, OPENING, OPEN, CLOSING, WAIT
Active-HIGH inputs:
obs, opn, cls
Input priority:
obs > opn > cls
CLOSE is the reset state. Only inputs relevant to the current state are evaluated. If more than one applicable input is HIGH, the priority order is followed.
State Diagram

If no transition condition is active, the FSM remains in its current state.
One-Hot Encoding
Five states use five state flip-flops.
| State | Q4 Q3 Q2 Q1 Q0 |
|---|---|
| CLOSE | 00001 |
| OPENING | 00010 |
| OPEN | 00100 |
| CLOSING | 01000 |
| WAIT | 10000 |
WAIT-State Counter
A 2-bit T-flip-flop counter measures the three one-second intervals required in WAIT. The counter and state register use the same rising-edge clock.
~CLR0 = WAIT
~CLR1 = WAIT
T0 = 1
T1 = C0
cof = C1 · C0
Both T flip-flops use a 1-second clock tick.
WAIT = 0 → active-low clear resets the counter to 00.WAIT = 1 releases the counter, which follows 00 → 01 → 10 → 11.WAIT with the counter cleared to 00.01, 10, and 11.cof = 1. The FSM samples it at the following rising edge and changes WAIT → OPENING.Time in WAIT | Counter | cof | FSM action |
|---|---|---|---|
| Entry | 00 | 0 | Remain in WAIT |
| 1 s | 01 | 0 | Remain in WAIT |
| 2 s | 10 | 0 | Remain in WAIT |
| 3 s | 11 | 1 | Request OPENING at the next edge |
This timing holds WAIT for three complete seconds. If the design must enter OPENING exactly on the third rising edge, generate the terminal-count request from count 10 instead.
The counter avoids creating separate
WAIT1,WAIT2, andWAIT3states, preventing state explosion.
Excitation Table for D Flip-Flops
X = either HIGH or LOW; the input does not affect that transition.
| Current State | obs | opn | cls | cof | Next State | D4 | D3 | D2 | D1 | D0 |
|---|---|---|---|---|---|---|---|---|---|---|
00001 | X | 0 | X | X | 00001 | 0 | 0 | 0 | 0 | 1 |
00001 | X | 1 | X | X | 00010 | 0 | 0 | 0 | 1 | 0 |
00010 | X | X | X | X | 00100 | 0 | 0 | 1 | 0 | 0 |
00100 | X | X | 0 | X | 00100 | 0 | 0 | 1 | 0 | 0 |
00100 | X | X | 1 | X | 01000 | 0 | 1 | 0 | 0 | 0 |
01000 | 1 | X | X | X | 10000 | 1 | 0 | 0 | 0 | 0 |
01000 | 0 | 1 | X | X | 10000 | 1 | 0 | 0 | 0 | 0 |
01000 | 0 | 0 | X | X | 00001 | 0 | 0 | 0 | 0 | 1 |
10000 | X | X | X | 0 | 10000 | 1 | 0 | 0 | 0 | 0 |
10000 | X | X | X | 1 | 00010 | 0 | 0 | 0 | 1 | 0 |
D Flip-Flop Equations
For present-state bits Q4...Q0:
D4 = Q3 · (obs + opn) + Q4 · ~cof
D3 = Q2 · cls
D2 = Q1 + Q2 · ~cls
D1 = Q0 · opn + Q4 · cof
D0 = Q0 · ~opn + Q3 · ~obs · ~opn
Circuit Diagram

The authentication FSM checks the entered digits one by one. The valid code is 784. A wrong digit resets the sequence, while the correct sequence unlocks the system.
Circuit Requirement
The system uses four states:
00 → Waiting for 1st digit
01 → 1st digit correct
10 → 2nd digit correct
11 → UNLOCKED
The circuit uses:
INVALID outputUNLOCK outputRESETValid code:
784
Only one digit button is pressed at a time, and it is released before the next digit is entered.
State Diagram

No key press retains the current state. RESET returns the FSM to 00 and is omitted from the diagram for clarity.
Input-Output Logic
Correct digit → Next state
Incorrect digit → 00
RESET → 00
No press → Hold current state
INVALID becomes HIGH for one incorrect-digit press.
UNLOCK becomes HIGH when the FSM reaches state 11.
Once:
UNLOCK = 1
all digit presses are ignored.
Only RESET returns the system to the locked state.
Encoding
Digit buttons 1 to 9 use a 10-to-4 encoder. Input I0 is tied LOW.
The encoder produces an active-HIGH ordinary binary code. Only one digit button may be pressed at a time. The encoded digit must remain stable while PR_EDGE is HIGH. With no button pressed, 0000 means no press, not digit 0.
| Digit | D C B A |
|---|---|
| 1 | 0001 |
| 2 | 0010 |
| 3 | 0011 |
| 4 | 0100 |
| 5 | 0101 |
| 6 | 0110 |
| 7 | 0111 |
| 8 | 1000 |
| 9 | 1001 |
All four encoder outputs are used.
Press Detector
The press detector converts a held button into one clock-cycle event.
First combine the encoder outputs:
PR = A + B + C + D
Pass PR through an active-HIGH rising-edge detector:
PR → Rising-Edge Detector → PR_EDGE
The encoded digit is passed only during PR_EDGE:
A_valid = A · PR_EDGE
B_valid = B · PR_EDGE
C_valid = C · PR_EDGE
D_valid = D · PR_EDGE
This prevents one long button press from being detected multiple times.
This FSM uses all four possible 2-bit state values:
00, 01, 10, 11
Therefore, no unused state exists.
nRESET always forces the FSM to:
00
Excitation Table
| Present State | Input Condition | Next State | D1 | D0 | INVALID | UNLOCK |
|---|---|---|---|---|---|---|
00 | No press | 00 | 0 | 0 | 0 | 0 |
00 | Digit 7 (0111) | 01 | 0 | 1 | 0 | 0 |
00 | Any other pressed digit | 00 | 0 | 0 | 1 | 0 |
01 | No press | 01 | 0 | 1 | 0 | 0 |
01 | Digit 8 (1000) | 10 | 1 | 0 | 0 | 0 |
01 | Any other pressed digit | 00 | 0 | 0 | 1 | 0 |
10 | No press | 10 | 1 | 0 | 0 | 0 |
10 | Digit 4 (0100) | 11 | 1 | 1 | 0 | 0 |
10 | Any other pressed digit | 00 | 0 | 0 | 1 | 0 |
11 | Any input | 11 | 1 | 1 | 0 | 1 |
D-Input Equations
For simpler implementation, define:
K7 = D_valid' · C_valid · B_valid · A_valid
K8 = D_valid · C_valid' · B_valid' · A_valid'
K4 = D_valid' · C_valid · B_valid' · A_valid'
NP = D_valid' · C_valid' · B_valid' · A_valid' //No Press
For present-state bits Q1 Q0:
D1 = Q1' · Q0 · K8
+ Q1 · (Q0 + NP + K4)
D0 = Q0' · (Q1' · K7 + Q1 · K4)
+ Q0 · (Q1 + NP)
Moore output:
UNLOCK = Q1 · Q0
A valid key press is detected by:
PRESS = NP'
Correct-digit logic:
CORRECT = Q1' · Q0' · K7
+ Q1' · Q0 · K8
+ Q1 · Q0' · K4
Mealy invalid output:
INVALID = PRESS · CORRECT' · (Q1 · Q0)'
Circuit Diagram

Each signal uses the same FSM. A train passing the current signal makes it RED. Events from the next signal then move it through YELLOW and back to GREEN.
Circuit Requirement
States:
GREEN, RED, YELLOW
Active-HIGH inputs:
TR
NXT
Active-HIGH output:
PRV
GREEN is the reset state.
PRVof the current signal is connected toNXTof the previous signal.
For deterministic operation, TR_P is given priority if TR_P and NXT occur together.
State Diagrams
The transition label uses NXT / PRV because each diagram fixes the value of TR_P.
For TR_P = 0, the downstream event NXT advances RED → YELLOW → GREEN. NXT does not affect GREEN.

For TR_P = 1, train detection has priority over NXT. The controller enters or remains in RED.

X = either HIGH or LOW; the value of NXT does not affect that transition.
One-Hot State Encoding
| State | Q2 Q1 Q0 |
|---|---|
| GREEN | 001 |
| RED | 010 |
| YELLOW | 100 |
Edge Detector
The digital TR input may remain HIGH for more than one clock cycle. A rising-edge detector converts it into a single pulse:
TR → Rising-Edge Detector → TR_P
The FSM uses TR_P, not the held TR level.
Invalid-State Recovery
Any invalid one-hot pattern is forced back to:
GREEN = 001
Excitation Table
X = either HIGH or LOW; the value does not affect that transition. Invalid encodings recover to 001.
| Current State | TR_P | NXT | Next State | D2 | D1 | D0 | PRV |
|---|---|---|---|---|---|---|---|
001 | 1 | X | 010 | 0 | 1 | 0 | 1 |
001 | 0 | X | 001 | 0 | 0 | 1 | 0 |
010 | 1 | X | 010 | 0 | 1 | 0 | 0 |
010 | 0 | 1 | 100 | 1 | 0 | 0 | 1 |
010 | 0 | 0 | 010 | 0 | 1 | 0 | 0 |
100 | 1 | X | 010 | 0 | 1 | 0 | 1 |
100 | 0 | 1 | 001 | 0 | 0 | 1 | 1 |
100 | 0 | 0 | 100 | 1 | 0 | 0 | 0 |
| Invalid | X | X | 001 | 0 | 0 | 1 | 0 |
D-Input Equations
For valid one-hot states, let:
G = Q0
R = Q1
Y = Q2
T = TR_P
N = NXT
Then:
D0 = ~T · (G + Y · N)
D1 = T + ~T · R · ~N
D2 = ~T · (R · N + Y · ~N)
Mealy output:
PRV = T · (G + Y) + ~T · N · (R + Y)
Note: Before operating the circuit, press
nRESETto initialize it to a valid state.
Circuit Diagram

This diagram contains one signal controller. NXT is provided using a digital input, and PRV is monitored using a digital output.
FSM Communication
For two adjacent controllers:
Signal 1 and Signal 2 are GREEN.Signal 1, TR1_P = 1 and Signal 1 → RED.Signal 2, Signal 2 → RED and PRV2 = 1.PRV2 is connected to NXT1, so Signal 1: RED → YELLOW.NXT2 event advances Signal 2, generating another PRV2 pulse.Signal 1: YELLOW → GREEN.Connection:
NXT1 = PRV2
Both PRV1 and PRV2 can be monitored using digital outputs.
Complete Communication Circuit Diagram
