Spring 2025 Tutorial 09 PDF
Spring 2025 Tutorial 09 PDF
What is an FSM?
A Finite State Machine (FSM) is a mathematical model used to design digital circuits that
transition between states based on inputs. FSMs are widely used in CPU control units, vending
2. Mealy Machine – Output depends on both the current state and inputs.
FSM Components
Let's design an FSM that detects a specific sequence of bits (1011) in a serial input stream.
Output '1']
Verilog Code for Sequence Detector (FSM)
module sequence_detector(
input wire clk,
input wire rst,
input wire in_bit,
output reg detected
);
typedef enum reg [2:0] {IDLE=3'b000, S1=3'b001, S2=3'b010, S3=3'b011, S4=3'b100}
state_t;
state_t state, next_state;
module sequence_detector_tb;
reg clk, rst, in_bit;
wire detected;
initial begin
$monitor("Time: %0t | Input: %b | Detected: %b", $time, in_bit, detected);
clk = 0; rst = 1; in_bit = 0;
#10 rst = 0;
#10 in_bit = 1;
#10 in_bit = 0;
#10 in_bit = 1;
#10 in_bit = 1;
#10 in_bit = 0;
#20 $finish;
end
endmodule
Submission LINK
Lab Tasks
● Description: Implement a Moore FSM that cycles through Red -> Green -> Yellow ->
Red.
● Description: Implement a Mealy FSM that releases an item after two 10¢ coins are
inserted.
1. Lab Objectives
● Understand the fundamentals of FSMs (Moore and Mealy machines).
● Implement FSMs using Verilog.
● Simulate and verify FSM behavior using testbenches.
2. Design Approach
Describe the modules you created and their functionalities.
3. Verilog Code
🔗 EDA Playground Link: [Insert URL Here]
5. Conclusion
Summarize what you learned from this lab