You are on page 1of 5

Design and Implementation of A Finite State Machine Based Vending Machine

Controller
Abdullahi Isa Mikail
MSc. Telecommunication and
Electronic Engineering.
Sheffield Hallam University,
Sheffield, England
b5035600@my.shu.ac.uk

Abstract
As people continue to seek ultimate convenience, more
and more technologies are being invented. One of these
technologies is the vending machine. Majority of the
vending machines available today are based on CMOS,
SED or Micro-controller technology. In this paper a
Vending machine controller based on the Mealy Model of
finite state machine is discussed. The design is
functionally verified using Modelsim simulator.
Keywords-FSM;VendingMachine;VHDL;Modelsim
simulator FPGA : Altera DE2 board.
.

Introduction
A vending machine is a machine that dispenses
various products to customers, after the customer must
have inserted money into it. Vending machines have been
around since the early 20th century. The first vending
machine to be used for commercial purposes was
introduced in London used for selling postcards.
Vending machines are more accessible nowadays as
they can be found everywhere from hospitals, schools and
train stations vending chocolates and drinks to the
banking industry as ATM machines. Most vending
machines available nowadays are based on CMOS circuit,
SED, and Microcontroller technology [1]. The CMOS
circuit and SED based machines are more time
consuming than FPGA based machines. Also the FPGA
based vending machine is more flexible to change as it is
reprogrammable and can be reconfigured. Whereas in the
microcontroller based vending machine when there is
need for an upgrade the whole architecture has to be
changed.
In this paper, the design of a finite state machine based
vending machine controller, the machine can only accept
four coins, after the four coins have been inserted into the
machine, any coin fed into the machine again will be
returned back to the customer automatically. This

machine also supports a cancel feature which enables


customers to cancel a transaction and retrieve their
money. This machine can be used at various places,
ranging from airports, hospitals, restaurants, streets,
schools. The machine is very easy to use and it is also
efficient in terms of cost and time.
The functionality of the proposed vending machine
has functionally simulated using Modelsim simulator and
implemented on the Altera DE2 board. The types of
Finite State machines (i.e. of Mealy and Moore machines)
are also explained in this paper. The basic steps all
vending machines follow, the operation of the proposed
machine, the flow chart for the vending machine,
evaluation and results of the proposed machine are all
discussed in this paper. The conclusion is also covered in
the last part of this paper.

Finite state machines (FSM)


The finite state machine is an important tool for
Digital engineers, it serves as a mathematical model of
computation used to design sequential logic. The machine
can only be in one state at a time, this state is called the
present state. The machine can also move from one state
to another, this movement is called a transition and it can
only be triggered by pre stated events or conditions.
Finite state machines can be divided into two main types,
The Mealy State Machine Model and The Moore State
Machine Model.
The Mealy State Machine Model: in this type of
FSM, the output values are determined by both the
current state and the current input. The Mealy State
Machine Model is shown in Figure 1.

16-7220 Digital Electronic System Design, Sheffield Hallam University.

Figure 1: the Mealy state machine model


The Moore State Machine Model: in this type of
FSM, the output values are determined only by the
current state. The Mealy State Machine Model is
shown in Figure 2.

There are also two input signals reset and clk. The
machine works on the positive edge of clock and returns
to its initial state when reset button pressed. The proposed
machine is designed using Finite state machine modelling
and is coded in VHDL language. VHDL language was
chosen for the implementation of this machine because of
its flexibility and efficiency. Details of the entire signals
with their description is shown in table 2.
The advantages of VHDL implementation includes
minimum cost and time, better design, faster time to
market and increased flexibility.
Table 1: Products with their prices.
S/N Products
Prices
1

Coca-Cola

2 pounds

Figure 2: the Moore state machine model

1 Bar of chocolate

2 pounds

Operation

Bottle of water

3 pounds

The basic operation of a vending machine are as follows;


1. Selection: Customer selects product from the menu
2. Waiting for Money to be inserted: when the
customer inserts the money, the counter tells the
control unit how much have been inserted in the
vending machine.
3. Product Deliver: if the correct amount has been
inserted, the machine dispenses the selected
product. In case of excess money, the balance will
be returned to the customer.
4. Service: If the product is not available, the vending
machine will ask for service.
5. Cancel: this is when the user wants to withdraw his
request. Money will also be returned back.

Implementation of the vending machine


The first step to implementing the proposed machine
is constructing a state diagram. The vending machine can
dispense 3 products which are 50cl Coca-Cola bottle, 1
Bar of chocolate and 1 liter of water. The products are
selected by W for water, C for Coca-Cola and B for bar
or chocolate. The machine also has a cancel button Cr for
if a customer wants to cancel a request if this happens, the
coin is returned through the Coin return out CRo. It is
also important to note that only one input can be active at
a time and all products can be dispensed in one clock
cycle. Furthermore, if no input is active, the state machine
stays in its current state. If more than 3 pounds is inputted
into the machine, the money is automatically returned
through the Qo output. Other output signals include Wo
Water Out, Co Cola. The products and their prices are
contained in table 1.

