0% found this document useful (0 votes)
43 views54 pages

VendingMachine Notes

This project report details the design of a vending machine using a Finite State Machine (FSM) in Verilog HDL, submitted by Bhaskar Sharma, Pankaj Kumar Sharma, and Vishal for their Bachelor of Technology degree in Electronics and Communication Engineering. The report includes an introduction to vending machines, their history, design methodology, implementation methods, and simulation results. The project aims to enhance vending machine functionality with features like auto-billing and product selection flexibility.

Uploaded by

rohanjoshirj2001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views54 pages

VendingMachine Notes

This project report details the design of a vending machine using a Finite State Machine (FSM) in Verilog HDL, submitted by Bhaskar Sharma, Pankaj Kumar Sharma, and Vishal for their Bachelor of Technology degree in Electronics and Communication Engineering. The report includes an introduction to vending machines, their history, design methodology, implementation methods, and simulation results. The project aims to enhance vending machine functionality with features like auto-billing and product selection flexibility.

Uploaded by

rohanjoshirj2001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 54

A

project report on
DESIGN A VENDING MACHINE TO FETCH ONE OF THE
MANY PRODUCTS BY USING MULTIPLE STATES FSM IN
VERILOG HDL
submitted in partial fulfilment of
the requirements for the award of the degree of
BACHELOR OF TECHNOLOGY
in
ELECTRONICS AND COMMUNICATION ENGINEERING

by
Bhaskar Sharma Pankaj Kumar Sharma Vishal
(212099020122) (212099020199) (212099020285)

Under the Supervision of


Dr. S. K. Tomar
HOD ECE Department
Faculty of Engineering and Technology
M. J. P. Rohilkhand University, Bareilly

1
UNDERTAKING

We hereby declare that We, Pankaj Kumar Sharma (212099020199), Bhaskar Sharma
(212099020122) and Vishal (212099020285) have completed the project work on the title
“DESIGN A VENDING MACHINE TO FETCH ONE OF THE MANY PRODUCTS BY
USING MULTIPLE STATES FSM IN VERILOG HDL” under the supervision of Dr. S. K.
Tomar, HOD Department of Electronics and Communication Engineering, M. J. P. Rohilkhand
University, Bareilly, Uttar Pradesh for the award of the degree of Bachelor of Technology during
the academic year 2023-24.
This is our own work and we have not submitted it anywhere.

Date: 24/05/2024
Place: Bareilly

Bhaskar Sharma Pankaj Kumar Sharma Vishal


(212099020122) (212099020199) (212099020285)

2
CERTIFICATE

This is to certify that project work embodied in this report entitled “DESIGN A VENDING
MACHINE TO FETCH ONE OF THE MANY PRODUCTS BY USING MULTIPLE STATES
FSM IN VERILOG HDL” submitted to M. J. P. Rohilkhand University Bareilly Uttar Pradesh,
for the award of the degree of Bachelor of Technology in Electronics and communication
Engineering has been carried out by Pankaj Kumar Sharma, Bhaskar Sharma and Vishal under
my supervision during the academic year 2023-24.

Dr. S. K. Tomar Dr. Janak Kapoor


(HOD ECE Department) (Project In-charge)
(Project Guide)

3
ACKNOWLEDGEMENT

We take this opportunity to express our profound sense of gratitude and respect to all those who
helped us through the duration of this project work. First of all, we thank the almighty, who gave
us the opportunity and strength to carry out this project. Our greatest thanks are to all those
people whose contributions in various ways helped.
We would like to express our gratitude to Dr. S. K. Tomar (Project Guide) for guidance and
support throughout this project work. He has been a constant source of inspiration to us
throughout the period of this project. We consider ourselves extremely fortunate for having the
opportunity to learn and work under his supervision over this entire period. We are proud to do
this project under such an experienced teacher and a great human being like him. We would also
take this opportunity to express our sincere thanks to Dr. S. K. Tomar for their valuable and kind
support.
Finally, we would like to thank the entire faculty members and lab staff of the Department of
Electronics and Communication Engineering, Institute of Engineering and Technology, M. J. P.
Rohilkhand University Bareilly, Uttar Pradesh.
Our greatest thanks are to our parents who bestowed ability and strength in us to complete this
project.

Bhaskar Sharma Pankaj Kumar Sharma Vishal


(212099020122) (212099020199) (212099020285)

4
CONTENTS

CHAPTER PAGE No.

1. INTRODUCTION 6
2. VENDING MACHINE AND ITS HISTORY 7
3. DESIGN METHODOLOGY 9
4. IMPLEMENTATION METHODS 12
5. VERILOG CODE 17
6. SIMULATION AND RESULTS 30
7. HARDWARE IMPLEMENTATION 34
8. ADVANTAGES AND DISADVANTAGES 51
9. CONCLUSION 53
10. REFRENCES 54

5
CHAPTER 1
INTRODUCTION
Vending Machines are used to dispense various products like Coffee, Snacks, and Cold Drink
etc. when money is inserted into it. Vending Machines have been in existence since 1880s. The
first commercial coin operated machine was introduced in London and England used for selling
post cards. The vending machines are more accessible and practical than the convention
purchasing method. Nowadays, these can be found everywhere like at railway stations selling
train tickets, in schools and offices vending drinks and snacks, in banks as ATM machine and
provides even diamonds and platinum jewelers to customers.

