Codiode

Sequence Detector: 101

MediumVerilog / SystemVerilogBuild1 solved

Design a Moore finite state machine that detects the bit sequence 101 on a serial input x.

Output z is asserted to 1 for exactly one clock cycle when the last three received bits are 1, 0, 1 in order.

State Encoding

State Meaning z
S0 Idle 0
S1 Received "1" 0
S2 Received "10" 0
S3 Received "101" 1

Transitions

Current x=0 x=1
S0 S0 S1
S1 S2 S1
S2 S0 S3
S3 S2 S1

After detection (S3), the FSM checks for overlapping sequences. If x=0, suffix "10" matches a prefix of "101" so it returns to S2. If x=1, suffix "1" matches so it goes to S1.

FSMs are the backbone of protocol controllers, parsers, and CPU control units.

Constraints

  • Moore machine — output z depends only on current state, not x
  • Synchronous active-high reset returns FSM to S0 with z=0
  • Overlapping sequences allowed (after detection, transition correctly)
  • Use an always block for state register and a separate one for next-state logic
  • Enumerate your states clearly (parameter or localparam)

Topics

SequentialFSMMoore Machine

Solve this problem

Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.

This problem is part of Codiode Pro. The statement above is free to read.

The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.

Part of FSM Coding

Problem 7 of 15 in the FSM Coding track.

Related problems

Browse all problems · Verilog practice problems · Learning tracks

Solve this on a laptopSend yourself the link and continue there.