Figure 3: Flow chart for the vending machine.


Table 2: Input/ Outputs with remarks
Name
Wid Direction
Description
th
Clk

Input

Clock

Reset

Input

System reset

Ci

Input

Coca Cola request

Bi

Input

Chocolate
Request

Wi

Input

Water request

Cr

Input

Cancel

Qi

Input

Total money

Co

Output

Coca-Cola out

Bo

Output

Chocolate bar out

Wo

Output

Water out

Cro

Output

Output
money

Qo

Output

Output extra change

bar

return

Select Coca-Cola (move to state E, output a


Coca-Cola, then move to state A)
Select Bar of Chocolate (move to state F,
output Bar of chocolate, then move to state A)
or
Insert another pound (3 pounds move to
state G and wait).
4. When the machine is in State G(3 pounds), the
customer can either
Do nothing (stay in state G)
Hit the coin return button (go to state C and
return the money)
Select a Coca-Cola (move to state k, return
1pound and then move to state E, output a
Coca-Cola, then move to state A)
Select a bar of Chocolate (Go to state J, return
1 pound then move to state F, output a beer
then go to state A)
Insert 1 pound (return the 1 pound too much
money move back to state G and wait) or
Select a water (go to state H, output water,
then move to state A)
It is important to note that the machine only accepts 1
pound coins. The complete state diagram is shown in
Figure 3 and the state table in table 3 below;

Design methodology
The state diagram used to implement this machine
consists of eight states (A, B, C, D, E, F, G, and H) for
every transition from one state to the other, there is
condition that must be met so the machine can decide on
which state to execute next. After the condition has been
met, the machine goes back to a WAITING state. At the
end of the whole process the customer will get their
desired product if the price of the product is equal to the
amount inputted. The conditions for which the circuit
moves from one state to the next are stated below;
1.

2.

3.

When nothing happens, or if the machine has been


reset, the machine is in State A.
If 1 pound is inputted into the machine, the
machine goes to State B,
when in State B the customer can either
Do Nothing
Hit cancel (Go to state C and return the
money) or
Insert another pound (2 pounds) to move to
State D (move to State D and wait).
When the machine is in state D, the customer can
choose to either
Do nothing (Stay in State D), Hit the coin
return (move to state C and return the money)

Figure 4: State Diagram for vending Machine.

Table 3: State table for vending machine

machine does not dispense water (PURPLE). Cancel is hit


and no coin is returned (GREEN).
The Register Transfer Level (RTL) schematic diagram is
shown in figure 6

Figure 5: simulation waveform showing how the machine


handles more than 3 pounds.

Simulation Results
The state diagram in figure 4 and the State table in table 3
were used to produce the wave form below. The wave
form in figure 4 shows 4 different scenarios. In the first
scenario, 2 pounds is inputted into the machine to buy a
bar of chocolate, a bar of chocolate is dispensed. In the
second scenario 2 pounds is also inputted into the
machine but this time the customer wants to buy a bottle
of Coca-Cola, the Coca-Cola is then dispensed. In the
third scenario the customer inputs 3 pounds and buys a
bottle of water. In the last scenario, the customer inserts a
1 pound coin and later hits the cancel, the coin is then
returned.

Figure 6: RTL Schematics

Conclusion

Figure 4: simulation waveform showing selection of


Coca-Cola, bar of chocolate, water and cancel.

The design of this vending machine is functionally


verified using Modelsim simulator and is implemented on
Altera DE2 board. The result shows that FPGA based
vending machines are far more efficient than CMOS
circuit, SED, and Microcontroller based vending
machines. The FPGA based vending machine is also very
flexible and reliable and it is easy for the algorithm used
to be enhanced to cater for a greater number of products
and coins.

References
The simulation waveform in figure 5 below shows 5
different scenarios. The first scenario is an attempt to
insert 5 coins into the machine (RED) but the machine
starts to return coins after the third coin has been inserted
(BROWN). Then a bar of chocolate is selected, a bar of
chocolate is dispensed and 1 pound is returned (BLUE).
Four more 1 pound are inputted and the, the machine
returns the third one (RED) 1 Coca-Cola is bought and 1
pound is returned (YELLOW). Buy water is hit and the

[1] . M. V. Ms.Rincy and S. . M. Jeeba, "Design and


Implementation of Multi Select Smart," International
Journal of Computer Networks and Wireless
Communications (IJCNWC), 2014.

About the Author


Abdullahi Isa Mikail received a Bachelors degree
from the department of computer science, Al-Hikmah
University, Ilorin. Presently doing his MSc. In
Telecommunication and Electronic Engineering at
Sheffield Hallam University, Sheffield England.

You might also like