Contact us Start a Trial
Article illustration

In A Nutshell

Everything You Need to Know About FSMs

Finite State Machines (FSMs) are an essential tool in a digital designers toolkit, especially when control flow, sequencing, and decision-making are involved. Whether you’re writing RTL code for FPGAs or crafting a control unit for a processor, FSMs play a central role in simplifying complex behaviors.

This article distills key insights from expert resources to give you a full-spectrum understanding of FSMs โ€” from theory to VHDL implementation.


๐Ÿง  What Is an FSM?

An FSM is a computation model that can exist in exactly one state at a time, and transitions between states based on inputs and conditions. Itโ€™s ideal for modeling systems that respond to sequential inputs over time.

FSMs are classified into two main types:

1. Moore Machine

  • Outputs depend only on the current state.
  • Simpler timing, but may need more states.

2. Mealy Machine

  • Outputs depend on current state and inputs.
  • Typically requires fewer states, but can be more timing-sensitive.

โœ… Use Moore when output timing needs to be predictable.
โœ… Use Mealy when design compactness matters more.


๐Ÿ› ๏ธ FSM Design Styles in VHDL

There are two dominant coding styles for FSMs in VHDL:

๐Ÿ” 1. Single Process FSM

All logic (state transitions, registers, and outputs) are inside one clocked process. It’s easier for simple FSMs, but can get messy in complex systems.

๐Ÿ“˜ Source: VHDLwhiz โ€“ Finite State Machine 


Typically split into 3 processes:

  1. Synchronous process for state register
  2. Combinational process for next state logic
  3. Combinational process for output logic

๐Ÿ“˜ Source: VHDLwhiz โ€“ N-process FSM 


๐Ÿงฌ FSM Encoding: Binary vs One-Hot

๐Ÿงฎ Binary Encoding

  • Minimum number of flip-flops (logโ‚‚(N) for N states).
  • May produce complex combinational logic.

๐Ÿ”ฅ One-Hot Encoding

  • One flip-flop per state; only one bit is โ€˜1โ€™ at any time.
  • Simple logic and faster transitions.
  • Ideal for FPGAs, which have abundant flip-flops.

๐Ÿ“˜ Source: Sigasi โ€“ One-Hot FSM


๐Ÿงช Practical Example: Sequence Detector FSM

A great example is a Sequence Detector โ€” a design that detects a specific bit pattern in a stream.

  • Moore FSM delays output until entering the final state.
  • Mealy FSM gives output immediately once the final input is received.

๐Ÿ“˜ Source: AllAboutFPGA โ€“ Sequence Detector 


๐Ÿ’ฃ Common Pitfalls in FSM Design

  • โŒ Unintentional Latches: Forgetting default values in combinational processes.
  • โŒ Improper Resets: Poor reset strategies cause simulation-synthesis mismatches.
  • โŒ Inconsistent Output Timing: Mealy FSMs can glitch if not handled carefully.

โœ… Always simulate thoroughly
โœ… Use enumerated types
โœ… Keep output logic isolated from state transitions


โœ… Best Practices for FSM Design

  1. Use enumerated types for states
  2. Isolate logic into 3 processes
  3. Add default assignments in combinational logic
  4. Comment your state transitions
  5. Modularize FSMs for reuse

๐Ÿงฐ Sample FSM Skeleton in VHDL (3-Process)

type state_type is (IDLE, LOAD, PROCESS, DONE);
signal state, next_state: state_type;

-- 1. State register
	process(clk, reset)
	begin
		if reset = '1' then
			state <= IDLE;
		elsif rising_edge(clk) then
			state <= next_state;
		end if;
	end process;

	-- 2. Next state logic
	process(state, start, execution_complete)
	begin
		case state is
			when IDLE =>
				if start = '1' then
					next_state <= LOAD;
				else
					next_state <= IDLE;
				end if;
			when LOAD =>
				next_state <= EXECUTE;
			when EXECUTE =>
				if execution_complete = '1' then
					next_state <= DONE;
				else
					next_state <= EXECUTE;
				end if;
			when DONE =>
				next_state <= IDLE;
		end case;
	end process;

	-- 3. Output logic
	-- In this example 'output' is just a signal resembling some output logic
	process(state)
	begin
		case state is
			when IDLE    => output <= '0';
			when LOAD    => output <= '0';
			when EXECUTE => output <= '1';
			when DONE    => output <= '0';
		end case;
	end process;

๐Ÿš€ Why FSMs Are Essential for RTL Engineers

FSMs are fundamental for:

โœ… Communication protocols โœ… CPU control units โœ… Robotic control logic โœ… Protocol engines โœ… Traffic light controllers

By mastering FSMs, your HDL becomes easier to simulate, synthesize, and scale.

Want to see how Sigasi Visual HDL helps design better FSMs faster?

Mastering FSMs with Sigasi Visual HDL

FSMs play a central role in simplifying complex behaviors and itโ€™s one of the most transferable skills across ASIC, FPGA, and SoC development. Sigasi visualizes FSMs in real-time while you write.

Product screenshot on laptop

2025-07-03, last modified on 2025-07-04