Challenge - 5 Problems
Sequence Detector Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of a simple sequence detector FSM
What is the output of this VHDL sequence detector FSM when the input sequence is 110110?
VHDL
library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity seq_detector is Port ( clk : in STD_LOGIC; rst : in STD_LOGIC; din : in STD_LOGIC; dout : out STD_LOGIC); end seq_detector; architecture Behavioral of seq_detector is type state_type is (S0, S1, S2, S3); signal state, next_state : state_type; begin process(clk, rst) begin if rst = '1' then state <= S0; elsif rising_edge(clk) then state <= next_state; end if; end process; process(state, din) begin dout <= '0'; case state is when S0 => if din = '1' then next_state <= S1; else next_state <= S0; end if; when S1 => if din = '1' then next_state <= S2; else next_state <= S0; end if; when S2 => if din = '0' then next_state <= S3; else next_state <= S2; end if; when S3 => dout <= '1'; if din = '1' then next_state <= S1; else next_state <= S0; end if; end case; end process; end Behavioral;
Attempts:
2 left
💡 Hint
Trace the FSM states step-by-step for each input bit and note when dout becomes '1'.
✗ Incorrect
The FSM detects the sequence '110' and sets dout to '1' when the sequence is detected at the last input bit. For input 110110, the output is '000010' because the sequence '110' appears starting at the first bit and again starting at the fourth bit, but only the second occurrence triggers dout at the fifth input bit.
🧠 Conceptual
intermediateUnderstanding state transitions in sequence detector FSM
In the given FSM, what is the purpose of state S2?
Attempts:
2 left
💡 Hint
Look at the transitions from S1 to S2 and from S2 to S3.
✗ Incorrect
State S2 is reached after detecting two consecutive '1's. It waits for a '0' to complete the sequence '110'.
🔧 Debug
advancedIdentify the error causing incorrect output in FSM
This FSM is supposed to detect the sequence '110' but it never outputs '1'. What is the error?
VHDL
process(state, din)
begin
dout <= '0';
case state is
when S0 =>
if din = '1' then
next_state <= S1;
else
next_state <= S0;
end if;
when S1 =>
if din = '1' then
next_state <= S2;
else
next_state <= S0;
end if;
when S2 =>
if din = '0' then
next_state <= S3;
else
next_state <= S2;
end if;
when S3 =>
dout <= '1';
if din = '1' then
next_state <= S1;
else
next_state <= S0;
end if;
end case;
end process;Attempts:
2 left
💡 Hint
Consider how dout is assigned in the process and when it might be reset.
✗ Incorrect
Assigning dout to '0' at the start of the combinational process resets it every time the process runs, so dout never stays '1'.
📝 Syntax
advancedIdentify the syntax error in FSM code snippet
Which option contains the syntax error preventing this FSM from compiling?
VHDL
process(clk, rst)
begin
if rst = '1' then
state <= S0;
elsif rising_edge(clk) then
state <= next_state;
end if;
end process;Attempts:
2 left
💡 Hint
Check each line for missing punctuation.
✗ Incorrect
In VHDL, each statement must end with a semicolon. The line 'state <= S0' is missing a semicolon.
🚀 Application
expertNumber of states in a sequence detector FSM for '1011'
How many states are needed in a Moore FSM to detect the sequence '1011' overlapping allowed?
Attempts:
2 left
💡 Hint
Count states for each prefix of the sequence including the initial state.
✗ Incorrect
For sequence '1011', the FSM needs one initial state plus one state for each prefix: '', '1', '10', '101', '1011' totaling 5 states.