Previous CMOS and SED based machines are more time consuming than the FPGA based
machines. The FPGA based machine is also more flexible, programmable and can be re-
programmed. But in microcontroller-based machine, if one wants to enhance the design, he has
to change the whole architecture again but in FPGA user can easily increase the number of
products. In this paper a new approach is proposed to design a Vending Machine with auto-
billing features. The machine also supports a cancel feature means that the person can withdraw
the request and the money will be returned back to the user. This machine can be used at various
places like Hotels, Restaurants and food streets. This reduces the time and cost.

6
CHAPTER 2
VENDING MACHINE AND IT’S HISTORY
A vending machine is a machine which dispenses items such as snacks, beverages, alcohol,
cigarettes, lottery tickets, cologne, consumer products and even gold and gems to customers
automatically, after the customer inserts currency or credit into the machine.

History

The earliest known reference to a vending machine is in the work of Hero of Alexandria, a first-
century engineer and mathematician. His machine accepted a coin and then dispensed holy
water. When the coin was deposited, it fell upon a pan attached to a lever. The lever opened a
valve which let some water flow out. The pan continued to tilt with the weight of the coin until it
fell off, at which point a counterweight snapped the lever up and turned off the valve.

Modern vending machines

The first modern coin-operated vending machines were introduced in London, England in the
early 1880s, dispensing post cards. The machine was invented by Percival Everitt in 1883 and
soon became a widespread feature at railway stations and post offices, dispensing envelopes,
postcards and notepaper. The Sweetmeat Automatic Delivery Company was founded in 1887 in
England as the first company to deal primarily with the installation and maintenance of vending
machines.

The first vending machine in the U.S. was built in 1888 by the Thomas Adams Gum Company,
selling gum on New York City train platforms. The idea of adding games to these machines as a
further incentive to buy came in 1897 when the Pulver Manufacturing Company added small
figures, which would move around whenever somebody bought some gum from their machines.
This idea spawned a whole new type of mechanical device known as the "trade stimulators". The
birth of slot machines and pinball is ultimately rooted in these early devices.

In December 1970, Ussery Industries of Dallas, Texas at its Dallas convention displayed its
"talking" vending machine, the Venda Talker. With insertion of a coin, the machine said "thank
you" and added a one-liner voiced by comic Henny Youngman.

In the Western world, some vending machines dispense personal products, typically in public
toilet facilities. These are often found at toilets used by transient persons in high traffic locations,
such as bus stations, shopping centers, airports and service stations.

From the 1950s until well into the 1970s, vending machines were used at American airports to
sell life insurance policies covering death, in the event that the buyer's flight crashed. Such
policies were quite profitable, because the risk of a plane crash is low. However, this practice
gradually disappeared due to the tendency of American courts to strictly construe such policies
against their sellers, such as Mutual of Omaha.

7
Starting with 1994, vending machines approached successfully the basic food commerce
specialization and began to compete with the Fast-Moving Consumer Goods industry. Milk
dispensers and egg vending machines networks spreading in European towns accelerated after
2000. The basic food vending machines are usually owned by farmers selling their production
directly to consumers, providing fresh food to urban population at low prices, small operational
costs and encouraging the distributism.

Another type of vending machine is a Chargebox which is used for charging small mobile
devices such as mobile phones and iPods. They are useful for when one runs out of power on
such devices in between locations like home and work.

From 2000-2010, specialization of vending machines became more common. Vending extended
increasingly into non-traditional areas like electronics, or even artwork. Machines of this new
category are generally called Automated Retail kiosks. The trend of specialization and
proliferation of vending machines is perhaps most apparent in Japan where vending machines
sell products from toilet paper to hot meals, and there is 1 vending machine per 23 people.

Liskom (Russia) and Xerox (Global) both have coin-operated or pay-per-copy vending
machines.

A full-line vending company may set up several types of vending machines that sell a wide range
of products. Products may include candy, cookies, chips, fresh fruit, milk, cold food, coffee and
other hot drinks, bottles, cans of soda, and even frozen products like ice cream. machines,

These products can be sold from machines that include coffee, snack, cold food, 20-oz. bottle
and glass-front bottle machines.

8
CHAPTER 3
DESIGN METHODOLOGY OF VENDING MACHINE

FINITE STATE MACHINE METHOD:


A finite-state machine (FSM) or finite-state automaton (plural: automata), or simply a state
machine, is a mathematical model of computation used to design both computer programs and
sequential logic circuits. It is conceived as an abstract machine that can be in one of a finite
number of states. The machine is in only one state at a time; the state it is in at any given time is
called the current state. It can change from one state to another when initiated by a triggering
event or condition; this is called a transition. A particular FSM is defined by a list of its states,
and the triggering condition for each transition.

The behavior of state machines can be observed in many devices in modern society which
perform a predetermined sequence of actions depending on a sequence of events with which they
are presented. Simple examples are vending machines which dispense products when. the proper
combination of coins is deposited, elevators which drop riders off at upper floors before going
down, traffic lights which change sequence when cars are waiting, and combination locks which
require the input of combination numbers in the proper order.

Finite-state machines can model a large number of problems, among which are electronic design
automation, communication protocol design, language parsing and other engineering
applications. In biology and artificial intelligence research, state machines or hierarchies of state
machines have been used to describe neurological systems and in linguistics to describe the
grammars of natural languages.

Considered as an abstract model of computation, the finite state machine is weak; it has less
computational power than some other models of computation such as the Turing machine. That
is, there are tasks which no FSM can do, but some Turing machines can. This is because the
FSM has limited memory. The memory is limited by the number of states.

FSMs are studied in the more general field of automata theory.

