Cpr E 281 Final Project
Spring 2014 semester
Vending Machine
Daoxi Sun
Introduction
In this project, I will design a vending machine prototype, it should accept three most commonly used
coins (nickel, dime, quarter) in U.S. and it will provide 2 different products (A and B).
The machine accepts only one coin at a time, controlled by switches SW1 and SW0. A nickel, dime, or
quarter is added if SW1, SW0 = 01, 10, or 11 respectively. The vending machine cannot hold more than
35 cents. Thus, if inputting a coin would cause the total to go over this value, the total should not be
updated and the coin should be rejected.
Products A and B cost 10 and 25 cents respectively. A user indicates they wish to purchase these
products by setting SW2 to 1 (for product A) or SW3 to 1 (for product B). If both SW2 and SW3 are set to
1, the machine dispenses the change. A product should not be dispensed if there is not sufficient money
inside the vending machine.
I’m free to choose whether or not the remaining change is dispensed along with the product (e.g.,
purchasing product A with 25 cents in the machine brings the total down to either 15 or 0 cents). If both
a coin is added and a product is selected, the product will have priority and the coin will be rejected. A
rejected coin should be indicated by a single LED.
I will display the amount of money in the vending machine using two seven segment displays, also I will
display the value of the coin the user wishes to enter into the machine.
Software used: Quartus II
Programing language used: Verilog
Device used: Field Programmable Gate Array (FPGA) DE2 board
Project also requires knowledge of logic circuit design, Boolean algebra, and state machine.
Lab
Here is how I allocated the switches:
Clock: SW17
Money0: SW0
Money1: SW1
Product A: SW2
Product B: SW3
Seven segment display below shows when SW0=1, SW1=0, user wishes to put in 5 cents (a nickel).
(the number of each switch is below each switch, zoom in to see it clearly, toggled-up means on (1),
toggled-down means off (0))
Similarly, when SW0=0, SW1=1, user wishes to put in 10 cents (a dime).
When SW0=1, SW1=1, user wants to put in 25 cents (a quarter).
Note that nothing has happened to the balance of vending machine, because we have not toggled the
clock (SW17) yet.
Now, keep SW0=1, SW1=0 and then toggle clock once, 5 cents has been added to the vending machine.
Toggle again, another 5 cents are added.
Now try to buy product B (SW3), nothing happened as there is not enough money.
Now add more money until balance reaches 30 cents.
Now buy product A, part of money is used, and rest of the money is returned to the user, so the balance
goes back to 0 cents.
The vending machine cannot hold more than 35 cents, if a user tries to add more, it will be rejected,
indicated by a red LED.
When both money and product is selected, money will be rejected, indicated by the same red LED.
The internal design of this project is shown below:
Upper part of project:
Lower part of project:
*To view the Verilog codes written for the blocks, open the .v files in the project folder.
Conclusion
To conclude, my design meets the requirement, and this project helped me understanding the concept
of state machine and practicing Verilog. The design process was difficult but I enjoyed finding solution by
myself.