today we're going to focus on the operation of the JK flip-flop circuit so let's begin by drawing a circuit what we're going to do first is we're going to draw the SR latch circuit and then build the JK flip-flop circuit around that now you could design the SR latch circuit using two nor Gates or two nand gates for this particular video I'm going to use two nand Gates now the input of the top name gate is going to become where it's going to be attached to the output of the other nand gate and the input of the bottom negate is going to be connected to the output of the other nand gate so that's the SR latch circuit now to build a JK flip-flop circuit we're going to add two three input nand Gates to the circuit we'll call this input J and this input k now there's three inputs to those two nand gates on the left one of those inputs will be connected to each other we'll call this the clock input the third input is going to be connected to the output of the other nine gate so we're going to attach this input all the way to the output of the bottom nand gate and this input here we're going to connect that to the input the output of the top name gate so that's how you can draw the circuit for the JK flip flop now let's call the output of the first negate s and we'll call this r and the final output we'll call Q and the other one Q Bar now let's review the truth table for nand gate if you recall the truth table 4 and and gate well first let me fill out the values of A and B for an and gate the output is 1 only if both A and B are on for the nand gate is to reverse the output is only zero when both A and B are on the on State so this is the truth table four a two input nand gate now we can construct a truth table for a three input nand gate but here's what you need to know the output is always going to be a one unless both inputs are 1. if both inputs are one the output will be zero so for three input nand gate all the inputs have to be one in order for the output to be zero so in order for us to get a zero for s all three inputs must be a one if one of them is a zero then the output is going to be a zero here's the formula for the output of a three input net gate let's use S and the three inputs a b and c so s is going to be a times B times C but it's the complement of that so if we have 1 0 1 times 0 times 1 that's going to be zero the complement of zero is one so the only way we're going to get a zero here is if all three of these are one using that formula will be one times one times one which is one the complement of one is zero so keep that in mind as we discuss the operation of this circuit we're only going to get an output of zero if all the inputs are one now one of the first things we need to do before we discuss the operation of this circuit is decide what values q and Q Bar should be we can make Q equal to zero or we can make it equal to one so what I'm going to do what I like to do is set Q to zero as our starting values so what we're going to do is imagine if there's a push button for the J K and clock signal we're going to push the clock button and we're going to press k when we put an input of 1 to K it's going to set it's going to reset Q to zero if we were to press the J button it'll set Q to 1. if there's an active clock input so that's what we're going to do right now we're going to have an active clock input and then we're going to press the K button that's going to set Q to zero and Q Bar to one so that's going to be our starting values now what we're going to do is we're going to create a truth table for this circuit so let's see if I can fit that here we'll have our inputs J and K and then the inputs for the latch circuit SNR and then the values of Q and Q Bar and then a description for the output now the first thing we need to consider is what happens when we don't have an active clock signal or if the input at the clock is zero if the input is zero right now Q is zero and Q Bar is one but if the input is zero it doesn't matter what the values of J and K will be the output of the three input nand Gates the values of S and R will be one and let's talk about that so we're going to have a zero here and a zero error now Q is zero so this input at the K nand gate will be zero Q Bar is one so the input for the Top Line gate will be one here now if J is zero zero times zero times one is zero the complement of zero is One S is going to be one or if J is one one times one times zero is still zero the complement of zero is one so it doesn't matter what J is s is going to be 1.
the same is true for K if K is zero R is going to be 1. 0 times 0 times 0 is 0 complement of zero is one or if K is one R is still going to be one remember the only time s or R will be zero is if all three inputs are one if this is just a single zero there we're not going to get a one at s or R if there's a single zero it's the output is going to be one the only way we're going to turn this into a zero is if all inputs are one so hopefully I didn't confuse you with that so remember the only way s is going to be a zero is if we have a one a one and a one if there's a single zero S and R will be one so if the clock is zero doesn't matter what J and K will be S and R is one now what happens when s and r is 1. in this case when SNR has these values the output is not going to change Q is zero so that follows the input here this is zero Q Bar is one so that follows the input there a zero and a one will give an output of one which is the same as Q Bar so it's not going to change Q Bar and for net a 2.
5 gate with the two inputs are one the output will be zero which will not change Q because Q is already zero now let's see what would happen if Q had different values when S and R are both one but this way so let's say Q is 1 and Q Bar is zero when S and R is one it's not going to change the values of Q whatever the values of Q are it's going to remain the same when S and R is 1. so here Q is one so that means this input is going to be a one a one and a one one times one is one complement of one is zero so this becomes zero here zero times one is zero complement of zero is one so Q doesn't change nor does Q Bar change so when S and R are both one whatever Q and Q Bar whatever the values they have at that instant they will remain at those values so we can say that there's no change or the circuit is in a state of memory so what this means is that when we don't have an active clock signal the output is not going to change whatever the values of Q and Q Bar at that instant it's going to remain at those values regardless if you press j or k so the output can only change with an active clock signal or an active clock input now we're going to apply an active clock input but we're not going to press the j or k buttons what's going to happen in this case well remember s will be one if any of the three inputs are zero so because J is zero s is going to be one and because K is zero R is going to be one so if J and K are zero S and R will remain one and when S and R are both one the output is not going to change the circuit will still remain in a state of memory so there's going to be no change now what happens when we press J with an active clock input what you need to know is that when you press the J button you're going to set Q to 1. now let's prove that so right now we have a one at the clock input J is 1.
K is zero Q is zero so that means this input is going to be zero Q Bar is one so the top input will be 1. now we have a zero here so R is going to stay in one now we have three ones at the top nand gate three ones will change S to zero so now the output is going to change so Q is zero that means this input will be zero a zero and a one is going to give us an output of 1. so this is one a zero and one will give us an output of one so Q has now changed from zero to one now that Q is 1 is going to change this input the one it's going to follow here so this is no longer a zero two ones will make it zero so that's going to change Q Bar to zero and of course that will change this input but two zeros will make a one and after that there's going to be no more changes there so Q is now 1 Q Bar we have to change that that is now zero as you can see here s is now zero R is one so when we press the J button the result is that we set Q to 1.
now here's a question for you at this point what happens if we release the J button and then press the J button again with an active clock input so first let's release the J button so J is going to go from 1 to 0. right now because Q change the inputs will change so Q is one this one is going to go here so it's no longer zero at this input but we now have a one Q Bar is zero so that's going to change this one to a zero now when Q goes to 1 notice what happens when Q goes to one that means that this nand gate is waiting to be activated it's now active but it's waiting for K to be pressed Q Bar went to zero so this input is zero this nand gate is inactive because now it doesn't matter if J is 0 or 1. s is going to be a one now remember the only way we can get S and R to a zero is if we have three ones at the input so because Q Bar is zero and now this is zero this nand gate has been inactivated which means s is locked into one so if you release J to zero s is still going to be one if you press J to 1 s is still going to be one right now we haven't pressed k k is waiting to be pressed so because K is 0 R is 1.
so notice what's happening here whether we press J to 1 or release J to zero s is locked into one so both S and R are one and when that happens there's no change in the output so the first time we press J we set Q to 1. if we release it Q is going to remain at 1. if we press J again Q stays at 1.
so once you press it the first time if you release press release press is not going to change the output the output is now locked into the state so since we can't do anything with J after we press it the first time since it's no longer going to change the output if we press in a second or third time the only thing that's left to do right now is to press k so with an active clock input we're going to release J to zero and we're going to press the K button so J is now 0 K is 1. so right now s is locked into one since Q Bar is zero now once we press K we when Q is 1 we have three ones at the input that's going to change R to zero so s is one R is zero now that the values of S and R have changed the output will change so at this instant Q is initially 1. so we have a one and a zero that will give us an output of one so that's going to change Q Bar to one okay let's just get rid of the values here so I have to write this twice so now that Q Bar is one the input at the top nand gate will be one and two ones one times one is one complement of that is zero that's going to change Q to zero and when Q goes to zero this input will be zero and two zeros will give an output of one which Q Bar is already one so when we press the K button we reset Q back to zero so Q is zero Q Bar is one now what happens after we press the K button once what happens if we release the K button and then press it again now that q and Q Bar have changed the K nand gate is inactive the J nand gate will be active so if we release K and then press press K again it's not going to change the output because Q is now resetted back to zero this input will be zero and that's going to deactivate the bottom nand gate Q Bar is one so now the top nand gate or the chain and gate is now active and waiting to be pressed so now that Q is 0 and the K9 gate has been deactivated if we release K to zero R is still going to be 1.
remember R will only be zero if we have three ones here so because Q is zero we can't have three ones anymore so R is going to be one regardless if we release K to zero or if we press K to one so remember this when Q is 0 the K nand gate is deactivated which means if you press or release K even if there's an active clock input the output is not going to change when Q is 0. pressing and releasing K will not affect the output and when Q is 0 because the K nand gate is deactivated that means that the J nand gate will be activated because Q Bar is one so the J nand gate is waiting to be pressed and that's going to change the output of the circuit when Q Bar is zero the jnand gate will be deactivated which means if you try to press J or release date it will now change the output and when Q Bar is zero the K nand gate is activated so it's waiting for K to be pressed once you press K it'll change the output so make sure you understand that when you press k after you press it the first time the K-9 gate is deactivated the j9 gate is activated with to be pressed the output will only change once you press J after you press J the first time if you press again the output won't change once you press J the chain and gate will be deactivated but it's going to reactivate the canine gate the waiting for K to be pressed and it's constantly going to flip flop so when you press J once the output changes you press it again it doesn't change the output is only going to change when you press k if you press k a second time the output is not going to change it's only going to change when you press straight and it's constantly going to go back and forth like that now I know I did a lot of talking but I want to make sure I can simplify this so that you understand it well when you press J the first time you set Q to 1. if you press it a second time the output is not going to change J is deactivated the only thing you can do at this point is press K with an active clock input once you press K you reset Q back to zero and after you press K the first time the K navigate is now deactivated if you press k a second time the output is not going to change all you could do now is press J when you press J Q goes back to one if you press j a second time or release it then press it again Q is not going to change J is now deactivated K is activated weight is we press you press k q goes back to zero press K again Q space at zero until you press J which makes Q go back to one so that's the that's how this JK flip flop works it only switches State when you press j or k once pressing a second time will not change the state you have to press the other button with an active clock input so now that we've considered All That what's going to happen if we press J and K at the same time with an active clock input so right now we've pressed K we're going to hold on to K with the current circuit conditions and then we are going to press J so what's gonna happen at this instant in time Q is 0 and Q Bar is one so we have a one at J and a one at K which is already there feel free to pause the video and think about what's going to happen here so because K is deactivated because Q is zero R is going to be one Q Bar is one so the S I mean the Janine gate is activated because we have three ones at the input s is going to be zero now for you to understand what's happening I'm going to make another table with q and Q Bar right now Q is 0 and Q Bar is one when s becomes zero we have a zero and a one that's going to make the output 1.
so Q is going to change to 1. so Q is no longer zero now this is going to change here so this is going to become a one and that is going to make Q Bar 0. now that q and Q Bar have changed values the Janine gate is going to be deactivated and the canine gate is going to be activated so the inputs at J and K or those two nand gates will change so Q is one so this zero is going to become one now and Q Bar is zero so this input here is now zero so that's going to affect the values of r and s the k90 is activated and we got three ones that's going to change r to zero and S is going to change to 1.
because it's now deactivated with this zero here now because S and R changes that's going to change the value of Q and Q Bar so at this instant when Q is 1 and R is zero that's going to make Q Bar one and now here Q Bar is one s is one that's going to make Q zero now let's do this one more time so now that Q is zero it's going to deactivate the canine gate so this changes to zero Q Bar is now one so that's going to reactivate the j9 gate this turns to one these three ones will make s is zero and because we have a zero here R is going to be one and this is going to once again change q and Q Bar so Q is initially zero so we'll change this to zero zero and one will make a one so Q Bar is one s is zero that's going to change Q to 1. and now when Q is one this input changes one and one will make Q Bar 0. and this cycle is gonna keep repeating itself so Q is going to change from 0 to 1 0 to 1 and it's going to keep doing that Q Bar is going to remain the complement of Q so it's going to go from one to zero one to zero so I'm just going to call this q and I'm going to all this Q Bar so they're constantly going to alternate but to be more specific when s is 0 and R is 1 we see that Q is one and Q Bar is zero which matches what we see here and in the previous condition we saw that when s is one and R is zero Q is going to be 0 and Q Bar is going to be 1.
now how do we describe this What's Happening Here for the output the description here is toggle toggle means a switch in action so right now that we say that the circuit is toggling like Q is toggling back and forth between 0 and 1. and Q Bar is always going to be the complement of Q and these two are just toggling switching States going back and forth so I'm going to put a line here so with an active clock input and when J and K are one s is going to toggle between one and zero R is going to toggle between 0 and 1 Q is going to toggle between 0 1 and Q Bar is going to toggle between 1 and 0. so the values of s are q and Q Bar they're constantly switching States when s and r when it's 1 0 Q Bar will be Q will be zero Q Bar will be 1.