Challenge - 5 Problems
Two-process FSM Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of a two-process FSM with synchronous reset
Consider the following VHDL two-process FSM code snippet. What is the value of
state after the third rising clock edge if reset is deasserted at the second clock edge?type state_type is (IDLE, S1, S2);
signal state, next_state : state_type;
-- Clock process
process(clk)
begin
if rising_edge(clk) then
if reset = '1' then
state <= IDLE;
else
state <= next_state;
end if;
end if;
end process;
-- Next state logic
process(state, input_signal)
begin
case state is
when IDLE =>
if input_signal = '1' then
next_state <= S1;
else
next_state <= IDLE;
end if;
when S1 =>
next_state <= S2;
when S2 =>
next_state <= IDLE;
end case;
end process;VHDL
type state_type is (IDLE, S1, S2); signal state, next_state : state_type; process(clk) begin if rising_edge(clk) then if reset = '1' then state <= IDLE; else state <= next_state; end if; end if; end process; process(state, input_signal) begin case state is when IDLE => if input_signal = '1' then next_state <= S1; else next_state <= IDLE; end if; when S1 => next_state <= S2; when S2 => next_state <= IDLE; end case; end process;
Attempts:
2 left
💡 Hint
Trace the state transitions step-by-step considering the reset and input_signal values at each clock edge.
✗ Incorrect
Initially, state is IDLE due to reset. At first clock edge after reset deassertion, if input_signal is '1', next_state becomes S1. At second clock edge, state updates to S1, next_state updates to S2. At third clock edge, state updates to S2. Thus, after the third clock edge, state is S2.
🧠 Conceptual
intermediatePurpose of separating state register and next state logic in two-process FSM
In a two-process FSM coding style in VHDL, why do we separate the state register update and the next state logic into two different processes?
Attempts:
2 left
💡 Hint
Think about how synchronous and combinational logic are typically coded in VHDL.
✗ Incorrect
The two-process style separates the synchronous state register update (clocked process) from the combinational next state logic (combinational process). This separation improves code clarity and helps synthesis tools generate efficient hardware.
🔧 Debug
advancedIdentify the error in this two-process FSM code
What is the error in the following two-process FSM VHDL code snippet?
process(clk)
begin
if rising_edge(clk) then
if reset = '1' then
state <= IDLE;
else
state <= next_state;
end if;
end if;
end process;
process(state)
begin
case state is
when IDLE =>
if input_signal = '1' then
next_state <= S1;
else
next_state <= IDLE;
end if;
when S1 =>
next_state <= S2;
when S2 =>
next_state <= IDLE;
end case;
end process;Attempts:
2 left
💡 Hint
Consider what signals the combinational process depends on to update next_state correctly.
✗ Incorrect
The combinational process that calculates next_state depends on both state and input_signal. Missing input_signal in the sensitivity list can cause simulation mismatches or incorrect behavior in simulation, even if synthesis tools may infer it correctly.
📝 Syntax
advancedSyntax error in two-process FSM next state logic
Which option contains the correct syntax for the next state combinational process in a two-process FSM?
Assume
Options:
Assume
state and next_state are of an enumerated type with states IDLE, S1, S2, and input_signal is a std_logic.Options:
Attempts:
2 left
💡 Hint
Remember that signal assignment in VHDL uses '<=' and enumerated states are not strings.
✗ Incorrect
Option D uses correct signal assignment '<=' and assigns enumerated states directly. Option D uses '=' which is variable assignment and invalid for signals. Option D uses ':=' which is for variables, not signals. Option D uses string literals for states which is invalid.
🚀 Application
expertNumber of states and output values in a Moore FSM two-process design
You design a Moore FSM using the two-process style in VHDL. The FSM has 4 states: IDLE, READ, WRITE, DONE. The output signal
Given the following code snippet for the output logic process:
How many clock cycles after reset will it take for
done_flag is '1' only in the DONE state and '0' otherwise.Given the following code snippet for the output logic process:
process(state)
begin
case state is
when DONE =>
done_flag <= '1';
when others =>
done_flag <= '0';
end case;
end process;How many clock cycles after reset will it take for
done_flag to become '1' if the FSM transitions IDLE -> READ -> WRITE -> DONE on consecutive clock cycles with no stalls?Attempts:
2 left
💡 Hint
Count the clock edges needed to reach DONE state starting from reset state IDLE.
✗ Incorrect
After reset, FSM is in IDLE (done_flag = '0'). On first clock, moves to READ; second clock to WRITE; third clock to DONE. Output done_flag updates immediately with state, so it becomes '1' at the third clock cycle.
