BitFlow

Vending Machine FSM

advanced · state_machine · 330 XP

Sign in to write your solution, run it in the simulator and submit it for grading.

Sign in or create a free account →

Problem

Vending Machine FSM Implement a **vending machine** that accepts coins, dispenses items, and gives change. Price is fixed at **$0.50** (50 cents). Accepts nickels ($0.05), dimes ($0.10), quarters ($0.25). **States** - IDLE: Waiting for coins - ACCEPTING: Coins inserted, tracking balance - DISPENSE: Item dispensed - CHANGE: Returning excess coins **Interface** | Port | Direction | Width | Description | |----------------|-----------|-------|-------------------------------------| | `clk` | input | 1 | Clock | | `rst` | input | 1 | Sync reset (IDLE, balance=0) | | `nickel` | input | 1 | Nickel inserted (5 cents) | | `dime` | input | 1 | Dime inserted (10 cents) | | `quarter` | input | 1 | Quarter inserted (25 cents) | | `balance` | output | 8 | Current balance in cents | | `dispense` | output | 1 | Item dispensed (1-cycle pulse) | | `change_due` | output | 8 | Change to return (in cents) | **Logic:** 1. IDLE: balance=0, wait for coin 2. ACCEPTING: accumulate coins 3. When balance >= 50: - DISPENSE item (pulse output) - Calculate change = balance - 50 - CHANGE state: output change amount - Return to IDLE **Rules:** - One coin per cycle (nickel XOR dime XOR quarter) - balance saturates at 255 - change_due only valid during CHANGE state **Example:** Insert quarter + dime + quarter → balance=60 → dispense → change_due=10

Constraints

  • One-hot coin inputs: only one coin per cycle.
  • Price: fixed at 50 cents.
  • Accumulate balance across cycles.
  • Dispense when balance >= 50.
  • Calculate and output change.

Examples

Input: Quarter (25) + Quarter (50) + Dime (10)

Output: After 2 cycles: dispense=1, change_due=10 (balance=60, price=50)

Change returned

Input: Nickel + Nickel + Dime + Dime + Dime

Output: After 5 cycles: balance=50, dispense=1, change_due=0

Exact amount

Common questions

What does the Vending Machine FSM problem ask you to build?
Vending Machine FSM Implement a **vending machine** that accepts coins, dispenses items, and gives change. Price is fixed at **$0.50** (50 cents). Accepts nickels ($0.05), dimes ($0.10), quarters ($0.25).
What constraints does Vending Machine FSM have?
One-hot coin inputs: only one coin per cycle.; Price: fixed at 50 cents.; Accumulate balance across cycles.; Dispense when balance >= 50.; Calculate and output change.
What is an example input and output for Vending Machine FSM?
Input Quarter (25) + Quarter (50) + Dime (10) gives output After 2 cycles: dispense=1, change_due=10 (balance=60, price=50). Change returned
Which Verilog concepts does Vending Machine FSM practise?
state_machine, FSM, control, multi-condition, interview.