Challenge - 5 Problems
Mealy Machine Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of a simple Mealy machine process
Consider this VHDL process implementing a Mealy machine with one input
x and output z. What is the output z after the input sequence x = 1, 0, 1 if the initial state is S0?VHDL
library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity mealy_example is Port ( clk : in STD_LOGIC; reset : in STD_LOGIC; x : in STD_LOGIC; z : out STD_LOGIC); end mealy_example; architecture Behavioral of mealy_example is type state_type is (S0, S1); signal state, next_state : state_type; begin process(clk, reset) begin if reset = '1' then state <= S0; elsif rising_edge(clk) then state <= next_state; end if; end process; process(state, x) begin case state is when S0 => if x = '1' then next_state <= S1; z <= '1'; else next_state <= S0; z <= '0'; end if; when S1 => if x = '1' then next_state <= S0; z <= '0'; else next_state <= S1; z <= '1'; end if; end case; end process; end Behavioral;
Attempts:
2 left
💡 Hint
Trace the state transitions and output for each input step starting from S0.
✗ Incorrect
Starting at S0 with x=1, output z=1 and next state S1. Then at S1 with x=0, output z=1 and stay in S1. But the code sets z=1 only if x=0 in S1, so second output is 1. However, the question asks for the output after each input, so the sequence is z=1 (first input), z=1 (second input), then for x=1 at S1, output z=0 and next state S0. So the output sequence is 1, 1, 0. But the code assigns z in the combinational process, so the output corresponds to the current input and state. The correct sequence is 1, 1, 0 because after the first input, output is 1; second input 0 at S1 outputs 1; third input 1 at S1 outputs 0.
🧠 Conceptual
intermediateUnderstanding Mealy machine output timing
In a Mealy machine implemented in VHDL, when is the output
z updated relative to the clock edge?Attempts:
2 left
💡 Hint
Recall how Mealy machines produce outputs based on current state and inputs.
✗ Incorrect
Mealy machine outputs depend on current state and inputs, so outputs are generated by combinational logic and update immediately when inputs or state change, not waiting for clock edges.
🔧 Debug
advancedIdentify the error in this Mealy machine VHDL code
What error will this VHDL code produce when compiled?
VHDL
architecture Behavioral of mealy_bug is type state_type is (IDLE, BUSY); signal state, next_state : state_type; begin process(clk) begin if rising_edge(clk) then state <= next_state; end if; end process; process(state, input_signal) begin case state is when IDLE => if input_signal = '1' then next_state <= BUSY; output_signal <= '1'; else next_state <= IDLE; output_signal <= '0'; end if; when BUSY => next_state <= IDLE; output_signal <= '1'; end case; end process; end Behavioral;
Attempts:
2 left
💡 Hint
Check if all possible paths assign 'next_state' in the combinational process.
✗ Incorrect
The architecture declares 'state' and 'next_state', but 'output_signal' is not declared as a signal. Assigning to an undeclared identifier 'output_signal' (and similarly 'input_signal' and 'clk') will cause compilation errors, matching option A.
📝 Syntax
advancedIdentify the syntax error in this Mealy machine snippet
Which option correctly fixes the syntax error in this VHDL code snippet?
VHDL
process(state, x)
begin
case state is
when S0 =>
if x = '1' then
next_state <= S1
z <= '1';
else
next_state <= S0;
z <= '0';
end if;
when S1 =>
next_state <= S0;
z <= '0';
end case;
end process;Attempts:
2 left
💡 Hint
Check missing semicolons in VHDL statements.
✗ Incorrect
VHDL requires semicolons after each signal assignment. The line 'next_state <= S1' is missing a semicolon, causing a syntax error.
🚀 Application
expertDesign a Mealy machine output for a sequence detector
You want to design a Mealy machine in VHDL that outputs '1' when the input sequence '101' is detected on input
x. Which of these state transition and output assignments correctly implements this behavior?Attempts:
2 left
💡 Hint
The output should be '1' only when the full sequence '101' is detected at the last input.
✗ Incorrect
Option C correctly outputs '1' only when the sequence '101' is detected at state S2 with input '1'. Other options output '1' at wrong states or inputs.
