Challenge - 5 Problems
VHDL Vending Machine Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Vending Machine FSM after inserting coins
Consider a VHDL vending machine FSM that accepts 5-cent and 10-cent coins to reach a total of 15 cents to dispense an item. What is the output signal
dispense after the input sequence: insert 10 cents, then 5 cents?VHDL
library ieee; use ieee.std_logic_1164.all; entity vending_machine is port( clk : in std_logic; reset : in std_logic; coin_5 : in std_logic; coin_10 : in std_logic; dispense : out std_logic ); end vending_machine; architecture fsm of vending_machine is type state_type is (S0, S5, S10, S15); signal state, next_state : state_type; begin process(clk, reset) is begin if reset = '1' then state <= S0; elsif rising_edge(clk) then state <= next_state; end if; end process; process(state, coin_5, coin_10) is begin dispense <= '0'; case state is when S0 => if coin_5 = '1' then next_state <= S5; elsif coin_10 = '1' then next_state <= S10; else next_state <= S0; end if; when S5 => if coin_5 = '1' then next_state <= S10; elsif coin_10 = '1' then next_state <= S15; else next_state <= S5; end if; when S10 => if coin_5 = '1' then next_state <= S15; elsif coin_10 = '1' then next_state <= S15; -- Overpay treated as 15 else next_state <= S10; end if; when S15 => dispense <= '1'; next_state <= S0; when others => next_state <= S0; end case; end process; end fsm;
Attempts:
2 left
💡 Hint
Think about the total value after inserting 10 cents then 5 cents.
✗ Incorrect
The FSM moves from S0 to S10 after the first 10-cent coin, then from S10 to S15 after the 5-cent coin. At S15, dispense is set to '1'.
🧠 Conceptual
intermediateNumber of states in the vending machine FSM
How many states are needed in a vending machine FSM that accepts 5-cent and 10-cent coins to dispense an item costing 15 cents?
Attempts:
2 left
💡 Hint
Count all possible sums of inserted coins up to 15 cents.
✗ Incorrect
States represent sums: 0, 5, 10, and 15 cents, so 4 states are needed.
🔧 Debug
advancedIdentify the error in this VHDL vending machine FSM snippet
What error will this VHDL code cause?
process(state, coin_5, coin_10) is
begin
dispense <= '0';
case state is
when S0 =>
if coin_5 = '1' then
next_state <= S5
elsif coin_10 = '1' then
next_state <= S10;
else
next_state <= S0;
end if;
when others =>
next_state <= S0;
end case;
end process;
Attempts:
2 left
💡 Hint
Check each statement for proper VHDL syntax.
✗ Incorrect
The line 'next_state <= S5' is missing a semicolon, causing a syntax error.
📝 Syntax
advancedCorrect way to reset FSM state in VHDL
Which code snippet correctly resets the FSM state to S0 on reset signal in VHDL?
Attempts:
2 left
💡 Hint
Reset should be checked inside the clock edge condition for synchronous reset.
✗ Incorrect
Option A shows a synchronous reset inside the rising edge clock check, which is correct.
🚀 Application
expertCalculate total dispense signals in a coin sequence
Given the vending machine FSM from the example, if the input coin sequence over 6 clock cycles is: 5c, 5c, 10c, 5c, 10c, 5c (one coin per cycle), how many times will the
dispense signal be '1'?Attempts:
2 left
💡 Hint
Track the state transitions and when the total reaches or exceeds 15 cents.
✗ Incorrect
The FSM dispenses when reaching 15 cents. The sequence causes dispense at cycles 3, 5, and 6.
