Professional Documents
Culture Documents
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.
Coin N Gum
Vending- Open
Sensor D Machine Release
FSM Mechanism
Reset
Clk
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.
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:
Reset
S0
N D
S1 S2
N D N D
S3 S4 S5 S6
[Open] [Open] [Open]
N D
S7 S8
[Open] [Open]
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
specification allows us to assume that N and D are never asserted at the same time).
Also, we include the output Open only in states in which it is asserted. Open is implicitly
unasserted in any other state.
State Minimization
This nine-state description isn't the "best" possible. For one thing, since states S4, S5, S6,
S7 and S8 have identical behavior, they can be combined into a single state.
To reduce the number of states even further, we can think of each state as representing
the amount of money received so far. For example, it shouldn't matter whether the state
representing 10 cents was reached through two nickels or one dime.
A state diagram derived in this way is shown in Figure 7.37. We capture the behavior in
only four states, compared with nine in Figure 7.36. Also, as another illustration of a
useful shorthand, notice the transition from state 10¢ to 15¢. We interpret the notation
"N, D" associated with this transition as "go to state 15¢ if N is asserted OR D is
asserted " and could have also written it as N + D.
Reset 0¢
5¢ D
D 10¢
15¢
[Open]