Sequential Design of a Gumball Machine

A place to discuss the science of computers and programs, from algorithms to computability.

Formal proofs preferred.

Moderators: phlip, Larson, Moderators General, Prelates

Sequential Design of a Gumball Machine

Postby Geldhart » Fri Feb 10, 2012 2:51 am UTC

The Scenario
Gumballs cost 15 cents and the machine accepts nickels and dimes. The circuit needs to show when the Gumball Machine should dispense a gumball, and also when it should give back change.

My first attempt ended up in an extremely complex circuit that dispensed gumballs after 10 cents was put in.

I was able to simplify the circuit when I noticed I didn't use all of the don't care conditions in the k-maps to full advantage - no change still had 10 cent gumballs

I slept on it, and made it even more simple when I realized I only needed 1 input variable, not 2, making it an 8 entry truth table instead of 16.

Now my "gumball machine" will dispense gumballs after you put in 15 cents EXCEPT for the case of putting in 2 dimes, which is also the only time you have to deal with change.

Input
I = Input, 0 if you put in a nickel, 1 if you put in a Dime

Current State Q(t)
D = Is there a dime in the machine already (2 nickels = 1 dime)
N = Is there a nickel in the machine already

Next State Q(t+1)
Dn = Next state for the dime
Nn = Next state for the nickel

Outputs
C = Should change be given?
G = Should a gumball be released?

I'm using JK flip flops for this one, but the type of flip flop isn't specified.

Things are spaced a bit to make it easier to read. (I hope anyway)

Truth Table

I D N Dn Nn C G
0 0 1 0 1 0 0
0 0 1 1 0 0 0
0 1 0 1 1 0 0
0 1 1 0 0 0 1

1 0 0 1 0 0 0
1 0 1 1 1 0 0
1 1 0 0 0 1 1 (This is the problem child)
1 1 1 0 0 0 1

My previous table had entries like 010 00 01 but that was releasing the gumball after only ten cents. When I build the circuit based on this chart, the gumballs are releasing after 15 cents. That is, except for the 2 dimes case, and I'm not sure how to handle it - it's treating 1 dime in the machine as 20 cents providing a gumball and a nickel back.

I like figuring things out for myself, so hints are great.
Geldhart
 
Posts: 6
Joined: Thu Oct 20, 2011 10:23 pm UTC

Re: Sequential Design of a Gumball Machine

Postby mfb » Fri Feb 10, 2012 8:17 am UTC

I D N Dn Nn C G
0 0 1 0 1 0 0
0 0 1 1 0 0 0

I think that the first 1 in the upper line should be a 0.

0 1 0 1 1 0 0
You have a dime inside and give a nickel to the machine. Shouldn't that give a gumball?

1 1 1 0 0 0 1
0 1 1 0 0 0 1
And I doubt that these cases could happen.


What is wrong with the 20cent-issue?
mfb
 
Posts: 803
Joined: Thu Jan 08, 2009 7:48 pm UTC

Re: Sequential Design of a Gumball Machine

Postby freakish777 » Fri Feb 10, 2012 7:37 pm UTC

You're making this more complicated than it has to be.

Instead of doing what you're doing, just count the coins instead.

I can give you a bigger hint if necessary.
User avatar
freakish777
 
Posts: 330
Joined: Wed Jul 13, 2011 2:14 pm UTC

Re: Sequential Design of a Gumball Machine

Postby Geldhart » Sat Feb 11, 2012 3:25 am UTC

Thanks for the tips - the issue with the 2 dimes is that as soon as I put the first dime in, the machine was showing Change and Gumball. As for the cases that don't happen, it looks like that is what was needed to make the gumball appear when 15 cents are in the machine, otherwise it was issuing a gumball after only 10 cents.

As for counting the coins, I'm going to think about that one. I think I might know where I need to go for that one, I'll work it out over the weekend and see what I come up with.

Thanks all - especially for not spoiling the surprise.
Geldhart
 
Posts: 6
Joined: Thu Oct 20, 2011 10:23 pm UTC

Re: Sequential Design of a Gumball Machine

Postby Geldhart » Sat Feb 11, 2012 4:23 am UTC

Whooo Hoooo! And here it is, the working gumball machine.

Thanks for the tip on counting coins. Using two three bit shift registers to store the coins made it really easy to design the circuit. There are 5 ways to get a gumball (which reduced to four using an XOR gate). The hint was perfect - enough to get me on the right track, but vague enough that I still feel like I accomplished something.

N & N & N
D (XOR) N
D & D (which gives change)
N & N & D (which also gives change, but only if put in that order)

I created the circuit at home using Logisim, should be easy to draw it up in Logic Works since that is the program we use in the lab, and the version he wants submitted. Hopefully this image appears. . .

This Gumball machine works.png
The working gumball machine....
This Gumball machine works.png (7.44 KiB) Viewed 1618 times
Geldhart
 
Posts: 6
Joined: Thu Oct 20, 2011 10:23 pm UTC

Re: Sequential Design of a Gumball Machine

Postby Geldhart » Sat Feb 11, 2012 4:27 am UTC

And yes, I do plan to neaten up the drawing a bit before turning it in.

If I have time, I may see if I can make the circuit even simpler.
Geldhart
 
Posts: 6
Joined: Thu Oct 20, 2011 10:23 pm UTC

Re: Sequential Design of a Gumball Machine

Postby freakish777 » Mon Feb 13, 2012 2:28 pm UTC

What would happen if you had one coin register instead of two? And counted Nickel as 001, and Dime as 010?
User avatar
freakish777
 
Posts: 330
Joined: Wed Jul 13, 2011 2:14 pm UTC


Return to Computer Science

Who is online

Users browsing this forum: No registered users and 3 guests