>> Good day, this is Jim Pytel from Columbia GorgeCommunity College.

This is digital electronics.

This lecture's entitledDesigning Synchronous Counters.

Okay, so in our previouslectures I've been giving you synchronous counters and we'vejust been performing an analysis of them.

And the question remains ishow do you actually make one of these things? So I mentioned previouslyit's kind an art form.

And what I'm intending thislecture to be is art school.

I'm going to give asystematic method to go ahead and design a synchronouscounter.

And we are going to beusing JK Flip Flops.

You can do the samething with D Flip Flops.

Takes a little bit more logicbut we're going to go ahead and use JK Flip Flopsfor these purposes.

When we created a 2 bit binaryup counter it was kind of one of those things where wecan see the transition.

In a state diagramfor a 2 bit binary up counter let's saywe're in state zero, zero, we're going upward out of 1, 2, 3, back to zero and so forth.

We can see that.

And we can visualize when doI want that MSB to change? Well it will togglewhen the LSB is 1.

Okay, if you think about thisyou can kind of see this, okay.

When do I want this toggle whenits previous state was high? What do I want this toggle likehere is 1, it's going to toggle to a zero when itsprevious state was high.

We can see that.

When do we want theLSB to toggle? Well all the timebecause I can see that.

It's, was a zero, goingto a 1, was a 1 going to a zero zero, 1 1 zero.

We can see that.

Not so easy all the time.

In our first example ofthis what we're going to do is design two bitgray code up counter.

First off start offwith a state diagram.

What is a two bit gray code upcounter state diagram look like? Chances are it lookssomething like this.

We are in state zerozero, go to zero 1.

We are in zero 1, we arein zero 1, go to 1 1.

Notice only 1 bitposition changes at a time.

That's the advantageof gray code.

And then let's countup, go to 1 0, count up, we recycled back to zero zero.

And we can do that samething with the truth table.

Present state, zero zero, goto zero 1, zero 1, go to 1 1.

And notice here I ampurposely not counting in gray code for the present.

I'm exhausting allbinary combinations.

So now what I'm doing, I'min 1 zero, where do I go? I go to zero zero.

I'm in 1 1, where do I go? One zero.

So again keep theorder for the present state in an exhaustivebinary combination.

And what I've kind of drawn hereis it's a synchronous counter that has a clock tied to it.

It's two stages obviouslybecause it's a 2 bit counter.

But what is the logic that wewant to put on those J&K inputs? And quite like our lastexample in an analysis of synchronous counters, those J's and K's don't haveto be tied together.

We're going to get independentlogical values for them.

How we do this isvery systematic means.

What we have to do isbasically start with an analysis of how a JK Flip Flop works.

If the present state is a zero and the next state istransitioning to a zero, i.

e.

it's saying thesame, what could we have on our inputs for J & K? Well put it in memorystate, zero zero.

Okay, if its memory, youknow, we're going to be good.

However, what ifI was to reset it.

Well if it's already a zeroresetting it doesn't change it also.

So I could also potentiallyreset it.

So it sounds like a K inputdoesn't matter, doesn't matter.

It's going to be an X, right.

Let's look at that next stage.

If the present stateof that input is a zero and at the next clockpulse it transitions to a 1, what do I want to do? Well maybe I want to set it.

How do I set something? One zero.

Well ifa zero transitions to a 1 I could also toggle it.

So how do I toggle something? I'm actually going to go aheadand put a 1 on the K input.

So it sounds like that again, that K input doesn't matter.

Now let's go ahead andconsider a third case.

If we are a 1 and wetransition to a zero.

Well maybe I want to reset it.

Well also what about toggling? What if I toggled it? That would also makeit go to a zero.

So I could also potentiallytoggle the thing.

So it sounds like theJ input doesn't matter.

Now let's take that finalconsideration 1 going to a 1.

Yep, that's a memorystate, definitely memory.

Is that the only thingthat could happen? No.

What if I also setsomething that was already set, i.

e.

put a 1 on the J? Sounds like the Jinput doesn't matter.

So what we've created here isa truth table that we can use when we reform theanalysis of this.

It's exactly whatI'm going to do.

I know in this case for designing synchronouscounters I know this state machine diagram.

Or from the requirements of thedevice I'm capable of figuring out the state machine diagram.

So I've got the presentstate and the next state.

What I have to do isfigure out the logic for the J & K Flip Flops.

