DESIGNING THE CONTROL MODULE FOR A NEWSPAPER VENDING MACHINE


SECTIONS

PROBLEM DEFINITION

Design the control for a newspaper vending machine. The newspaper costs 35 cents, which can be paid in any combination of nickels, dimes, and quarters. The customer presses a "start" button and then begins entering coins. Coin sorter logic indicates to the FSM whether a nickel, dime, or quarter has been deposited by asserting the corresponding signal when appropriate. If exact change is entered, the control asserts "unlatch" so the customer can take a paper. If the amount of money the customer inserts exceeds 35 cents, change is given if possible. If insufficient change is availiable, all money inserted by the customer is refunded.

Assume that the money inserted by the customer is kept separated from money inserted by previous customers, which are held in a coin repository. Change is given only in dimes and nickels; the number of nickels and dimes availiable for refund are decimally encoded in the signals "nickelChange2..nickelChange0" and "dimeChange1..dimeChange0". In the case that the customer inserts more money than the newspaper costs, the FSM pulses a "nickelRelease" and/or "dimeRelease" signal to release one coin of change at a time (it would jam the machine to release more than one coin at a time).

If insufficient change is available, all coins the customer has inserted are refunded by the FSM by asserting a "refundMoney" signal. Otherwise the customer's 35 cents are deposited in the coin repository as the FSM asserts a "depositCoins" signal.

A block diagram of the module would look as follows:

Implement the FSM as a synchronous Mealy machine and test it for two cases: (1) when two quarters are inserted and there is sufficient change, and (2) when two quarters are inserted and there is not sufficient change.

This problem is based on 8.27 of Katz.

APPROACHING THE PROBLEM ABSTRACTLY

CONSIDERING THE PROBLEM IN TERMS OF SYNARIO

We will implement the FSM using ABEL-HDL rather than using a schematic.

IMPLEMENTATION

WRITING A TEST FIXTURE

Now we will write a test fixture corresponding to the cases outlined in the problem definition.

SIMULATION

Now we will simulate our design. Below are the waveforms corresponding to the first test case, where two quarters are inserted and there is sufficent change.

Here is a summary of what you see above:

Time t = 0: all signals undefined
t = 2: start signal asserted and all other signals set to 0
t = 12: the fsm patiently waits in the state of 0 coints having been inserted
t = 22: the first quarter's signal is asserted.
t = 32: our state now reflects 25 cents have been deposited. The second quarter's signal is now asserted.
t = 42: our state now reflects 50 cents have been deposited. The FSM has sufficient change for the purchase and so "dimeRelease" is asserted.
t = 52: our state now reflects 40 cents have been deposited. "nickelRelease" is now asserted.
t = 62: having reached exactly 35 cents have been deposited, unlatch and depositCoins are now asserted.
t = 72: our FSM sits patiently, awaiting another start signal. Note that any money inserted by customers is automatically refunded as long as the start signal has not been asserted.

Below are the waveforms for the second test case, where two quarters are inserted an insufficient change is availaible.

Here is a summary of what you see above:

Time t = 82: start signal is asserted. Note the only change we have availiable now is two nickels.
t = 92: our FSM sits patiently waiting for the first coin to be inserted.
t = 102: the first quarter's signal is asserted.
t = 112: our state now reflects 25 cents have been inserted. The second quarter's signal is now asserted.
t = 122: our state now reflects 50 cents. "refundMoney" is asserted since there is not enough change availiable to refund to the customer.

t = 132: our FSM has returned to its wait state.

DOWNLOAD THE PROJECT FILES