The automata theory is the basis behind the traditional model of computation and is used for
many purposes other than controller circuit design, including computer program compiler
construction, proofs of algorithm complexity, and the specification and classification of
computer programming languages. Because automata are mathematical models that produce
values dependent upon internal state and possibly some dependent input values, they are referred
to as state machines. A state machine may allow for a finite or an infinite set of possible states
and furthermore, they may have nondeterministic or deterministic behavior. A deterministic state
machine is one whose outputs are the same for a given internal state and input values. A finite
state machine (FSM) is one where all possible state values made a finite set.

In a Finite State Machine the circuit's output is defined in a different set of states i.e. each output
is a state. A State Register to hold the state of the machine and a next state logic to decode the

9
next state. An output register defines the output of the machine. In FSM based machines the
hardware gets reduced as in this the whole algorithm can be explained in one process.

Two types of State machines are:

Mealy Machine: A Mealy machine is a type of finite state machine (FSM) where the output
depends on both the current state and the input. In contrast, a Moore machine's output depends
only on the current state.

A Mealy state diagram consists of states, transitions, inputs, and outputs. Here's a basic
description of the components:

1. States (circles): Represent the different conditions or modes that the system can be in.

2. Transitions (arrows): Show how the system moves from one state to another based on input
conditions. Each arrow typically indicates a transition triggered by a specific input.

3. Inputs (labels on arrows): Indicate the conditions or inputs that trigger the transitions
between states.

4. Outputs (labels on states or transitions): Represent the outputs produced by the system when
in a particular state or during a specific transition. In a Mealy machine, the output is
associated with transitions.

Moore Machine: A Moore state diagram represents a type of finite state machine (FSM) where
the outputs are associated with the states themselves, not the transitions between states. Here's a
basic explanation and an example of a Moore state diagram:

10
Components of a Moore State Diagram:

1. States (circles): Represent different conditions or modes that the system can be in.

2. Transitions (arrows): Show how the system moves from one state to another based on input
conditions. Each arrow typically indicates a transition triggered by a specific input.

3. Inputs (labels on arrows): Indicate the conditions or inputs that trigger transitions between
states.

4. Outputs (labels on states): Represent the outputs produced by the system when in a particular
state. In a Moore machine, the output is associated with states.

11
CHAPTER 4
IMPLEMENTATION METHOD

MINOR PROJECT:
• The vending machine designed in the minor project dispense three different following
products and their price are as written below.

• The variables used in the code are as shown below:

• The variable ‘clk’ is the clock input signal which controls the working of the vending
machine. It is a square wave of time period 10 seconds.

• The “rst” variable is the input signal which is used to reset the vending machine.

12
• The “coin” variable represents insertion of coin.

• The “product_select” variable represents the product selected by the user and has following
conditions:
1. (product_select =00) =>None selected
2. (product_select=01) =>Candy
3. (product_select=10) =>Coffee
4. (product_select=11) =>Snacks

MAJOR PROJECT:
• In the major project we have modified the previous vending machine by adding more
products in the vending machine and we have also increased the number of coins accepted by
the vending machine. some important details of the modified vending machine are shown
below:

• We can see in the above table that there are now five products, the user can select any one of
the following products and after inserting sufficient money the selected product will be
dispensed.

13
• In the above table the input and output variables along with their size are specified. We can
see that now size of the product_select variable and the coin variable is three bits which was
initially two bits and one bit respectively.

• The variable ‘clk’ is the clock input signal which controls the working of the vending
machine. It is a square wave of time period

• The “rst” variable is the input signal which is used to reset the vending machine.

• The “coin” variable represents the coin inserted by the user. It has following conditions :
(coin=000) => No coin inserted
(coin=001) => Rs. coin inserted
(coin=010) => Rs. 5 coin inserted
(coin=011) => Rs. 10 coin inserted
(coin=100) => Rs. 20 coin inserted

• The product_select variable represents the product selected by the user and has following
conditions:
(product_select =000) => None selected
(product_select=001) => Candy
(product_select=010) => Coffee
(product_select=011) => Tea
(product_select=011) => Snacks
(product_select=011) => Snacks
The state diagram of the vending machine is shown below:

14
• Initially the machine is in idle state.

• When the user insert a coin the machine goes to wait state.

• As long as the user keep inserting the coin the machine will remain in the wait state and it
will keep incrementing the value of current _amount variable by 1.

• When the user select the desired product, the machine goes to dispense state.

• If the product is available and the “current_balance” is greater than the price of the selected
product then the machine dispenses the selected product otherwise it will return the money
back to the user.

• The flow chart for the vending Machine is shown below:

1. First we select the product which we want to buy.


2. For coffee, Product_select=01;

15
3. For coffee, Product_select=10;
4. For coffee, Product_select=11;
5. Now the machine checks the availability of the selected product. If the product is available
then the machine accepts the money from the user otherwise it returns to the idle state.
6. If product is available then the machine accepts money from the user.
7. When the inserted money is equal to the price of the selected product the machine
8. Dispenses the product and returns the change to the user.
9. After the product is dispensed the machine goes back to idle state.

16
CHAPTER 5
VERILOG CODE

MINOR PROJECT:
The objective here is to design Vending Machine Controller which accepts money (Rs. 1 coins)
in any sequence and delivers the products when the required amount has been deposited and
gives back the change. we have used verilog language to design the machine and the is written
using behavioural modelling.

SPECIFICATIONS:
1. Price of the products are Rs. 5, 7 and 10.

2. Possible money input is coin of Rs.1 which is indicated by variable coin.

