Vending Machine Help

Thread Starter

smokingpotnonstop

Joined May 8, 2014
21
============================
STATE_0: No money has been put in.
============================

EVENT_Q: A quarter is put in.
OUTPUT: None
GOTO: STATE_25

EVENT_C: The cancel button is pressed.
OUTPUT: None
GOTO: STATE_0

EVENT_D: The dispense button is pressed
OUTPUT: None
GOTO: STATE_0

============================
STATE_25: One quarter has been put in.
============================

EVENT_Q: A quarter is put in.
OUTPUT: LED ON
GOTO: STATE_50

EVENT_C: The cancel button is pressed.
OUTPUT:LED OFF/Return Money
GOTO: STATE_0

EVENT_D: The dispense button is pressed
OUTPUT: Release soda/LED OFF
GOTO: STATE_0

============================
STATE_50: Two quarters have been put in.
============================

EVENT_Q: A quarter is put in.
OUTPUT: Return quarter
GOTO: STATE_50

EVENT_C: The cancel button is pressed.
OUTPUT: LED OFF/Return money
GOTO: STATE_0

EVENT_D: The dispense button is pressed
OUTPUT: Release soda/LED OFF
GOTO: STATE_0
 

WBahn

Joined Mar 31, 2012
26,398
Think about this. Someone puts in a quarter. They then press the dispense button. What will happen according to your table?

Remember, the events listed under each state occur one at a time. So only one of the three possible event occurs and then the system takes the appropriate action.

You're making progress.
 

Thread Starter

smokingpotnonstop

Joined May 8, 2014
21
============================
STATE_0: No money has been put in.
============================

EVENT_Q: A quarter is put in.
OUTPUT: None
GOTO: STATE_25

EVENT_C: The cancel button is pressed.
OUTPUT: None
GOTO: STATE_0

EVENT_D: The dispense button is pressed
OUTPUT: None
GOTO: STATE_0

============================
STATE_25: One quarter has been put in.
============================

EVENT_Q: A quarter is put in.
OUTPUT: LED ON
GOTO: STATE_50

EVENT_C: The cancel button is pressed.
OUTPUT: Return Money/LED OFF
GOTO: STATE_0

EVENT_D: The dispense button is pressed
OUTPUT: Return money/LED OFF
GOTO: STATE_0

============================
STATE_50: Two quarters have been put in.
============================

EVENT_Q: A quarter is put in.
OUTPUT: Return quarter/LED ON
GOTO: STATE_50

EVENT_C: The cancel button is pressed.
OUTPUT: Return money/LED OFF
GOTO: STATE_0

EVENT_D: The dispense button is pressed
OUTPUT: Release soda/LED OFF
GOTO: STATE_0

Does that mean, that the LED isn't part of the output? Or does it mean that there's a delay in which output 1 happens, then output 2 occurs within that one event?
 

WBahn

Joined Mar 31, 2012
26,398
Does that mean, that the LED isn't part of the output? Or does it mean that there's a delay in which output 1 happens, then output 2 occurs within that one event?
Now you are thinking critically about things. Good.

What you want to do is ask if an output need to be maintained after the event that it is associated with is over. If so, then it needs to be associated with a state and not an event.

In the case of the LED, what does that LED tell you? Does it just tell you that a second coin has been inserted (i.e., associated with an event), or does it tell you that two coins have been accepted (i.e., associated with a state)?

Here is where you might make some useful assumptions. For instance, you might assume that the change return and the dispense mechanisms are edge-triggered. If you make that assumption, what simplifications does it permit in your logic?
 

Thread Starter

smokingpotnonstop

Joined May 8, 2014
21
It tells you that two coins have been accepted, so it's assoicated with state. So does it allow the states to have the LED on? Also, I tired to draw a diagram, but I'm kinda lost.
 

Attachments

WBahn

Joined Mar 31, 2012
26,398
Sure. The state is represented by digital signals that can be inputs to the logic to drive the outputs.

Your diagram just has one input. You have three inputs (one for each type of event). Using the labels from the table, I'd call them Q, C, and D. Each arrow should have one of those three labels on it (it can be assumed -- but you should state this -- that the machine responds to the first event that happens). Outputs that are associated with a state should be written within the state's circle while outputs that are associated with an event should be written next to the corresponding arrow.
 

WBahn

Joined Mar 31, 2012
26,398
You're getting there.

Why do you have the "quarter" input as 011? Why assert the same signal that gets asserted when the "cancel" button is pressed? Dedicate one bit to each input. It will also make your diagram more readable if you use the labels Q, C, and D (or whatever meaningful labels you choose) instead of bit patterns.

I haven't looked closely at the machine itself yet; let's get the form of things in order first. But I do notice that after you dispense a soda your machine doesn't go to one of the defined states. What happens? Does it explode? Does it lock up? Does it start belly dancing? Is it a one-use-only machine? Remember, you are defining the behavior of this machine and it can only do what you tell it to do.
 

WBahn

Joined Mar 31, 2012
26,398
Much.

Now you just need to make sure that the behavior is defined for each input for each state. You could do this with a comment, but it is better (unless it clutters the diagram excessively) to do this explicitly. Your diagram doesn't say what should happen if someone presses the Soda button in the first two states.

Next you need to indicate your outputs as described earlier. Take your best shot at that and we will go from there.
 

Thread Starter

smokingpotnonstop

Joined May 8, 2014
21
Outputs = LED, Coin Release, Coin Bypass, Soda Release

The state table is wrong. I was just throwing in whatever. Ignore the L=000. I forgot to sctrach that out. That means 3 input and 4 outputs for a state table?
 

Attachments

WBahn

Joined Mar 31, 2012
26,398
Event Outputs = Soda Release, Coin Release, Coin Bypass?

State = LED
This could probably be make to work, but think about what happens with additional quarters after the second. In order for the state machine to bypass the quarter this way, it must first sense the quarter. But this probably means that it has been added to the two quarters that have been captured.

Wouldn't it be better to see if there is a state in which we want to bypass any coins that are put in just because we are in that particular state?
 

WBahn

Joined Mar 31, 2012
26,398
So it means that Soda Release is part of the state? Since it's only active when there's 2 quarters?
No. Just because someone puts in a second quarter does not mean that you release a soda -- they have to still push the soda button.

But once someone has put in a second quarter, do you need to know anything else to know that you want to bypass any further coins back to the change return?
 

WBahn

Joined Mar 31, 2012
26,398
Look at the original problem description. Look at the description of the four outputs. What will happen if you activate the coin release as soon as you enter the state that indicates that the person has inserted two quarters? Is that what you want to have happen? If not, what DO you want to have happen (i.e., what change in behavior do you want to see in the machine while in that state)?
 
Top