Transcribed TextTranscribed Text

Finite State Machine Design–A Vending Machine Design a vending machine with finite state machine using verilog 1.0 Introduction Design of sequential circuits is quite a bit more involved than that of combinational circuits. There are many opportunities for things to go wrong, and debugging a malfunctioning circuit can be tedious at best and downright frustrating at worst. Fortunately, by adopting a structured approach to the design and debug of sequential circuits, and by carefully documenting the design, many of these problems become manageable. The analogy to software development here is quite apt; if you write “spaghetti” code you are more likely to be frustrated when things don’t work, and won’t get much sympathy when you seek help. The reward for discipline, on the other hand, is that you’ll spend less time chasing after hard-to-find bugs and more enjoying the fruits of your creativity. Design can be fun! 2.0 Design Specifications VENDMACH is a vending machine that accepts nickels, dimes, and quarters, and dis-penses gum, apple, or yogurt. A gum pack costs 15¢, an apple is 20¢, and yogurt is 25¢. FIGURE 1. Top-level schematic of VENDMACH VENDMACH Left Most two Seven segment LEDs SW0 SW1 (GUM) (APPLE) (YOGURT) Other Seven segment LED Green LEDs SW2 The top-level schematic of VENDMACH is shown in Figure 1. The machine has the fol- lowing 1-bit inputs: • NICKEL: a signal that becomes 1 when a nickel is deposited in the coin slot. • DIME: a signal that becomes 1 when a dime is deposited in the coin slot. • QUARTER: a signal that becomes 1 when a quarter is deposited in the coin slot. • COINRETURN: a signal that becomes 1 when the coin return button is pressed. • GUM: a signal that becomes 1 when the gum selection button is pressed. • APPLE: a signal that becomes 1 when the apple selection button is pressed. • YOGURT: a signal that becomes 1 when the yogurt selection button is pressed. In addition to these “user” inputs, the machine has two control inputs: • CLOCK: a timing signal that sequences the state transitions of the machine. • INIT: an initialization signal that resets the machine to a suitable starting state. The machine has three outputs: • CREDIT: the amount of money deposited so far and available to make a purchase; CREDIT, in cents, should be displayed on the LEFT most seven segment displays. • DISPENSED ITEM: the item that was just purchased should be displayed on one of the other seven segment displays. Display: g for gum, A for apple, and y for yogurt, as indicated in Figure 1. • CHANGE: the amount of money returned in change, or as a result of pressing the coin return button. The machine returns change using only nickels; the number of nickels returned should be displayed as a binary number using the three right-most Green LEDs. The machine should behave in accordance with the following specifications: 1. A customer needs to deposit a sufficient amount of money before or at the same time that he or she is selecting an item for purchase. If the item costs less than the depos- ited amount, the item is dispensed and the correct change is returned. If the item costs more than the deposited amount, the machine waits for more coins to be inserted or for a cheaper item to be selected. 2. The coin slot in the machine will only accept a single coin. Attempts to jam two or more coins cannot affect the state of the machine and are ignored. Similarly, attempts to make multiple selections (e.g. selecting apple and yogurt at the same time) are ignored. 3. At any time, pressing the coin return button causes the credit amount to be returned as change in nickels. Furthermore, when credit is equal to 25¢, any additional coins that are inserted are immediately returned as change. Finally, the return button closes the coin insertion slot; thus attempting to deposit a coin while at the same time press- ing the return button prevents the coin from being inserted.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

`timescale 1ns / 1ps
// Company:
// Engineer:
// Create Date:   
// Design Name:
// Module Name:    fsm
// Project Name:
// Target Devices:
// Tool versions:
// Description:
// Dependencies:
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
module FSM(nickel,dime,quarter,coin_ret,clk,init,gum,apple,yogurt,disp_item,crdl,crdr,change);
input nickel,dime,quarter,gum,apple,yogurt,clk,init,coin_ret;
output reg [6:0]disp_item,crdl,crdr;
output reg [2:0] change;
reg [2:0] state,next_state;

parameter Zero=0, //these are the states of the FSM
    Five = 1,
    Ten = 2,
    Fifteen = 3,
    Twenty = 4,
    TwentyFive = 5;

always @(posedge clk) begin
if ((nickel&&dime)||(dime&&quarter)||(quarter&&nickel)||(nickel&&dime&&quarter)||(gum&&apple)||(apple&&yogurt)||(yogurt&&gum)||(gum&&apple&&yogurt))

if (init)

case (state)
Zero: begin
if (nickel)
if (dime)
if (quarter)
Five: begin
crdl=7'd0; //7 segment display is in the order of 0123456 i.e segA corresponds to MSB

By purchasing this solution you'll be able to access the following files:
fsm.qsf and fsm.v.

for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Electrical Engineering Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats