Skip to the selected question
ASIC.FYI

ASIC Question Bank

1,000+ hardware interview questions
DescriptionQ371
Page ↗
Q371DesignQualcommASIC interview problem

Implement a Stock-Aware 75-Cent Vending FSM

TechniquesDesignFSM
DifficultyMedium
TopicRTL Design
LanguageSystemVerilog
Requirements4 checkpoints
01

Problem

A machine sells one drink for 75 cents and accepts one 25-cent or 50-cent coin per accepted cycle. It stores at most 50 cents of credit because the next valid coin either vends or reaches that bound. A one-bit stock flag is cleared by a vend and set by restock. Implement the FSM with deterministic cancel, restock, invalid-coin, and simultaneous-input priority behavior.

Module declarationSystemVerilog
module vend75(input logic clk,rst_n,coin_valid,coin50,cancel,restock,
 output logic coin_ready,vend,change25,refund_valid,
 output logic [6:0] refund, output logic sold_out);
// coin50=0 means 25 cents; coin50=1 means 50 cents
// reset state: no credit and sold_out=1

Example input and output

Use this case to check your interpretation
Input
Case 1: After restock, accept 25 then 50
Case 2: After restock, accept 50 then 50
Case 3: After restock, accept 50 then assert cancel
Output
Case 1: vend pulses on the second coin, change25=0, credit returns to 0, and sold_out becomes 1
Case 2: vend=1 and change25=1 on the second coin; the extra 25 cents is returned
Case 3: refund_valid=1 with refund=50 for one cycle, no vend occurs, credit becomes 0, and stock remains
Explanation

The shown result follows by applying this rule: The state transitions implement the exact 0/25/50 credit set and the 75/100-cent vend cases. The cases also demonstrate this requirement: When sold out, coin inputs are not accepted. `vend`, `change25`, and `refund_valid` are one-cycle pulses, refund is zero whenever `refund_valid` is zero, and restock wins if restock, cancel, and coin_valid arrive together.

02

Requirements (4)

  • Use credit states 0, 25, and 50 cents plus one stocked bit. Active-low reset clears credit, marks sold out, and clears every pulse output.
  • Cycle priority after reset is restock, then cancel, then an accepted coin. Restock sets stocked and leaves credit unchanged; cancel emits one `refund_valid` pulse with refund equal to current credit, then clears credit.
  • `coin_ready` is one only when stocked, cancel and restock are low, and no vend/refund pulse from the prior cycle is being held. An accepted 25/50-cent coin adds credit; totals 75 or 100 vend, clear stock and credit, and pulse `change25` only for total 100.
  • When sold out, coin inputs are not accepted. `vend`, `change25`, and `refund_valid` are one-cycle pulses, refund is zero whenever `refund_valid` is zero, and restock wins if restock, cancel, and coin_valid arrive together.