Whereas previouswe had the analysis of synchronous counters.

The analysis of synchronouscounters we knew the present state, we knew the logicfor the J & K Flip Flops, we tried to figureout the next state.

So designing a synchronouscounters we've got that overarching generaldescription how we want the thing to behave or doing this, we are actually going to come up with the illogic forthe J & K Flip Flops.

This is how you do it.

You have the present state.

You have the next state.

Where do we get that from? We got it from thestate diagram.

Put them right nextto each other.

How many stages do you have? Well this is, excuse me, this is a [inaudible].

Its next state is dependentonly on its present state.

So there's no externalinput for this thing.

Anytime there's a clock pulseon this thing it's going to count in gray code.

I've got inputs forthe Q 1 stage and I've got inputsfor the Q zero stage.

And this is where ithelps to have like kind of those colored markers.

This is Q 1's present state.

It is transitioningto Q 1's next state where its inputs, it's these guys.

And do the same thingfor Q zero.

Okay, let's juststick a Q 1 right now.

Just divide these things upinto their own separate realms.

Okay, look at Q 1'spresent state.

It's presently a zero.

It's going to a zero.

Where are we on the truth table? Right there.

J could be a zero, Kcould be, don't care.

Okay, move on to the next one.

Q 1 is presently a zero.

It's moving to a zero, excuseme, it's moving to a 1.

Where are we? We're right herein our truth table.

So J could be 1, Kcould be, don't care.

Now move onto the third one.

We are a 1.

We're moving to a zero.

Where are we? Right here, okay.

So J could be don'tcare, K could be a 1.

Finally we are in aposition where Q 1 is a 1 and its next state for a 2 bit up gray code counter, it stays a 1.

So where are we onthe truth table? One is transition to a1, J, don't care, K zero.

What do we do with this stuff? Don't worry about it right now because we're only halfdone for the truth table.

We got to go ahead andfigure out for Q zero.

Because this is what I'msaying about using color codes or somehow organizing it.

Forget about Q 1.

Let's look at Q zero.

Q zero's present state is here.

It's transitioningto its next state on the positive clock edges.

What are its stages inputs? They're right there.

Look at it.

Was a zero, it's transitioningto a 1 right there, 1 X.

It was a 1, stayinga 1, where are we? Don't care, zero.

Next one, zero moving to a zeroright here on our truth table.

Zero X, not truth table, little cheat sheet.

Finally we are a1 going to a zero.

Should be don't care, 1.

So now what am I going todo with all these J 1, K 1, J zero, K zero inputs.

Well what I'm going to dois just to try to figure out the minimum SOPexpression for J 1.

The minimum SOP expression forK1, minimum SOP for J zero, minimum SOP for K zero.

How do I do that? Use the card on that.

So what I've got is fourpremade Karnaugh maps here.

And what I've got is Q 1 onthe left, Q zero on the right.

Again we've got 2bit input here.

If we add some externalinput we have to go ahead and count for that.

But in this caseit's a Moore machine.

It's next state ispresent only, excuse me, it's next state is onlydependent on its present state.

All you do is just take J 1, putin the, its appropriate K-map.

Come up with its[inaudible] SOP expression.

Do the same thing for K 1, do the same thing for J zero, do the same thing for K zero.

So let's go ahead andjust take the J 1 column.

Go ahead and putit in the K-map.

I see zero, 1, don'tcare, don't care.

What is the best expressionyou can come up with for J 1? Okay, what I see is rightthere, that's my best group.

Yes I could have justgrouped that upper 1 in the upper right hand corner.

However, if I'm makinguse of the don't cares, if they help me I'm not makinguse of them if they don't.

For example I would includedthis lower group of 2 because I've alreadyaccounted for that.

Okay, what is that? To me J 1's expressionlooks like it is Q zero.

So do the same thing for K 1.

What is K 1's populatedK-map look like? It looks like don'tcare, don't care, 1 zero.

Go ahead and find its group.

It looks like that so to me K1's expression should be not Q zero.

Now go ahead and populatethe K-map for J zero.

What we've got here is 1, don't care, zero, don't care.

What is its expression? We find that to bethe best group.

What is that representin the K-map? Looks like that, minimumSOP expression is not Q 1.

And we've come up with a minimumSOP expression for J zero.

Let's move on to K zero.

Take the K zero column, populate the K-map.

