Okay so this is a question for school, I am not expecting someone to give me the full thought out answer, I just need someone to point me in the right direction as I am confused and my tutor is off on holiday.

Here is the question:

In this experiment you will be deriving a controller for a simple machine. The machine is very simple; it is a vending machine that can only accept £1 coins. It can dispense two different items, one costing 67 pence the other costing 52 pence. It has three outputs; one for 10 pence coins, one for 5 pence coins and one for 1 pence coins. Your machine must give change in the minimum number of coins depending on the item selected. The outputs are each a single signal such that if for example three 10 pence coins were needed in the change then the signal must be pulsed three times.

The problem I am having is that whenever I have made a state machine it has always relied on the inputs. So for example if we were going to do a vending machine then an item might cost 50p. So I make all my states go off what a user is putting into the machine, when a 10p goes in then I will go to state "10p" etc.

This example seems to just have 2 inputs (1 each for each item which both accept £1 coin) and then once the pound coin gets put in the machine just does it's thing without relying on the input again. This is seriously confusing me.

Never mind the getting the output the pulse for each coin output. I am seriously confused :(


1 Answer 1


There are two sides to this problem: the algorithmic and the engineering.


How do you determine the amount of each type of coins to give back as a change, such that the total amount of coins is minimized?

In this case, there is very simple algorithm: start by giving back the highest value coins. Once the remaining amount of change gets below the value of the highest value coins, start giving back the second highest. Keep this process until you gave back the whole amount of change required.


In the most general case of a vending machine, you would implement in HW the above algorithm. However, due to the simplifications provided in the problem's description you can do the following:

  • Calculate yourself the required change for each item
  • Implement a simple state machine which returns the amount of coins which you've just calculated based on the type of item bought.

The input to your state machine will be the type of the item.

There will be three outputs: one for each type of coin you can give back for change.

The purpose of the state machine is to assert the outputs some predefined number of times based on the input.

You do not necessarily have to latch the input - once you got the input, your state machine will transition to one of the two states corresponding to each type of item. From now on, you no longer need the input signal.

One possible implementation:

This implementation is one of the possible implementations, but not the only one.

You got just three coins types which you can use for the change. The amount of each coin type you need to give back to the buyer is determined by which kind of product did he buy.

You could use three different counters (one for each type of coins). Once you get the input from the buyer you load the initial amount of coins to each counter. While not all the counters are zeroed, on each clock cycle you assert the output corresponding to the one of non-zero counters and reduce the count of this particular counter by 1.

This is not the best approach in terms of gate count, but it will work.

  • \$\begingroup\$ Thanks a lot for your input, I am still a little bit confused though about how the actual state machine diagram would work. My tutor got back to me with the following information which doesn't explain it much more to me.. Don't forget that a state machine is synchronous; it has a clock signal. Effectively, on each rising edge of the clock you need to consider the current total in terms of money and then act accordingly. You just need to decide what coin to dispense each time you go round a loop. \$\endgroup\$
    – Shasam
    Aug 19, 2013 at 11:53
  • 1
    \$\begingroup\$ @lilSebastian, I added an example of possible behavior of the whole circuit. You can derive the state machine from it (hint: one initial IDLE state, and two operational states which are reached depending on the input). \$\endgroup\$
    – Vasiliy
    Aug 20, 2013 at 8:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.