3. Product to be delivered when Rs.5,7 or Rs.10 is reached.

4. A variable “product_select” is used to select the desired product.

VERILOG CODE:
// Code your design here
module VendingMachine(
input clk,
input rst,
input coin,
input [1:0] product_select,
output reg dispense_product,
output reg [6:0] change
);
// Define product prices
parameter PRICE_PRODUCT1 = 5; // Price of product 1
parameter PRICE_PRODUCT2 = 7; // Price of product 2
parameter PRICE_PRODUCT3 = 10; // Price of product 3

// Define states
reg [3:0] state;
parameter IDLE_STATE = 4'b0000;
parameter WAIT_STATE = 4'b0001;
parameter DISPENSE_STATE = 4'b0010;
// Define product availability flags
reg [2:0] product_available;
parameter PRODUCT1_AVAILABLE = 3'b001;
parameter PRODUCT2_AVAILABLE = 3'b010;

17
parameter PRODUCT3_AVAILABLE = 3'b100;

// Define product dispensing flags


reg [2:0] dispense_flag;
reg dispense_complete;

// Define variables for tracking coins


reg [6:0] current_balance;

always @(posedge clk or posedge rst) begin


if (rst) begin
// Reset the vending machine
state <= IDLE_STATE;
product_available <= {3{1'b1}};
dispense_flag <= 3'b000;
dispense_product <= 0;
dispense_complete <= 0;
change <= 0;
current_balance <= 0;
end else begin
// Vending machine logic
case (state)

IDLE_STATE: begin
// Idle state - waiting for coin and product selection
dispense_product <= 0;
change <= 0;
if (coin) begin
current_balance <= current_balance + 1;
state <= WAIT_STATE;
end
end

WAIT_STATE: begin
// Wait state - waiting for product selection
dispense_product <= 0;
change <= 0;
if(product_select==2'b01 && product_available[0])
begin
state <= DISPENSE_STATE;
dispense_flag[0] <= 1;
end else if (product_select == 2'b10 && product_available[1])
begin

18
state <= DISPENSE_STATE;
dispense_flag[1] <= 1;
end else if (product_select == 2'b11 && product_available[2)
begin
state <= DISPENSE_STATE;
dispense_flag[2] <= 1;
end
else if (coin) begin
current_balance <= current_balance + 1;
end
end

DISPENSE_STATE: begin
// Dispense state - dispensing the selected product
if (dispense_flag[0]) begin
if (current_balance >= PRICE_PRODUCT1) begin
dispense_product <= 1;
change <= current_balance-PRICE_PRODUCT1;
current_balance <= current_balance - PRICE_PRODUCT1;
product_available[0] <= 0;
dispense_complete <= 1;
end
else begin
change<=current_balance;
end
end
else if (dispense_flag[1])
begin
if (current_balance >= PRICE_PRODUCT2) begin
dispense_product <= 1;
current_balance <= current_balance - PRICE_PRODUCT2;
change <= current_balance;
product_available[1] <= 0;
dispense_complete <= 1;
end
else begin
change<=current_balance;
end
end

else if (dispense_flag[2])
begin
if (current_balance >= PRICE_PRODUCT3)

19
begin
dispense_product <= 1;
current_balance <= current_balance - PRICE_PRODUCT3;
product_available[2] <= 0;
change <= current_balance;
dispense_complete <= 1;
end
else begin
change<=current_balance;
end
end
state <= IDLE_STATE;
end
endcase
end
end
endmodule

TEST BENCH:

module tb_VendingMachine;
reg clk;
reg rst;
reg coin;
reg [1:0] product_select;
wire dispense_product;
wire [6:0] change;

// Clock generation
always #5 clk = ~clk;
// Instantiate the VendingMachine module
VendingMachine vending_machine (
.clk(clk),
.rst(rst),
.coin(coin),
.product_select(product_select),
.dispense_product(dispense_product),
.change(change)
);

// Dump file configuration


initial begin
$dumpfile("vending_machine_waveform.vcd");

20
$dumpvars(0, tb_VendingMachine);
end

// Initial values
initial begin
clk = 0;
rst = 1;
coin = 0;
product_select = 2'b00;

// Reset
#10 rst = 0;

// Test case 1: Insert enough coins for Product 1


// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 1;
// #10 coin =0;
// #10 product_select = 2'b01; // Select Product 1
// #100; // Wait for dispensing

// Test case 2: Insert insufficient coins for Product 2


#10 coin = 1;
#10 coin = 1;
#10 coin = 0;
#10 product_select = 2'b01; // Select Product 2
#100; // Wait for dispensing

// Test case 3: Insert enough coins for Product 2


// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 1;
// #10 product_select = 2'b01; // Select Product 2
// #100; // Wait for dispensing

// // Test case 4: Insert enough coins for Product 3

21
// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 1;
// #10 product_select = 2'b10; // Select Product 3
// #100; // Wait for dispensing

// // Test case 5: Insert insufficient coins for Product 3


// #10 coin = 1;
// #10 product_select = 2'b10; // Select Product 3
// #100; // Wait for dispensing

// End simulation
#10 $finish;
end
endmodule

22
MAJOR PROJECT:

The objective here is to design Vending Machine which accepts money (Rs. 1, 5, 10, 20 coins) in
any sequence and delivers the products when the required amount has been deposited and gives
back the change.

SPECIFICATIONS:

1. Price of the products are Rs. 5, 7 and 10.

2. Possible money input is coin of Rs.1 which is indicated by variable coin.

3. Product to be delivered when Rs.5,7 or Rs.10 is reached.

4. A variable “product_select” is used to select the desired product.

VERILOG CODE :

// Code your design here


// Code your design here
module VendingMachine(
input clk,
input rst,
input [2:0]coin,
// input [1:0] product_select,
input [2:0] product_select,
output reg dispense_product,
output reg [6:0] change
);
// Define product prices
parameter PRICE_PRODUCT1 = 5; // Price of product 1
parameter PRICE_PRODUCT2 = 7; // Price of product 2
parameter PRICE_PRODUCT3 = 10; // Price of product 3
parameter PRICE_PRODUCT4 = 15; // Price of product 3
parameter PRICE_PRODUCT5 = 20; // Price of product 3
// Define states
reg [3:0] state;
parameter IDLE_STATE = 4'b0000;
parameter WAIT_STATE = 4'b0001;
parameter DISPENSE_STATE = 4'b0010;

// Define product availability flags


reg [4:0] product_available;
parameter PRODUCT1_AVAILABLE = 5'b00001;
parameter PRODUCT2_AVAILABLE = 5'b00010;
parameter PRODUCT3_AVAILABLE = 5'b00100;
parameter PRODUCT4_AVAILABLE = 5'b01000;
parameter PRODUCT5_AVAILABLE = 5'b10000;

// Define product dispensing flags

23
reg [4:0] dispense_flag;
reg dispense_complete;
// Define variables for tracking coins
reg [6:0] current_balance;

always @(posedge clk or posedge rst) begin


if (rst) begin
// Reset the vending machine
state <= IDLE_STATE;
product_available <= {5{1'b1}};
dispense_flag <= 5'b00000;
dispense_product <= 0;
dispense_complete <= 0;
change <= 0;
current_balance <= 0;
end else begin
// Vending machine logic

case (state)

IDLE_STATE: begin
// Idle state - waiting for coin and product selection
dispense_product <= 0;
current_balance=0;
change <= 0;
if (coin!=3'b000)
begin
if(coin==3'b001)
begin
current_balance <= current_balance + 1;
end
else if(coin==3'b010)
begin
current_balance <= current_balance + 5;
end
else if(coin==3'b011)
begin
current_balance <= current_balance + 10;
end
else if(coin==3'b100)
begin
current_balance <=current_balance + 20;
end
state <= WAIT_STATE;
end
end

WAIT_STATE: begin
// Wait state - waiting for product selection
dispense_product <= 0;

24
change <= 0;
if (product_select == 3'b001 && product_available[0] )
begin
state <= DISPENSE_STATE;
dispense_flag[0] <= 1;
end
else if (product_select == 3'b010 && product_available[1]) begin
state <= DISPENSE_STATE;
dispense_flag[1] <= 1;
end
else if (product_select == 3'b011 && product_available[2] ) begin
state <= DISPENSE_STATE;
dispense_flag[2] <= 1;
end
else if (product_select == 3'b100 && product_available[3]) begin
state <= DISPENSE_STATE;
dispense_flag[3] <= 1;
end

else if (product_select == 3'b101 && product_available[4] ) begin


state <= DISPENSE_STATE;
dispense_flag[4] <= 1;
end
else if (coin!=3'b000)
begin
if(coin==3'b001)
begin
current_balance <= current_balance + 1;
end
else if(coin==3'b010)
begin
current_balance <= current_balance + 5;
end
else if(coin==3'b011)
begin
current_balance <= current_balance + 10;
end
else if(coin==3'b100)
begin
current_balance <= current_balance + 20;
end
end
end

DISPENSE_STATE: begin
// Dispense state - dispensing the selected product

if (dispense_flag[0]) begin
if (current_balance >= PRICE_PRODUCT1) begin

25
dispense_product <= 1;
change <= current_balance-PRICE_PRODUCT1;
current_balance <= current_balance - PRICE_PRODUCT1;
product_available[0] <= 0;
dispense_complete <= 1;
end
else begin
change<=current_balance;
end
end
else if (dispense_flag[1]) begin
if (current_balance >= PRICE_PRODUCT2) begin
dispense_product <= 1;
change <= current_balance-PRICE_PRODUCT2;
current_balance <= current_balance - PRICE_PRODUCT2;
product_available[1] <= 0;
dispense_complete <= 1;
end
else begin
change<=current_balance;
end
end
else if (dispense_flag[2]) begin
if (current_balance >= PRICE_PRODUCT3) begin
dispense_product <= 1;
change <= current_balance- PRICE_PRODUCT3;
current_balance <= current_balance - PRICE_PRODUCT3;
product_available[2] <= 0;
dispense_complete <= 1;
end
else begin
change<=current_balance;
end
end
else if (dispense_flag[3]) begin
if (current_balance >= PRICE_PRODUCT4) begin
dispense_product <= 1;
change <= current_balance- PRICE_PRODUCT4;
current_balance <= current_balance - PRICE_PRODUCT4;
product_available[3] <= 0;
dispense_complete <= 1;
end
else begin
change<=current_balance;
end
end
else if (dispense_flag[4]) begin
if (current_balance >= PRICE_PRODUCT5) begin
dispense_product <= 1;
change <= current_balance- PRICE_PRODUCT5;

26
current_balance <= current_balance - PRICE_PRODUCT5;
product_available[4] <= 0;
dispense_complete <= 1;
end
else begin
change<=current_balance;
end
end
state <= IDLE_STATE;
end
endcase
end
end
endmodule

TEST BENCH :

// Code your testbench here


// or browse Examples
module tb_VendingMachine;

reg clk;
reg rst;
reg [2:0]coin;
reg [2:0] product_select;
wire dispense_product;
wire [6:0] change;

// Clock generation
always #5 clk = ~clk;

// Instantiate the VendingMachine module


VendingMachine vending_machine (
.clk(clk),
.rst(rst),
.coin(coin),
.product_select(product_select),
.dispense_product(dispense_product),
.change(change)
);

// Dump file configuration


initial begin
$dumpfile("vending_machine_waveform.vcd");
$dumpvars(0, tb_VendingMachine);
end

// Initial values
initial begin

27
clk = 0;
rst = 1;
coin = 3'b000;
product_select = 3'b000;

// Reset
#10 rst = 0;

// Test case 1: Insert enough coins for Product 4


#10 coin = 3'b001;
#10 coin = 3'b001;
#10 coin = 3'b001;
#10 coin = 3'b010;
#10 coin = 3'b010;
#10 coin = 3'b010;
#10 coin = 3'b000;
#10 product_select = 3'b100; // Select Product 4
#100; // Wait for dispensing

// // Test case 2: Insert insufficient coins for Product 2


// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 0;
// #10 product_select = 2'b01; // Select Product 2
// #100; // Wait for dispensing

// Test case 3: Insert enough coins for Product 2


// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 0;
// #10 product_select = 2'b10; // Select Product 2
// #100; // Wait for dispensing

// // Test case 4: Insert enough coins for Product 3


// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 0;

28
// #10 product_select = 2'b11; // Select Product 3
// #100; // Wait for dispensing

// // Test case 5: Insert insufficient coins for Product 3


// #10 coin = 1;
// #10 coin = 1;
// #10 coin = 0;
// #10 product_select = 2'b11; // Select Product 3
// #100; // Wait for dispensing

// End simulation
#10 $finish;
end

endmodule

29
CHAPTER 6
SIMULATION AND RESULTS

MINOR PROJECT:
The verilog code is simulated on EDA playground software and compiled in ICARUS verilog
0.9.7 tool. The results obtained are shown below. Price of the products is Rs. 5,7 and 10 and
accepted coin is 1 rupee. following are some important points required to understand the results:

• The “current_balance” signal represents the amount of money inserted by the user in
hexa decimal.

• The “change” signal represents the amount of money to be returned to the user.

• “clk” is the input clock signal applied to the vending machine.

• The “coin” signal represents the insertion of coin. When the coin is inserted, it becomes
high.

• The “dispense_product” is the output signal which represents that the product is
dispensed.

• The “product_select” signal is of two bits and it represents the product selected by the
user.

• “rst” is the control signal used to reset the vending machine.

Test Case 1: When we insert enough money for product 1: In the following waveforms it can be
seen that product 1 (candy) is dispensed and Rs. 1 is returned successfully.

The time scale is in seconds and values are in Hexa Decimal. We can see that the user has
inserted six rupees in the vending machine and selected the first product which is candy. this
amount is sufficient to buy the selected product (candy) which worth five rupees thus the

30
dispense_product waveform has become high and “change” =1 which indicates that the product
is successfully dispensed and change Rs.1 is returned to the user.

Test Case:2 When we insert insufficient money for product 2: In the following waveforms we
can see the product is not dispensed and inserted money is returned successfully

The unit of time is seconds and values are in Hexa Decimal format. We can see that the user has
inserted only six rupees and selected the second product which is coffee. Since the inserted
amount is not sufficient thus dispense_product waveform remains low and change=6 which
indicates that no product is dispensed and change Rs. 6 is returned to the user.

31
MAJOR PROJECT :
The verilog code is simulated on EDA playground software and simulated with ICARUS
VERILOG 0.9.7. the result obtained are shown below. The price of the product is Rs. 5, 7, 10, 15
and 20 and the accepted coins are one , five ,ten and twenty .

• The “current_balance” signal represents the amount of money inserted by the user.

• The “change” signal represents the amount of money to be returned to the user.

• “clk” is the input clock signal applied to the vending machine.

• The “coin” signal here is of two bits and it represents the coin inserted by the user. When
the coin is inserted it becomes 01, 10 or 11 depending upon the coin.

• The “dispense_product” is the output signal which represents that the product is
dispensed.

• The “product_select” signal is of three bits and it represents the selected product. Here
we have five products

• “rst” is the control signal used to reset the vending machine.

Test case 1: when we insert money for product 4: the product is successfully dispensed and change
is returned to the user.

The time scale is in seconds and values are in Hexa Decimal format. We can see in the
“current_balance” that the user has inserted amount 12 (in hexa decimal) which means eighteen
rupees in decimal and selected the fourth product which is snacks. Since this amount is sufficient
thus the dispense_product waveform has become high and change =3 which indicates that the
product is successfully dispensed and change Rs.3 is returned to the user successfully.

32
Test case 2: When we insert insufficient coins for product 4(snacks) the money is returned to the
user and the product is not delivered.

The time scale is in seconds and values are in Hexa Decimal format.

We can see in the “current_balance” signal that the user has inserted eight rupees and selected
the fourth product which is snacks. Since this amount is insufficient thus the dispense_product
waveform remains low and change=8 which indicates that no product is dispensed and change
Rs. 8 is returned to the user.

33
CHAPTER 7
HARDWARE IMPLEMENTATION :
In the major project we have also made the circuit for the three products vending machine which
accepts one rupee coins. Implementing the hardware for a vending machine involves a
multidisciplinary approach that combines mechanical engineering, electrical engineering, and
software engineering. The key components include the structure, dispensing mechanism,
payment system, user interface, control system, and connectivity features. Below is a detailed
overview of each component:

1. Structure and Design

Frame: The frame is typically made of metal or reinforced plastic, providing durability and
security.

Storage: Shelves or racks are designed to hold various products. The design needs to
accommodate different sizes and shapes of products.

Door and Window: The front door often includes a transparent window for product visibility. It
should be strong enough to prevent theft and tampering.

2. Dispensing Mechanism

Motorized Dispensers: Stepper motors or servo motors are used to drive the dispensing
mechanisms. Common types include spiral, conveyor belt, or robotic arms.

Sensors: Optical or weight sensors ensure the product is correctly dispensed. These sensors can
detect jams or out-of-stock conditions.

Actuators: Solenoids and actuators control the movement of shelves, doors, or other mechanical
parts involved in dispensing.

We have determined the Boolean expression for the inputs of the sequential circuits responsible
for dispensing the products

3. State Diagram

The state diagram A state diagram is a graphical representation of a sequential circuit, illustrating
the states it can occupy and the transitions between these states based on inputs. Here we have
made the state diagram for the vending machine that dispenses three products. It operates in ten
states. It’s state diagram is shown below:

34
4. Truth Table

We can see in the above truth table below that the present state of the vending machine is
represented by four Variable A,B,C and D. The insertion of coin is represented by variable E and
the variable F and G represents the selected product. The machine operates in 10 states thus we
require four flip flops to make the sequential circuits. The output variables are Y1Y0 which
represents the dispensed product. TA, TB, Tc and TD are the inputs of the T flip flops used in the
sequential circuits.

35
From the above truth table we can find the Boolean expression of the Output Y1 ,Y0 and of the
input of the flip flops TA ,TB ,Tc and TD as shown below.

36
37
The Boolean function obtained in the previous step can be minimized using tabulation method as
shown below:

38
39
40
41
Prime Implicant table for minimized Boolean expression for TD:

42
5. Circuit Diagram:
Now since we have the minimized boolean expression for all output and state variables, we can
draw the circuit diagram of the vending machine. since the diagram is very complex so we have
made separate diagrams for each variable as shown below:
Circuit diagram for Y0:

In the above diagram A, B, C and D are Output of the flip flops E if the variable representing
coin insertion and F and G variables together represents the selected product. Y0 and Y1 are the
output variables which represents the dispensed product.

43
Circuit diagram for Y1:

In the above diagram A, B, C and D are Output of the flip flops E if the variable representing
coin insertion and F and G variables together represents the selected product. Y0 and Y1 are the
output variables which represents the dispensed product.

44
Circuit diagram for input of flip flop A:

In the above diagram A, B, C and D are Output of the flip flops E if the variable representing
coin insertion and F and G variables together represents the selected product. TA is the input of
flip flop A.

45
Circuit diagram for input of flip flop B :

In the above diagram A, B, C and D are Output of the flip flops, E is the variable representing
coin insertion and F and G variables together represents the selected product. TB is the input of
flip flop B.

46
Circuit diagram for the input of flip flop C :

In the above diagram A, B, C and D are Output of the flip flops, E is the variable representing
coin insertion and F and G variables together represents the selected product. TC is the input of
flip flop C.

47
Circuit diagram for the input of the flip flop D :

In the above diagram A, B, C and D are Output of the flip flops, E is the variable representing
coin insertion and F and G variables together represents the selected product. TD is the input of
flip flop D.

As we can see that the Boolean expressions consists of seven variables, thus it will require very
large number of gates to implement such large Boolean functions, due to that It might not be
possible to implement the circuit on bread board using IC’s.

48
6. Payment System

Coin and Bill Acceptors: These components validate and accept coins and bills. They are
equipped with sensors to detect counterfeit money.

Card Readers: RFID, magnetic stripe, and EMV chip readers allow for credit/debit card
transactions.

Contactless Payments: NFC readers enable mobile payments and other contactless payment
methods.

Connectivity: Secure connections to banking networks are essential for transaction processing.

7. User Interface

Display: LCD or touchscreen displays provide product information, prices, and instructions.

Buttons and Keypads: Physical buttons or capacitive touch buttons are used for product selection
and entering payment information.

Audio Feedback: Speakers can provide audio prompts and feedback to enhance user experience.

8. Control System

Microcontroller or PLC: A microcontroller or programmable logic controller (PLC) is the brain


of the vending machine, managing all operations.

Software: Embedded software handles tasks such as inventory management, user interaction, and
payment processing.

Sensors and Actuators Integration: The control system interfaces with various sensors and
actuators to monitor and control the vending process.

9. Connectivity and Telemetry

Networking: Wi-Fi, Ethernet, or cellular modules enable remote monitoring and control.

Telemetry: Telemetry systems provide real-time data on sales, inventory levels, and machine
status, which helps in restocking and maintenance planning.

Security: Secure data transmission protocols and encryption are critical to protect financial
transactions and user data.

Implementation Steps

1. Design and Prototyping:

Initial designs are created using CAD software, followed by prototyping using materials like
acrylic for initial testing.

The prototype is tested for mechanical functionality and user interaction.

49
2. Component Selection:

Selecting reliable motors, sensors, controllers, and payment modules based on the product
requirements and budget.

Integration of these components with the main control system.

3. Software Development:

Writing embedded software for the microcontroller or PLC.

Developing the user interface and integrating payment processing APIs.

4. Assembly and Testing:

Assembling all hardware components into the machine frame.

Comprehensive testing to ensure reliability, safety, and user-friendliness.

5. Field Testing and Iteration:

Deploying the machine in a real-world environment to gather data on performance and user
interaction.

Making necessary adjustments and improvements based on feedback.

Conclusion

Building a vending machine requires a harmonious integration of various hardware and software
components. Each component must be meticulously designed and tested to ensure that the
machine operates smoothly and efficiently. By leveraging modern technologies in payment
systems, connectivity, and control, vending machines can provide a reliable and user-friendly
experience.

50
CHAPTER 8
ADVANTAGES AND DISADVANTAGES

Advantages:
1. Convenience: Vending machines provide a convenient way for customers to access products
or services without the need for human interaction. This is especially beneficial in locations
where there might not be immediate access to traditional retail stores.

2. 24/7 Availability: Vending machines can operate 24 hours a day, 7 days a week, offering
products or services at any time. This continuous availability is particularly useful in
locations like airports, train stations, or workplaces where people may need items outside
regular business hours.

3. Reduced Labor Costs: As vending machines are automated, they don't require a constant
human presence. This can lead to reduced labor costs compared to traditional retail settings.

4. Quick Transactions: Vending machines facilitate quick transactions. Customers can select a
product, make a payment, and receive their item in a matter of seconds, contributing to
efficiency and time savings.

5. Space Efficiency: Vending machines take up relatively little space, making them suitable for
locations with limited square footage. They can be placed in areas where traditional stores
might not be feasible.

Disadvantages:
1. Limited Product Variety: Vending machines are typically designed to offer a limited range of
products due to space constraints. This limitation can be a disadvantage for customers
seeking a diverse selection.

2. Maintenance Issues: Vending machines can face technical malfunctions, and maintenance is
essential to ensure they operate smoothly. Issues such as coin jams, product jams, or power
failures can disrupt service.

3. Lack of Personal Interaction: Some customers prefer personal interaction when making
purchases. Vending machines lack the personalized service that human-staffed stores can
provide, which may impact customer satisfaction in certain situations.

4. Payment Limitations: Vending machines often accept only cash or specific types of cards,
limiting payment options. As digital payment methods become more popular, vending
machines may need to adapt to accommodate diverse payment preferences.

5. Product Freshness Concerns: In cases where vending machines dispense perishable goods,
there may be concerns about the freshness of the products, especially if they are not
restocked regularly.

51
The advantages and disadvantages of vending machines can vary depending on the context and
the specific needs of the users. Advances in technology may address some of the limitations
associated with vending machines, making them more versatile and user-friendly in the future

52
CHAPTER 9
CONCLUSION
When we realized that we have at last made a code that could actually work as a user friendly
vending machine. This code can actually provide a variety of options to the user and also return
him/her the balance money. This verilog code has been successfully verified using the EDA
playground simulation tool and Icarus verilog 0.9.7 compilation tool and the desired outputs
have been achieved. Vending Systems enhances productivity, reduces system development cost,
and accelerates time to market. Vending machine give fast response and easy to use by an
ordinary person. The designed machine can be used for many applications and we can easily
enhance the number of selections. thus we would conclude saying that we tried our best to
modify the present day complex vending machine into a user friendly and user specific vending
machine.

In conclusion, the Finite State Machine (FSM)-based vending machine project


implemented in Verilog language provides a robust and efficient solution for automating the
dispensing of products. Through the careful design of states, transitions, and outputs, the FSM
ensures seamless operation and accurate response to user inputs. This project leverages the
strengths of Verilog, a hardware description language, to model the behavior of the vending
machine in a manner that is both clear and concise.

The advantages of using an FSM approach in this project include its ability to capture
the complex and sequential nature of vending machine operations. By breaking down the system
into states and transitions, the Verilog implementation allows for a structured and systematic
representation of the vending machine's behavior. This enhances the overall reliability and
maintainability of the system. The modular and scalable nature of the Verilog code facilitates
easy modifications or additions to the vending machine's features, making it adaptable to
changing requirements.

However, like any project, there are challenges and considerations. Careful attention must be
paid to the design to ensure the FSM accurately reflects the desired vending machine behavior.
Additionally, thorough testing and validation are crucial to identify and rectify any potential
errors in the Verilog implementation.

In summary, the FSM-based vending machine project in Verilog demonstrates a


practical and effective application of digital design principles. It not only showcases the power of
FSMs in modeling complex systems but also highlights the versatility of Verilog in hardware
description and implementation. This project serves as a foundation for further exploration and
refinement, paving the way for the development of more sophisticated and feature-rich vending
machine systems in the future.

53
CHAPTER 10
REFERENCES
• Fauziah Zainuddin, Norlin Mohd Ali, Roslina Mohd Sidek, Awanis Romli, Nooryati
Talib & Mohd. Izham Ibrahim (2009) "Conceptual Modeling for Simulation: Steaming
frozen Food Processing in Vending Machine" International Conference on Computer
Science and Information Technology, University Malaysia Pahang, pp.145-149.

• Xilinx Inc., Spartan 3 Data sheet: http://www.xilinx.com.

• Bhasker "VHDL primer" Second Edition.

• Peter Minns & lan Elliott, "FSM-based Digital Design using Verilog HDL", John Wiley
& Sons Ltd 2008.

• Zhang Wen & Zhang Xin Long (2010) "Design and Implementation of automatic
vending machine Based on the short massage payment" International Conference on
Information and Communication technology in Electrical Sciences, Neijiang, Sichuan,
China.pp.978-981.

54

You might also like