# A Simple Vending Machane

Topics: State diagram, State, Diagram Pages: 5 (897 words) Published: March 12, 2013
Contemporary Logic Design, 2 Ed.

Spring 2008

Katz and Borriello

A Simple Vending Machine
To illustrate the basic design procedure, we will advance through the implementation of a simple finite state machine that controls a vending machine. Here is how the control is supposed to work. The vending machine delivers an item after it has received 15 cents in coins. The machine has a single coin slot that accepts nickels and dimes, one coin at a time. A mechanical sensor indicates whether a dime or a nickel has been inserted into the coin slot. The controller's output causes a single item to be released down a chute to the customer. We will make two additional assumptions to further simplify our specification. First, we will design our machine so it does not give change. A customer who pays with two dimes will lose the five extra cents! Second, we will expect our machine to be reset before each new use. This might be accomplished through a separate mechanism the customer uses to select the item to be purchased. N D Reset Clk

Figure 7.35 Vending-machine block diagram

Coin Sensor

VendingMachine FSM

Open

Gum Release Mechanism

Understanding the Problem
The first step in the finite state machine design process is to understand the problem. Start by drawing a block diagram to understand the inputs and outputs. Figure 7.35 is a good example. Let's assume that N is asserted for one clock period when a nickel is inserted into the coin slot and that D is asserted when a dime has been deposited. Furthermore, we'll postulate that it is enough if the machine asserts Open for one clock period to release an item after 15 cents (or more) has been deposited since the last reset. It is important to list these assumptions, as they will need to be verified later with other members of the vending machine design team. The specification may not completely define the behavior of the finite state machine. For example, what happens if someone inserts a penny into the coin slot? Sometimes we have to make reasonable assumptions. We'll assume that the coin sensor is designed so that it returns any coins it does not recognize, leaving N and D unasserted. As you can see, these assumptions can have significant implications for how other parts of the vending machine will have to be designed and implemented. In a design team, it is crucial to have a process that gets these assumptions aired early and keeps track of them as the design progresses.

1

Contemporary Logic Design, 2 Ed.

Spring 2008

Katz and Borriello

Abstract Representations
Once you understand the behavior reasonably well, it is time to map the specification into a more suitable abstract representation. A good way to begin is by enumerating the possible unique sequences of inputs or configurations of the system. These will help define the states of the finite state machine. For this problem, it is not too difficult to enumerate all the possible input sequences that lead to releasing an item: • • • • • Three nickels in sequence: N, N, N Two nickels followed by a dime: N, N, D A nickel followed by a dime: N, D A dime followed by a nickel: D, N Two dimes in sequence: D, D Reset S0

N
S1

D
S2

N
S3

D
S4
[Open]

N
S5
[Open]

D
S6
[Open]

N

D

S7
[Open]

S8
[Open]

Figure 7.36 Initial vending-machine state diagram

This can be represented as a state diagram, as shown in Figure 7.36. For example, the machine will pass through the states S0, S1, S3, S7 if the input sequence is three nickels. To keep the state diagram simple and readable, we include only transitions that explicitly cause a state change (in other words, we leave out the self-arcs). For example, in state S0 if neither input N or D is asserted, we assume the machine remains in state S0 (the

2

Contemporary Logic Design, 2 Ed.

Spring 2008

Katz and Borriello

specification...