Don't care, zero, don't care, 1.

Go ahead and come up withthe best grouping for that.

What I find is is righthere, this group of 2.

Again I'm making use ofthose don't care situations if they help me.

I'm not making use ofthem if they don't.

That expression there is Q 1.

In a perfect worldwhat we've come up with here is the expressionsfor the individual J's and K's that will set, reset or stayat that particular stage at those positiveclock edges to go ahead and initiate a 2 bitgray code up counter.

The last step for all this.

The last step, check your work, go ahead and do an analysis of synchronous counter.

Implement the device, do theanalysis of synchronous counters and see if this thing reallydoes count up in gray code.

So let's go ahead andset it up for that.

So we've gone uphere is went ahead and implemented that device.

We're put that logicon those J and K's for their respective stages.

And again J 1 has Qzero, K 1 has not Q 1 and J zero has notQ 1, K zero has Q 1.

These are the resultantlogic that we came up with our designingportion of it.

We're going to goahead and check to see if this thing works.

How do we do an analysisof synchronous counters? What we do is wejust come up with J and K expressionsfor each stage.

Evaluate those inputs basedupon our present combination of inputs.

And then figure out the actions for those respectivestages, okay.

So what is J 1, K 1, values and actions givenpresent state zero, zero? Well J zero, excuse me, J 1 is always Q zero.

So I can go ahead andjust fill out that column.

What's K 1? What's not Q zero? So I can just say 1 zero 1 zero.

Our action, what is the actionbased off J 1 K 1 zero 1? It's reset, set, reset, set.

Go ahead and lookat the expressions for J zero and K zero.

J zero is not Q 1.

So I can just say 1 1zero zero, K zero's Q 1.

So what it's going to do isgoing to say zero zero 1 1.

What are the actionbased off those inputs? That is a set, a set, a reset, a reset.

Now what we're going to do isgo ahead and use those actions for those respectivecolumns and go ahead and figure out our next state.

And if everythingworks out correctly, you know what it should do? It should do this.

That is our 2 bitgray code up counter.

So what we're going to dois just check our work, do our logic work.

So this section heredeals with a transition of this present stateto this next state.

Okay, go ahead andso that analysis.

If it is a zero it'sbeing reset to a zero.

If it is a zero, it'sbeing set to a 1.

If it is a 1, it'sbeing reset to zero.

If it is a 1, it'sbeing set to a 1.

Go ahead and do that sameanalysis for the Q zero inputs.

Where are the Q zero inputs? Right there.

That action is affectingthis present state and it's changing itto that next state.

So if it was a zero, it's being set to a 1.

It was a 1, it'sbeing set to a 1.

If it was a zero, it'sbeing reset to a zero.

If it was a 1, it'sbeing reset to a zero.

Go ahead, does our resultantfinite state machine do what it's supposed to? Okay, our designimplements zero zero, it goes to zero 1, looking good.

It is zero 1, it goesto 1 1, looking good.

It is 1 zero, it'sgoing to zero zero.

That's that transition rightthere, we're looking good.

Finally our last state, 11 where's it go to next? One zero.

Oh my gosh, our design worked.

So systematic, again systematic, that's the way yougo ahead and do that.

Take the present state, compare it to the next and use that cheat sheet right here.

You have to know how thesethings work given a present state and you know its nextstate, go ahead and figure out those J & K inputs.

Again just take those individualJ & K inputs and put them into their own individualK-maps and come up with a minimum SOPexpressions for it.

So that was a Mooremachine example.

Again how was Moore machine? Its next state is onlydependent on its present state.

What if I had an externalinput that I wanted to go ahead and have different modes formy finite state [inaudible]? So let's go aheadand do an example of designing a synchronouscounter that is a Mealy machine which next state is dependentnot only on its present state but also some external input.

Okay, so our second example of designing synchronouscounters using JK Flip Flops is [inaudible] the example.

It's a finite statemachine external inputs.

And the student among you mayrealize that this state diagram which I've drawn righthere is the exact same one for the example thatended the analysis of synchronous counters.

So ideally what'sgoing to happen here is when we design this we shouldget a fully minimized SOP expressions for those J& K inputs for each stage which exactly matchesthe analysis of synchronous counters example.

Again look at thisstate diagram here.

What it represents isa zero zero start state when X is zero, it goes to 1 1.

So it's an external input.

