Vending machine
From Ece
To design and implement a vending machine controller in Spartan-3E FPGA.
Contents |
Phase 1
Team Member
Nischal Dahal Coordinator, Checker, Recorder
Introduction
This project is based on the design and implementation of a vending machine controller. The payment, dispensing and returning change will be simulated by using the switches, buttons and leds of the Spartan-3e FPGA board of Xilinx. A user will input a product code via a keyboard interfaced with the FPGA and the system will dispense the corresponding product and change if the price of the entered product is less or equal to amount inserted by the user.
Concept
The main part of this project is to design the data-path and FSM for the controller of the data-path. This project will employ a finite state machine with few states. After the completion of the project, I expect to better understand finite state machine. The main parts required for the project are as follows
- Spartan3 Board ( already owned)
- Keyboard ( already owned)
Proposed Work
- Vending machine can dispense four products of price 25, 50, 75 or 90 cents each, the input of the product is delivered via switches
- Use two of the seven segment displays to display the cost of the product entered (Lower Two)
- Vending machine will accept nickel, dime, quarter and dollar from keyboard to be interfaced with the FPGA.
- Dispensing of the product is simulated by turning on led for 1 second for specific product
- Change to be given to the customer is shown in seven segment display (Upper two)
- After the product is dispensed, change is given to customer (nickel, dime and quarter) are given to customer by turning on corresponding led.
- For audit and stocking purposes the machine sends a signal, corresponding to the product dispensed to the computer via RS232.
- The vending machine resets at the end of a cycle
- A button is assigned as a canceling the current transaction or master reset, If amount has already been entered then that amount is returned to the customer, if product is already dispensed then the reset is ignored.
The basic flow diagram is shown in the figure.
Expected Deliverables
At the end of phase 4, it can be expected that Spartan 3E board will take input money (nickel, dime, quarter and dollar) from buttons of the board and dispense the product corresponding the product code entered by customer via a keyboard interfaced with the board giving appropriate change to the customer.
Phase 2
Introduction
This project is based on the design and implementation of a vending machine controller. The payment, dispensing and returning change will be simulated by using the switches, buttons and leds of the Spartan-3e FPGA board of Xilinx. A user will input a product code via a keyboard interfaced with the FPGA and the system will dispense the corresponding product and change if the price of the entered product is less or equal to amount inserted by the user.
Concept
The main part of this project is to design the data-path and FSM for the controller of the data-path. This project will employ a finite state machine with relatively few states. After the completion of the project, I expect to better understand finite state machine. The main parts required for the project are as follows
- Spartan3 Board ( already owned)
- Keyboard ( already owned)
Modules
Keyboard Interface
The keyboard will take the input of product selected by the user.
- Input(s): Keyboard strokes
- Output(s): Product code of the corresponding selection.
Product codes
| Key | Product/Operation | Code |
| X | Invalid Code | 000 |
| 1 | Yoghurt | 001 |
| 2 | cookie | 010 |
| 3 | coke | 011 |
| 4 | wafer | 100 |
| NUM LOCK | Cancel Transaction | 101 |
| Enter | Enter | 110 |
Product2Price
This will map the product to it's corresponding price.
- input: Product code.
- output: Price of the product.
Coin Input Interface
This interface will take the coin input from buttons of SPARTAN 3E board. Each button press will emulate the insertion of coin inside the vending machine. This unit will be responsible for keeping the track of coins inserted by the user.
Finite State Machine
This control the flow of data from input to output with necessary manipulation of the inputs with in the data-path
- Input(s): product Code, coins, deposited amount, price of currently selected product.
- Output(s): loads and clears inputs of the registers used in the data-path.
Finite State Machine Operation
- On Startup, all registers are empty. In the FIRST STATE have the amount entered by the user displayed at Seven Segment display which means the content of the register DepositReg is to be displayed at SSD. The next state will be reached if user enters any product from keyboard interfaced with the Basys board.
- The SECOND STATE is entered when user enters a product into a system via the keyboard. The user has to confirm the product by entering enter key of the keyboard. Before confirming the product the user can change the product he/she desired as many times as he wants. The system has to display the content of the PriceReg which holds the price of the currently selected product. The next state will be reached if user confirms the product by pressing enter key or user opts to cancel the current transaction.
- The THIRD STATE displays the change to be given to the user (value of coin inserted - price of the product just selected by the user) on the SSD and product selected by the user in the LED by lighting the corresponding LED of the board to indicate that the product is being dispensed. The system has to display the content of ChangeReg in SSD and glow the led in Basys board corresponding to the product selected by the user.
- The FOURTH STATE is reached when the price of the product is greater than the value of the totals coin inserted by the user, in this case the coin inserted is returned to the user by displaying the proper amount in SSD and system again returns to FIRST STATE. The system has to display the content of the ChangeReg in the SSD.
- The system reached a FIFTH STATE when cancel button is entered in any state, If the coin has been inserted at the time of canceling the transaction then the coin is returned to the user. Whenever the user enters any coins then system reaches the FIRST STATE accepting the coin just entered by user as a new input. If the product has already been dispensed then the cancel command is ignored.
Dispensing Unit
This unit will be responsible for the lighting on one of the led of the board to emulate the dispensing of the product if the deposited amount is greater or equal to the price of the product. And this module will also responsible for asserting output to the PC via RS232 for audit and stocking purposes
- Input(s): disp_ld input of FSM, Price
- Output(s): ledOut
Change Unit
This unit will be responsible for giving the change to the user. If the user cancels transaction before product is dispensed then deposited amount is given back to user. If deposited amount exceeds the price of the product then excess amount is returned to the user.
- Input(s): Deposit, price
- Output(s): SSDOut
Required Parts
- Spartan III development board
- PS/2: Keyboard
Phase 3
Introduction
This project is based on the design and implementation of a vending machine controller. The payment, dispensing and returning change will be simulated by using the switches, buttons and leds of the Spartan-3e FPGA board of Xilinx. A user will input a product code via a keyboard interfaced with the FPGA and the system will dispense the corresponding product and change if the price of the entered product is less or equal to amount inserted by the user.
Concept
The main part of this project is to design the data-path and FSM for the controller of the data-path. This project will employ a finite state machine with few states. After the completion of the project, I expect to better understand finite state machine. The main parts required for the project are as follows
- Spartan3 Board ( already owned)
- Keyboard ( already owned)
Module Description
Keyboard Interface
The keyboard will take the input of product selected by the user.
- Input(s): Keyboard strokes
- Output(s): Product code of the corresponding selection.
PS2Core
This module is the same as used in the labs. It converts the keyboard code into usable code.
- Input(s):
- PS2Clk
- PS2Data
- Output(s):
- hexcode(15:0) The corresponding usable code
DecodeProduct
This module converts the hexcode into the product code defined by table 1
- Input(s):
- Valid: If the code in code input in valid to avoid double press
- Clk: Clock signal
- Code(15:0): Code from PS2Core
- Output(s)
- ProdCode(2:0): product code of the product entered by user.
ProdReg
Holds the product code
- Input(s):
- d(2:0): Product code
- Clr: Synchronous reset signal
- enable: load signal of register
- clk: Clock signal
- Output(s):
- q(2:0): Product code
Product2Price
Maps the product to its corresponding price
- Input(s):
- ProdCode(2:0): Product code
- Output(s):
- Price(7:0): Price of the product
Coin Input Interface
Takes the coin input adds and stores
Input Buffer
Takes the inputs from buttons and prevents multi-inputs on one push.
- Input(s):
- clk: Clock signal
- Coin(3:0): Button input for coins
- Output(s):
- B(3:0): Buffered Coin input
DecodeCoin
Decodes the input button into corresponding coin input
- Input(s):
- Coins(3:0) Buffered coin input
- clk: Clock signal
- Output(s)
- Amount(7:0): denomination of corresponding coin
Adder
Adds the denomination of coins inserted by the user
- Input(s):
- A(7:0): One operand
- B(7:0): Other Operand
- Output(s):
- Z(7:0): Result
DepositRegister
- Input(s):
- clk: clock signal
- CE: chip enable
- D(7:0): input
- Output(s)
- Q(7:0): input after one clock cycle
Finite State Machine
- Input(s)
- clk: Clock Signal
- prodcode[2:0]: Product code
- coins[3:0]: coins input
- [7:0] price: price of the currently selected product
- [7:0] deposit: Total sum of denomination of coins inserted by user
- Output(s)
- dpst_ld: Load signal for deposit register
- pdt_ld: Load signal for product register
- price_ld: Load signal for price register
- cng_ld: Load signal for change register
- reset: reset signal
- dispense: Dispensing signal
- SSD_sel[1:0]: MUX select
- state[2:0]: State for debugging purpose
Dispensing Unit
This unit glows the LEDs of corresponding to the product selected by the user.
- Input(s):
- clk: clock signal
- en: enable signal
- clr: reset signal
- ProdCode(2:0): Code of the product to be dispensed
- Output(s)
- Product(3:0): Signal to LEDs
Change Unit
displays the change in Seven Segment display
Subtracter
- Input(s)
- A(7:0): One operand
- B(7:0): Other Operand
- Output(s):
- Z(7:0): Result
Change Register
- Input(s):
- clk: clock signal
- CE: chip enable
- D(7:0): input
- Output(s)
- Q(7:0): input after one clock cycle
Phase 4
Top-level Schematic
Verification Plan
As the inputs of the system is limited. The verification of correct working of the design was done manually, which is as follows
- All the sequence of products were tried both sequentially and randomly before confirming the product.
- All the sequence of coins were tried both sequentially and randomly.
- Invalid product inserted from keyboard.
- The scenario of amount of coin inserted greater than the price of product created.
- The scenario of amount of coin inserted less than the price of product created.
- The scenario of amount of coin inserted equal to the price of product created.
- The buttons were hold for different durations randomly.
Verification Plan Output
- Every time latest selected product was processed. SUCCESS
- Every time correct amount was displayed. SUCCESS
- Every time invalid products codes were ignored. SUCCESS
- Every time correct change was displayed and product was correct product was dispensed. SUCCESS
- Every time amount inserted by user was displayed (returned) to the user and no product was dispensed. SUCCESS
- Every time no change was returned to user and correct product was dispensed. SUCCESS
- Few times the dispensing led was not turned off. PARTIAL SUCCESS
Known Issue(s)
After the verification plan was executed, a bug was detected in the system. After the product is dispensed, the system should reset when a coin is inserted, but at times, the dispensing led was not turned off. However this error do not occur with consistency and the replication step was not correctly isolated. The cause of the error is suspected to be some form of timing issue. Few measures were taken to fix this bug, but no improvement was achieved. So, this has been stated as a known issue.
Deliverables and Output
The implementation of a vending machine controller was achieved. The payment, dispensing and returning change has been simulated by using the switches, buttons and leds of the Spartan-3e FPGA board of Xilinx. A user can input a product code via a keyboard interfaced with the FPGA and the system will dispense the corresponding product and change if the price of the entered product is less or equal to amount inserted by the user. The change is shown in the Seven segment display. The dispensing of the product is simulated by lighting the corresponding led of the FPGA board.
Source Code
The Source Code can be obtained here
Limitation
- The amount of deposit has been implemented only in 8 bits, so the deposited amount get lost when more than 255 cents are inserted.
- Only four products has been implemented in this demonstration, we can increase the number of products to 10 with current design, because each keyboard press is considered as a separate input.
- Only four coin denomination is used because of the limitation of four buttons on spartran3 board.
Future Work
The number of bits can be increased to handle more than 255 cents.





