Finite State Vending Machine Diagram

diagramsfinite-state machine

In class, we are asked to draw a finite state machine with the following instructions:

Design a finite state machine to model a vending machine that accepts
only quarters and gives a container of juice when 75 cents have been
deposited, followed by a button being pushed. If a fourth quarter is
deposited before the button has been pushed, this quarter is
immediately returned. If the button is pushed before three quarters
are deposited, nothing will happen. The machine is in state Si (i = 0;
1; 2; 3) when it has been given i quarters towards the next purchase.
Inputs to the machine are Q (inserting a quarter) and B (pushing a
button). After one request is processed, it is ready for another
request.

I'm not entirely sure what I'm doing is even remotely correct. For instance, I'm not sure how to represent the "return" or "dispense" actions, right now, the are represented as states, but I don't know if that is legally correct or not. I also don't know if my return Q4 is correct. There are no inputs on the lines connecting S4 to Return to S3, and I was hoping that that would mean that those happen automatically without input, is this correct?

Original:
Original

Improved:
Improved

Best Answer

Returning a quarter is not a state. It's an action. S4 should be removed. Also dispense is not a state. Those are your outputs. You can put them in states but that means ANY transition to that state causes that output. The real error here is that you can't leave a state for free just because there is only one choice. Transitions only happen because of input, unless you go non-deterministic.

An important distinction to make here is which type of finite state machine you're building. There are two types:

enter image description here

In Moore the states determine the output (S1, S2).
In Mealy the transitions determine the output (/0, /1).

Your 2nd diagram looks like it wants to be a hybrid. I advise you pick one kind and stick with it. A word of caution: if you choose Moore and move Dispense into the S0 state you're going to have a problem because people will be able to get juice without paying just by pushing the button.

Related Topic