When X is 1, it goes to zero 1.

So those are two choices.

There are two, excuse me, there's a single choice but there are two exits.

You either go X iszero 1 and you're going to go two different directions.

If it's zero it's going tokeep on going in this direction and keep on goingin that direction.

That zero zero isjust a feed in state.

Whereas if it was in 1, ifX was 1, we are at zero 1, 1 zero, 1 1, back to zero 1.

If at a time howeverwe switch modes, let's say for example we are instate zero 1, we are in mode 1.

We would go to 2 but themode suddenly switches to X equals zerowhere would we go? We'd go back to 1.

So using the state machinediagram, let's go ahead and figure out what ourpresent state of inputs are? And when I say inputs, again it's present state and the external input.

So there is how manyinputs here? So there's two stagesfor the present states.

Q 1 and Q zero andan external input.

So there's three inputs.

How many possible combinations? It sounds like there's eightpossible combinations for this.

And then just go ahead and basedoff of those present states and external inputsthere, go ahead and figure out what the next state is.

So what I've drawn hereis a bare truth table.

I'm setting you guysup for this already.

And this is again, this is kindof what I'm expecting you guys to have an understandingof this.

Is just, this is systematic.

And again this is art school.

I'm giving you the stepsto go ahead and do this.

What do we do every single time? Just look at the state diagram.

Here's out inputs.

We are in present state zerozero, we are in mode zero.

What's our next state? It sounds to me likewe'd moving to 1 1.

Okay, we are in present statezero 1, our mode is zero, X is zero, where do we go to? It's X state is also 1 1.

Okay, how am I doing this? I'm just looking fromthe state diagram.

Our first one we wentfrom zero zero to 1 1.

Now we are in zero 1.

We're going to 1 1.

Let's go ahead and if youcan, see if you can figure out the next state, i.

e.

the output for based off that state diagram see ifyou can go ahead and figure out the next Q 1and Q zero state.

So hopefully your next stateoutput looks the same as mine.

And again let's justpick an example here.

Okay, we are currentlyin present state 1 zero, however, we are in mode 1.

Where are we? We're right there.

We're in mode 1.

Where do we go to? One one.

Okay, so justreading that state diagram and putting it into this table.

All right now, what do we do? We divide these thingsup to each stages inputs.

J 1, K 1.

It is looking atthat one's present state and it's transitioningto this next state.

So it was a zero, it goes to a 1.

Where are we? It's right there.

So what we do is just fill outthese columns, 1, don't care, finally the, this nextone here, what is it? We are in a zero, we are going to a 1, so we're in the same spot.

One, don't care.

And let's go ahead and seeif you can compare each one of those present states of Q 1'sand the next states of Q 1's.

And use this truthtable which we've, the little cheat sheet truthtable there to go ahead and figure out for the J and K and hopefully yoursshould look like this.

Okay, so those areJ 1, K1 values.

Now just go ahead and whatare we going to do now is look at Q zero's present state.

It's transitioning toQ zero's next state.

What does it affect? What are its inputs, excuseme, it's J zero, K zero.

So it presently inzero, moving to a 1.

Where are we? It's 1, don't care.

Now we are 1 moving to a 1.

Where are we? Don't care, zero.

Go ahead and see if youcan fill out the rest of the J zero, K zero column.

And there we go, hopefully the J zero and K zero's look very similar.

Now what's our next step? We're going to go aheadand put J 1 into a K-map and develop the minimum SOPlogic expression for it.

Do the same thing for K 1.

Do the same thing for J zero.

Do the same thing for K zero.

And the key thing is is justonly do the expression for J 1.

Don't try to combine J 1with J zero or K 1, K zero.

So it's entirely separate.

So let's just look at J 1.

Just go ahead and try tofill out the K-map for J 1.

And if you need help withK-maps just go back and it's in the K-map lectures.

Should be prettyfamiliar to you.

It's 1 1, don't care, don't care, zero 1, notice the gray code there, don't care, don't care.

How do I develop theSOP expression for J 1? Again groups of 1, 2, 4, 8, 16, 32, so on and so forth.

Use the don't caresif they help you.

Don't use them if they don't.

So here's my firstgroup right there.

It's a group [inaudible].

That looks like that is Q zero.

My second group I'm going tograb a group of four also.

What is that? That looks like not X.

Somy final SOP expression for J 1 is Q zeroor not external.

