
It’s a Moore FSM with spaced change/refund pulses and a small datapath for credit/selection.
States: st_select → st_vend → (st_mc_pulse ↔ st_mc_gap)* → st_select st_select → (st_refund_pulse ↔ st_refund_gap)* → st_select
Prices depend on the selected index (sel_idx): idx 0..3 → price 1, idx 4..7 → price 2, idx 8..12 → price 3 When a valid selection exists and credit ≥ price, the FSM vends: Credit is debited by price in st_vend. If credit remains, it enters the make-change sequence (spaced pulses). Otherwise, it returns to st_select.
Refund (btn="0010") returns all current credit as pulses with 1-cycle gaps. Make-change happens after a vend if debit left credit > 0; same pulse/gap pattern.
Timing/Reset reset is asynchronous, active-high: immediately sends the FSM to idle. State updates on the rising edge of clk. Inputs are sampled synchronously. The “one-cycle pulse” behavior comes from those terminal states automatically returning to idle on the next clock.
Input: 1 coin (coin 1-cycle pulse), select btn in 0011
<img src="case 1.png" width="1260" alt="Scenario 1">
Input : 2 coins ( 2 pulses each coin for 1-cycle pulse), select btn in 0111
<img src="case 2.png" width="1260" alt="Scenario 2">
Input : 2 coins ( 2 pulses each coin for 1-cycle pulse), select btn in 1011
<img src="case 3.png" width="1260" alt="Scenario 3">
Input : 3 coins ( 3 pulses, each coin for 1-cycle pulse), select btn in 0011 (price product = 1 coin)
<img src="case 4.png" width="1260" alt="Scenario 4">
Input : 3 coins ( 3 pulses, each coin for 1-cycle pulse), select btn in 0010 (to return change)
<img src="case 5.png" width="1260" alt="Scenario 5">
Input : 2 coins ( 2 pulses, each coin for 1-cycle pulse), select btn in 1111 (product price= 3 coins)
Then press btn = '0001' to cancel the transaction, and then press btn = 0100 (product price = 1)
<img src="case 6.png" width="1260" alt="Scenario 6">
Inputs:
Outputs:
Clock & reset: board oscillator + synchronous active-high reset generation.
| # | Input | Output | Bidirectional |
|---|---|---|---|
| 0 | clk | dispense | |
| 1 | reset | change | |
| 2 | coin | product_num(0) | |
| 3 | btn (0) | product_num(1) | |
| 4 | btn (1) | product_num(2) | |
| 5 | btn (2) | product_num(3) | |
| 6 | btn (3) | ||
| 7 |