# Need help with designing simple vending machine

Discussion in 'Homework Help' started by Bogdann, Aug 9, 2012.

1. ### Bogdann Thread Starter New Member

Jul 31, 2012
5
1
Hello,

I have task where i need to design simple soda vending machine.
This machine accepts coins with value 5,10 and 15 and it doesn't give back change.

When the output is 1, it gives information what kind of coin entered in, table above:

Instead of OUT, it should be IN. A and B are outputs!

When the coin that makes the whole sum>20, output z1 gets activated and machine get coins back to customer.
When the sum=20 then output z2 is activated and customer get his soda can.
This should be realized with D-FF's and whatever logic gates are needed.

I have learned about state machines, moor and mealy machines and i have solved examples with sequences like for eg. when input sequence is 001 it gives 1 on the output.

I need guidance from where to start. I know i should have 2 functions as outputs, but i am not sure how many FF's should i have, i think 3 ?

2. ### WBahn Moderator

Mar 31, 2012
18,088
4,917
It's a bit hard to follow your description, but if I am understanding things you basically have:

A black-box soda machine that interfaces to the circuit you building as follows:

Three inputs to your circuit from the machine and two outputs from your circuit to the machine:

From the machine to your circuit:
OUT: Goes HI when a new coin is inserted (and presumably returns LO automatically after some suitable time period)
A,B: Provides information about the new coin. Only valid while OUT is HI.

From your circuit to the machine:
Z1: When HI, return all coins to user.
Z2: When HI, dispense soda (and keep coins).

There are some details missing, but I think you can make some reasonable assumptions to cover them. You can probably treat the OUT signal as a clock signal and you can probably hold your Z1 and Z2 outputs HI until the next time OUT goes HI.

To determine how many states are needed, ask yourself what information needs to be remembered regarding past events in order to know what to do about the current event?

In order to answer this, you have to understand clearly what "events" are possible, so what are they?

3. ### Bogdann Thread Starter New Member

Jul 31, 2012
5
1
Outputs should be like this:
Z1: When HI, return last coin that was inserted.
Z2: When HI, dispense soda (and keep coins).

Mainly I should just concentrate on the state machine.
Here are state diagrams, 2nd one is for this problem, it is just the coins are not codded. I assume i should code them as 5coins ->01; 10c ->10 etc... from table of 1st post.
http://postimage.org/image/5tbuiyajf/

4. ### WBahn Moderator

Mar 31, 2012
18,088
4,917
According to your diagram, if in State 0, the ONLY thing that can happen is someone can insert a 5 coin. Does that make sense?

You also have no way to leave states Z1 or Z2. Does that make sense?

So let's try again:

Q1) What information do you need to keep track of that tells you everything you need to know about past events?

Q2) What are the possible events that can happen while you are in a given state?

With those in mind, make sure that you have a table or diagram that clearly shows what happens in each state for each of the possible events.

5. ### WBahn Moderator

Mar 31, 2012
18,088
4,917
Are you sure Z1 just returns the last coin (your original post used plural, 'coins'). If you are only supposed to return the last coin, the machine gets a bit more complicated (but not too much).