Okay, and if you rememberright from our previous example of analysis synchronous countersthat's the original input I gave.

So we're tracking here.

Go ahead and see if youcan populate K 1 map, populate a J zero map andpopulate the K zero map.

Just do the populationright now.

So hopefully we'llstart off the same spot.

So there is the populationof those individual K-maps.

And let's look atK 1's expression.

So come up for the minimumSOP expression for K 1.

But I'm going togo ahead do those, I'm going to grab this groupof two right here and I'm going to grab this groupof two right there.

Okay, so the group inblue, what is that? That is not X and not Q zero.

What's the group in red? The group in red isQ zero and X.

Okay so the final SOP expressionfor K 1 is not X and not Q zero or Q zero and X.

Okay, J zero's expression.

J zero's expressionis pretty neat here.

Look at it.

Okay, we've got acolumn of 1's all the way down in the not Q zero column.

But look it, we've alsogot X's, i.

e.

don't cares in that Q zero column.

So what would you do? If it doesn't matterif it's a zero or a 1 for the Q zero column, just goahead and group the whole thing, okay it's a group of eight.

What is a group of eight? Basically it's alwaysgoing to be a 1.

Okay, so J zero isalways going to be a 1.

Let's go ahead andlook at Q zero.

What I'm going to do is finda group of two right there, another group of two there.

What do I get here? So this first one is going benot X, end Q 1 or X and not Q 1, excuse me, X and not Q 1.

So what we can do is takethe final SOP expressions for those J 1, J 1, J zero, K zero inputs for each stage.

And go ahead and implement it.

And what we came here with thisexactly what we had originally had in that, the endexample of the analysis of synchronous counters.

When we figured out thestate machine diagram for this one actually doesimplement with all what we're, what we've designed here.

So again I can always go back and check my work using whatI developed for the J zero, K zero, J 1, K 1 stages.

And go ahead and see how thisworks using that tabs or method for analysis of synchronouscounters.

So let's go ahead andclose up this lecture with a couple things that youmight be able to tackle here.

Just here's somesuggested exercise.

And I'm not going to giveyou the state diagram for these things whereaspreviously I had given you guys the state diagram.

I'm going to go ahead andhave you design it from there.

I'm actually just going to giveyou guys a verbal description of these things.

It says one of thosesteps here you've got to take this leaps of logic.

What does the state diagram for these two suggestedexercises look for? So for the first one herethink about a 2 bit binary or gray code up counter.

So it's got an externalmode, okay, that's called B, let's call it B slashnot G.

Okay so that's an external input.

When that B slash not G is1 it's counting in binary.

When B slash not G is in zero, its counter in 2 bit gray code.

So there is an external input inaddition to its present state.

How would it look inthe state diagram? And let's say it switches mode.

Okay so it was inbinary mode and it is in a certain present state.

And it suddenly switchesto gray mode.

Where would it go? Out, so you go to its nextgray code sequence based on that present input.

So this is pretty neat.

These conceptual exercisesactually visualize how these things work in a state machinediagram before you even do any of these techniques that we'vedone in this lecture here.

The next suggested exercise, this is a good one here.

See if you can design a 3bit odd even up counter.

So we've got oneinput, odd slash even.

So let's go ahead and sayit's an external input.

There's that external input.

That's making a decisionwhere it goes.

So let's go ahead and say whenit's in zero, go to even mode.

When it's in 1, go to odd mode.

And by the way so you don'thave to use this clunky notation for these external inputs, you can call it X or EX or E or whatever you want to do.

I just don't call it E forthat particular exercise.

Just come up withsomething memorable.

You don't have to usethis clunky notations.

But think about this 3bit odd even up counter.

If it's in odd mode, it'sgoing to obviously go to the next odd numberhighest in the sequence.

So for example 1 goes to3 goes to 5 and so on.

If it's in even mode, it's going to go from 2 to 4 to 6 and so on.

But what happens if it's ineven mode and an even number? Let's say 4 and it suddenlyswitches to odd mode prior to the next clock sequence, getting that clock edge.

What would it do? Well it would go up tothe next odd number.

So see if you can up withthe state machine diagrams for these things.

These are excellent exercisesto practice what we've learned in this lecture designsynchronous counters using JK Flip Flops.

Okay, let's go ahead and seeif we can in our next series of lectures here go ahead anddescribe some counters used in some different technology.

.