enter image description hereI can not solve this exercise. I really need help.

Design a coffee vending machine with the following specifications:

  1. Each coffee costs 15 c. The only output from the state machine, Y, changes from '0' to '1' when 15 c or greater has already been entered.
  2. Accepts coins of 5c or 10c (cents), and does not give change (that is, 2 coins of 10c are accepted and correctly processed). Thus, the state machine has two inputs, I5 and I10.
  3. After "delivering" a coffee, the state machine restarts (the transition will depend on whether or not new currency is being introduced).
  4. Two or more coins are not accepted simultaneously (the machine only has one slot).

A. Draw the diagram and the state transition table of the machine.

B. Perform state machine with flip-flops D, using the standard technique in state coding (i.e. states are encoded directly to binary, and associated with flip flops outputs). Draw the logic circuit.

C. Perform state machine with flip flops D, using the 1-hot technique in state coding. Draw the logic circuit.


closed as unclear what you're asking by pipe, uint128_t, R Drast, ThreePhaseEel, Wesley Lee Mar 20 '17 at 7:09

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 7
    \$\begingroup\$ This is clearly a homework problem. What have you tried so far, and what point are you stuck on? \$\endgroup\$ – Dave Tweed Mar 19 '17 at 14:09
  • \$\begingroup\$ @DaveTweed I tried to draw the state machine, but I do not know if I'm doing well and I don't know how to restart the machine, like "finishing the cycle". \$\endgroup\$ – Carmen González Mar 19 '17 at 14:13
  • \$\begingroup\$ exactly. Show us what you've got so far. It's much, much easier to help someone with a non-perfect approach then to give a complete lesson on state machines. \$\endgroup\$ – Marcus Müller Mar 19 '17 at 14:13
  • \$\begingroup\$ What you have in the diagram is a Moore state machine. Have you also learned about Mealy state machines? You might find that helpful... \$\endgroup\$ – Radian Mar 19 '17 at 14:43
  • \$\begingroup\$ @Radian We only learn Moore's machines and the teacher wants us to do this with a Moore machine. \$\endgroup\$ – Carmen González Mar 19 '17 at 14:50

The problem statement is somewhat ambiguous, but given that the suggested technology is D FFs, I think we can assume that we're talking about a synchronous state machine with a clock, and that the I5 and I10 inputs are pulses that are 1 clock wide. We are told that both inputs can't be active at the same time.

Therefore, the basic conceptual state machine just needs to keep track of how much money we've received so far, until it reaches enough to pay for a coffee:

     V                                              |
+------+      +------+      +------+      +------+  |
| idle | I5   |  5c  | I5   | 10c  | I5   | 15c  |  |
|  Y=0 |----->|  Y=0 |----->|  Y=0 |----->|  Y=1 |--+
+------+      +------+      +------+      +------+
  I10|          I10|         ^ I10|         ^ ^
     +-----------------------+    +---------+ |
                   |                          |

Note that since we aren't required to make change, the 15c state really means "15 or 20 cents received", either of which is enough to dispense a coffee. But giving change when we receive 20 cents just requires one more state (and one more output).

Implementing this abstract Moore state machine as either binary-coded D FFs or one-hot D FFs is left as an exercise for the reader.

EDIT: You seem to be making an earnest effort, so here's the next step of the analysis. I don't understand your notation for the state transition table, so I'll draw it the way I would approach it, where each line of this table corresponds to one transition in the diagram, with the "null" transitions (both inputs = 0) made explicit.

Current    Inputs     Next
 State    I5   I10    State
------   ---   ---   ------
 idle     0     0     idle
 idle     1     0      5c
 idle     0     1     10c
  5c      0     0      5c
  5c      1     0     10c
  5c      0     1     15c
 10c      0     0     10c
 10c      1     0     15c
 10c      0     1     15c
 15c      x     x     idle

Note that I'm still using abstract names for the states; whether these map to binary values or one-hot encoding is still up to you. Once you pick the mapping, the actual logic required to produce the actual D input values for each FF should fall directly out of the process.

EDIT #2: OK, taking into account the parenthetical comments on Specifications 2 and 3, it seems we need to keep track of overpayments and additional coins being introduced even while the coffee is being dispensed. Therefore the state diagram and transition table need to be modified:

                 |             +------------------------------+     |
     +-----------|-------------|--------------------+         |     |
     |           | +-----------|---------------+    |I5=0     |     |I5=0
     |           | |           | +----------+  |    |& I10=0  |     |& I10=0
     V           V V           V V       I10|  |I5  |       I5|     |
+------+      +------+      +------+      +------+  |     +------+  |
| idle | I5   |  5c  | I5   | 10c  | I5   | 15c  |--+  I10| 20c  |--+
|  Y=0 |----->|  Y=0 |----->|  Y=0 |----->|  Y=1 |<-------|  Y=1 |
+------+      +------+      +------+      +------+        +------+
  I10|          I10|         ^ I10|           ^             ^
     +-------------|---------+    +-----------|-------------+

Now, the machine will correctly dispense two coffees if you put three 10-cent coins into it. And now there are no unlabeled (unconditional) transitions.

Current    Inputs     Next
 State    I5   I10    State
------   ---   ---   ------
 idle     0     0     idle
 idle     1     0      5c
 idle     0     1     10c
  5c      0     0      5c
  5c      1     0     10c
  5c      0     1     15c
 10c      0     0     10c
 10c      1     0     15c
 10c      0     1     20c
 15c      0     0     idle
 15c      1     0      5c
 15c      0     1     10c
 20c      0     0      5c
 20c      1     0     10c
 20c      0     1     15c

FINAL EDIT (hopefully):

The output is only a function of the state, so calculating the output logic uses a different K-map from the one you use to calculate the transitions. The state assignment for the simpler 4-state machine might look like this:

State       Q1  Q0   Y
-----       --  --   -
 idle        0   0   0
  5c         0   1   0
 10c         1   0   0
 15c         1   1   1

Obviously, Y is simply Q0 AND Q1.

  • \$\begingroup\$ Thank you so much! I have attached an image to the post with the indication that you gave me. Could you confirm that the state diagram is correct this time? I'll try to make the states table and the circuit and then I'll post. I wish you'd tell me later if I did okay. \$\endgroup\$ – Carmen González Mar 19 '17 at 17:57
  • \$\begingroup\$ I did not realize why it is that when you get to state 15c puts an arrow that goes back to the iddle state, but without any caption at the top of the arrow. After having the money to drink a coffee if a 5-cent coin were introduced, should not there be an arrow linking 15c to 5c and having a caption I5? And another that united 15c to 10c and had I10 legend? \$\endgroup\$ – Carmen González Mar 19 '17 at 18:06
  • 1
    \$\begingroup\$ No. A single unlabeled transition out of a state simply means that the transition is unconditional, and that you only stay in that state for one clock cycle. When you get to the 15c state, you essentially pulse the Y output for one clock cycle to dispense the coffee and then go back to the idle state to wait for any additional coins from the next customer. \$\endgroup\$ – Dave Tweed Mar 19 '17 at 18:11
  • \$\begingroup\$ And what do I put in the state table in that case? Usually I make a state table where I put the current states in binary code and fill in the following states in binary code as well, but I separate case I5 and I10 according to the transition they make. How do I make the 15 c case since it is unconditional? \$\endgroup\$ – Carmen González Mar 19 '17 at 18:15
  • 1
    \$\begingroup\$ You put "don't cares" in the input columns for that transition. \$\endgroup\$ – Dave Tweed Mar 19 '17 at 18:16

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