// FSM that represents a 15-cent gumball dispensing machine with a single coin // slot and no change given. // Inputs: // - N: whether or not a nickel (5c) was inserted // - D: whether or not a dime (10c) was inserted // - Q: whether or not a quarter (25c) was inserted // Outputs: // - Open: whether or not the machine dispenses a gumball module vend15 (input logic clk, reset, N, D, Q, output logic Open); // State Encodings and Variables enum logic [1:0] {Zero, Five=2'b10, Ten=2'b11} ps, ns; // Next State Logic (ns) always_comb case (ps) Zero: case ({N,D,Q}) 3'b000: ns = Zero; 3'b100: ns = Five; 3'b010: ns = Ten; 3'b001: ns = Zero; default: ns = ps; endcase Five: case ({N,D,Q}) 3'b000: ns = Five; 3'b100: ns = Ten; 3'b010: ns = Zero; 3'b001: ns = Zero; default: ns = ps; endcase Ten: case ({N,D,Q}) 3'b000: ns = Ten; 3'b100: ns = Zero; 3'b010: ns = Zero; 3'b001: ns = Zero; default: ns = ps; endcase endcase // Output Logic assign Open = Q | ((ps != Zero) & D) | ((ps == Ten) & N); // State Update Logic (ps) always_ff @(posedge clk) if (reset) ps <= Zero; else ps <= ns; endmodule // vend15