FINAL PP
FINAL PP
JNANASANGAMA,BELGAVI-590045
This project presents the design and implementation of a digital vending machine
using Xilinx FPGA tools. The system is modeled using finite state machine (FSM)
principles and implemented in Verilog Hardware Description Language (HDL).
The vending machine is designed to accept inputs such as product selection and
coin detection, process transactions based on defined logic, and dispense products
or return change accordingly. The design is synthesized and simulated using Xilinx
ISE/Vivado, allowing real-time testing and verification of system behavior. The
primary objective is to demonstrate a practical application of VLSI design
techniques by integrating combinational and sequential logic to control a vending
machine.
The system architecture supports multiple product options and coin denominations,
with logic implemented to handle valid and invalid input conditions. The FSM is
structured to ensure efficient state transitions and reliable output generation,
maintaining system robustness and ease of scalability. Simulation waveforms
validate the design functionality and timing accuracy. This project reflects the
practical relevance of digital logic design in embedded systems and consumer
electronics, illustrating how FPGA-based solutions offer enhanced performance,
flexibility, and reduced time-to-market for complex control-oriented applications
such as automated vending machines.
TABLE OF CONTENTS
INTRODUCTION ................................................................................ 1
DESIGN OVERVIEW… ..................................................................... 2
VERILOG CODE................................................................................ 3-6
SIMULATION AND TESTING… ..................................................... 7-9
EXPECTED RESULTS AND CHALLENGES… ............................. 10
APPLICATIONS ................................................................................... 11
CONCLUSION ...................................................................................... 12
INTRODUCTION
1
System Design Overview
The digital vending machine system is designed using an Xilinx FPGA and is
based on a finite state machine (FSM). The main components of the system are:
1. Coin Detection: The system accepts a variety of coins, with each coin
corresponding to a specific value. A mechanism detects the coin inserted
into the machine and updates the total amount.
2. Product Selection: The user selects a product by pressing a button
corresponding to a product. If sufficient funds are available, the product is
dispensed.
3. Change Dispensing: If the total inserted coins exceed the price of the
selected product, the system calculates the difference and returns the
appropriate amount of change.
4. FSM Logic: The system is governed by an FSM that dictates the transitions
based on inputs like coin values and product selection. The states of the
FSM ensure correct operation in dispensing products and handling change.
2
Hardware Description Language (Verilog) Implementation
Verilog Implementation
The FSM for the vending machine is implemented in Verilog HDL. Below is a
basic outline of the Verilog modules:
Module: FSM (Finite State Machine)
module VendingMachineFSM(
input clk,
input reset,
input [3:0] coin, // 4-bit input for coin value
input [3:0] product, // 4-bit input for product selection
output reg dispense, // Output to control product dispensing
output reg change // Output to control change dispensing
);
// Define the states
reg [2:0] state;
reg [2:0] next_state;
// State encoding
localparam IDLE = 3'b000, COIN_INSERT = 3'b001, PRODUCT_SELECT =
3'b010, DISPENSE_PRODUCT = 3'b011, DISPENSE_CHANGE = 3'b100;
// State transitions
always @(posedge clk or posedge reset) begin
if (reset)
state <= IDLE;
else
state <= next_state;
3
end
4
// Output logic
always @(state) begin
case(state)
IDLE: begin
dispense = 0;
change = 0;
end
COIN_INSERT: begin
dispense = 0;
change = 0;
end
PRODUCT_SELECT: begin
dispense = 0;
change = 0;
end
DISPENSE_PRODUCT: begin
dispense = 1;
change = 0;
end
DISPENSE_CHANGE: begin
dispense = 0;
change = 1;
end
default: begin
dispense = 0;
5
change = 0;
end
endcase
end
endmodule
This Verilog code describes the FSM, where the system transitions between
various states based on inputs like coin value and product selection
Module Declaration:
• The VendingMachineFSM module accepts inputs like clock (clk), reset,
coin (inserted coin value), and product (selected product).
• It outputs dispense (to trigger product dispensing) and change (to trigger
change dispensing).
State Encoding:
• The system has 5 states:
o IDLE: Waits for coin insertion.
o COIN_INSERT: Accepts coins and updates the balance.
o PRODUCT_SELECT: User selects a product.
o DISPENSE_PRODUCT: Dispenses the product.
o DISPENSE_CHANGE: Returns any excess change.
State Transition Logic:
• The FSM moves between states based on inputs (coin value, product
selection). For example:
o From IDLE to COIN_INSERT when a coin is inserted.
o From COIN_INSERT to PRODUCT_SELECT when a product is
selected.
6
o If enough money is inserted, the FSM moves from
PRODUCT_SELECT to DISPENSE_PRODUCT and then to
DISPENSE_CHANGE.
State Update:
• The FSM updates its current state based on clock cycles, with reset setting
it back to IDLE.
Output Logic:
• Depending on the state, the outputs are set:
o dispense is set to 1 in the DISPENSE_PRODUCT state to dispense
the product.
o change is set to 1 in the DISPENSE_CHANGE state to return
change.
TestBench Code:
module Testbench();
reg clk;
reg reset;
wire dispense;
wire change;
7
// Instantiate the VendingMachineFSM module
VendingMachineFSM uut (
.clk(clk),
.reset(reset),
.coin(coin),
.product(product),
.dispense(dispense),
.change(change)
);
// Clock generation
always begin
end
initial begin
// Initial conditions
clk = 0;
reset = 1;
coin = 4'b0000;
8
product = 4'b0000;
end
endmodule
• The testbench generates the clock signal (clk), applies the reset, and
supplies various input values (coin and product) to the
VendingMachineFSM module.
• It simulates a scenario where coins are inserted and a product is selected,
and after a certain amount of time, it stops the coin insertion and de-selects
the product.
9
• The outputs of the FSM (dispense, change) are observed to verify if the
system behaves as expected.
• The simulation runs for a specified amount of time and is then stopped
using $finish.
1. Initially, the FSM is in the IDLE state, waiting for coins to be inserted.
2. Upon coin insertion (coin = 4'b0100), the FSM moves to COIN_INSERT
and updates the total balance.
3. After the product is selected (product = 4'b0001), the FSM checks if the
balance is sufficient to dispense the product.
4. If the balance is enough, it transitions to the DISPENSE_PRODUCT
state, and then moves to the DISPENSE_CHANGE state to return any
excess money.
5. The simulation ends after the specified time.
Analysis of Results
10
Applications of Vending Machine Design Using FSM in Xilinx
The Vending Machine FSM is primarily used for controlling systems that
require step-by-step operations, such as coin insertion, product selection, and
change dispensing. This FSM design can be implemented on Xilinx FPGAs to
control digital systems in real-time. Tools like Vivado and ISE allow designers
to simulate, synthesize, and implement the FSM logic on FPGA boards such as
Spartan-6 or Artix-7.
FSM designs are used in coin-operated machines like toll booths or ticket
dispensers. These systems require payment verification before providing
services or products. Xilinx FPGAs are suitable for processing coin values
quickly and efficiently, ensuring that the system verifies payments in real time.
Xilinx FPGAs provide the flexibility to implement FSMs for various applications,
from simple vending machine designs to more complex IoT or payment systems.
Xilinx's Vivado or ISE design tools are used for simulation, synthesis, and
hardware implementation, making FPGA-based solutions ideal for controlling
embedded systems and real-time applications.
11
CONCLUSION
The development of a vending machine using a Finite State Machine (FSM) and
its implementation on Xilinx FPGA platforms demonstrates the practical
application of digital system design principles. FSMs provide a systematic way
to manage sequential operations such as coin insertion, product selection,
validation, and dispensing, making them ideal for automation tasks. By
leveraging Xilinx tools like Vivado or ISE, the Verilog-based design can be
simulated, synthesized, and deployed efficiently onto FPGA hardware for real-
time operation.
This project not only strengthens understanding of FSM-based design but also
showcases the versatility and power of FPGAs in handling complex logic with
high speed and reliability. The vending machine model serves as a scalable
solution that can be extended to support multiple products, digital payments, and
smart features for IoT integration. Overall, this implementation highlights the
relevance of HDL and FPGA-based prototyping in modern embedded systems
and real-world automation.
12