Professional Documents
Culture Documents
A Simple Vending Machine
A Simple Vending Machine
Spring 2008
Coin Sensor
VendingMachine FSM
Open
Spring 2008
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]
S7
[Open]
S8
[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
Spring 2008
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 N
N D N
15
[Open]
10