Challenge - 5 Problems
Sequence Detector Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple sequence detector FSM
What is the output sequence of this FSM when the input sequence is 1,0,1,1,0,1?
The FSM detects the sequence '101' and outputs 1 when detected, else 0.
The FSM detects the sequence '101' and outputs 1 when detected, else 0.
Verilog
module seq_detector(input clk, input reset, input in, output reg out); typedef enum reg [1:0] {S0, S1, S2} state_t; state_t state, next_state; always @(posedge clk or posedge reset) begin if (reset) state <= S0; else state <= next_state; end always @(*) begin out = 0; case(state) S0: if (in) next_state = S1; else next_state = S0; S1: if (!in) next_state = S2; else next_state = S1; S2: begin if (in) begin next_state = S1; out = 1; end else next_state = S0; end default: next_state = S0; endcase end endmodule
Attempts:
2 left
💡 Hint
Trace the FSM states step-by-step for each input bit.
✗ Incorrect
The FSM outputs 1 only when the sequence '101' is detected ending at the current input. For the input sequence 1,0,1,1,0,1, the output is 0 until the last input where the sequence completes.
🧠 Conceptual
intermediate1:30remaining
Understanding overlapping sequences in FSM
Why is it important for a sequence detector FSM to handle overlapping sequences?
Consider detecting '101' in a stream like '10101'.
Consider detecting '101' in a stream like '10101'.
Attempts:
2 left
💡 Hint
Think about sequences that share bits between detections.
✗ Incorrect
Overlapping sequences allow the FSM to detect sequences that share bits, like '101' in '10101' where the last '1' of the first sequence is the first '1' of the next.
🔧 Debug
advanced2:30remaining
Identify the error in this sequence detector FSM code
This FSM is supposed to detect the sequence '110'. What error causes it to never output 1?
Verilog
module seq_detector(input clk, input reset, input in, output reg out); typedef enum reg [1:0] {S0, S1, S2} state_t; state_t state, next_state; always @(posedge clk or posedge reset) begin if (reset) state <= S0; else state <= next_state; end always @(*) begin out = 0; case(state) S0: if (in) next_state = S1; else next_state = S0; S1: if (in) next_state = S2; else next_state = S0; S2: if (!in) begin next_state = S0; out = 1; end else next_state = S2; default: next_state = S0; endcase end endmodule
Attempts:
2 left
💡 Hint
Check how the FSM transitions from S2 on input 1.
✗ Incorrect
The FSM stays in S2 on input 1, so it does not allow overlapping detection of sequences starting with '1' again, causing missed detections.
📝 Syntax
advanced1:30remaining
Identify the syntax error in this FSM Verilog code
Which option correctly fixes the syntax error in this FSM code snippet?
Verilog
always @ (posedge clk or posedge reset) begin if reset state <= S0; else state <= next_state; end
Attempts:
2 left
💡 Hint
Check the syntax for if statements in Verilog.
✗ Incorrect
In Verilog, the condition in an if statement must be enclosed in parentheses.
🚀 Application
expert3:00remaining
Number of states in a sequence detector FSM
How many states are required in a Moore FSM to detect the sequence '1011' with overlapping allowed?
Attempts:
2 left
💡 Hint
Count states representing each prefix of the sequence including the empty prefix.
✗ Incorrect
For a sequence of length N, a Moore FSM detecting overlapping sequences typically needs N+1 states representing progress from no match to full match.