Nonoverlapping Sequence Detector with Abort
Frame parsers look for a start marker in a serial stream. When the link reports an error, an abort input throws away whatever partial match the parser has.
The seq_detector module monitors a serial input stream seq_in and asserts the detected output for exactly one clock cycle immediately following the successful reception of the sequence 1011. The detection must be strictly non-overlapping; after a successful detection, the FSM resets its search, meaning the sequence 1011011 will only trigger a single detection. If the abort signal is asserted at any time, the FSM immediately abandons its current progress and returns to the initial search state on the next clock edge.
Clock edge: posedge clk
Reset type: Asynchronous, active-low rst_n
Reset values: FSM returns to IDLE, detected becomes 0
Priority rules: abort has strict priority over seq_in. If abort is 1, the FSM must transition to IDLE regardless of the value of seq_in.
Cycle 1: rst_n=0 → state=IDLE, detected=0
Cycle 2: rst_n=1, abort=0, seq_in=1 → state=S1, detected=0
Cycle 3: abort=0, seq_in=0 → state=S10, detected=0
Cycle 4: abort=0, seq_in=1 → state=S101, detected=0
Cycle 5: abort=0, seq_in=1 → state=DETECT, detected=1 (Sequence 1011 complete)
Cycle 6: abort=0, seq_in=1 → state=S1, detected=0 (Non-overlapping: evaluates the new '1' as start of next sequence)
Cycle 7: abort=0, seq_in=0 → state=S10, detected=0
Cycle 8: abort=1, seq_in=1 → state=IDLE, detected=0 (abort overrides seq_in)
(Note: For diagram clarity, the synchronous abort transitions are omitted, but an asserted abort forces a transition to IDLE from any state).
| Signal | Direction | Width | Description |
|---|---|---|---|
clk |
input | 1 | Positive-edge triggered clock |
rst_n |
input | 1 | Asynchronous active-low reset; FSM goes to IDLE and detected goes to 0 |
seq_in |
input | 1 | Serial data input stream |
abort |
input | 1 | Synchronous abort; forces FSM to IDLE on the next clock edge |
detected |
output | 1 | Asserted high for one cycle immediately after 1011 is fully received |
Constraints
- Clock edge and reset polarity:
posedge clk, active-low asynchronousrst_n. - Output values on reset:
detectedmust be 0. - Priority:
aborthas strict priority overseq_in. Ifabortis 1, the FSM must transition to IDLE regardless ofseq_in. - Non-overlapping: The FSM must reset its search after a successful detection. The bit evaluated during the DETECT state is treated as the first bit of a potential new sequence.
- Output timing:
detectedmust be high for exactly one clock cycle immediately following the successful reception of the final '1' in1011. A Moore machine where the output is tied to a specific state is required to meet this timing.
Topics
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 6 of 15 in the FSM Coding track.
Related problems
Browse all problems · Verilog practice problems · Learning tracks