in a previous video we looked at the JK
flip-flop and saw how it works similarly
to the SR flip-flop except that it has
this feedback so that if both inputs are
1 then on the rising clock the output
toggles rather than going into a sort of
undefined state in this video I want to
actually build this and and take a look
at how this works in practice
so here I've built the JK flip-flop
following this the circuit diagram here
and I wanted to kind of walk through a
couple things one thing I noticed though
when I was building it was I in diagram
here I got a couple things here I got
one thing wrong which is that this is
actually the K input and this is the J
input because J corresponds to setting
so when this goes high we want to see
the Q output go high and then when this
input goes high Dan the Q output should
go low so k reset so I just had that
labeled wrong but otherwise everything
is fine so what had built this and I'm
using the 74 LS 0 to 4 the nor gates so
on the top side of the chip I'm using
the 2 nor gates there and then this trip
over here is the 74 LS 11 which is a
triple 3-input and gate so I'm using
these two and gates that have three
inputs each in this if for these an gate
here they hook up power here it should
go into some state or other so it looks
like this is the Q output that's just on
and then I can also connect my clock
over here and I've got a clock circuit
over here and
basically what's going on here these two
switches are tied to ground through
these pulldown resistors and then when
you push the button it goes high so both
of these are connected via these green
wires to the two and gates so that
they're the K and the J inputs also
going into the en gates is our clock and
so the clock comes in here and it's
going through this RC circuit so there's
a capacitor here which is a point zero
zero one micro farad capacitor and then
a resistor here which is a 1000 ohm
resistor and then the output of that
goes into these two white wires which go
into another input on both of those an
gates and then the outputs of those and
gates are these blue wires to go to two
of the inputs on two of the nor gates
over here the other inputs of those nor
gates come from the outputs instead of
there these two yellow wires here and
then also the outputs of these go back
around the N gates which are these
yellow wires that go back over here to
the end gates and then also the output
so these or gates go to these two LEDs
this is our Q and this is our Q
complement so if we push the K input now
if we send that hi then that should
reset the latch and Q should go off and
indeed it does and if we push the J that
should set it and Q should go on and
indeed it does and you see it goes on
with with the clock so it's not
immediate when I push the button it
happens on the next clock signal because
this is gated on this clock rising edge
so now because this is a JK flip-flop if
we put both inputs J and K hi we should
see this toggle and it's not toggling
but sometimes it does and if I hold it
it just the right angle or poke at it up
there it toggled now it's occasionally
toggling
make sure I'm pushing both of these
buttons yeah sometimes it toggles on or
toggled a couple times what I'm finding
is that the circuit is is pretty
inconsistent so I'm going to do is
rather than try to push those buttons I
put a little jumper in here across that
button and then another jumper here
across this button that's the same as
you know inputting a one for both J and
K so this should be toggling right now
each time the clock rising edge goes and
you see up now it's sometimes toggling
now it's toggling again now it's
actually working pretty well but it's
definitely very inconsistent and it
turns out there's there's a good reason
why it's behaving inconsistently Herrick
just stopped then now it's started again
there's a very good reason that it's
behaving and consistently and in order
to understand what's going on here
really the only way to really see what's
happening is to use an oscilloscope to
take a look at the signals in here so I
start by just looking at the clock input
just so we have a reference of what that
looks like and so here it is this is our
our clock you can see it's going on and
off and it looks like it's about twice
per second each of these divisions here
is 100 milliseconds so over 10 divisions
it's pulsing twice so twice per second
and the next thing I want to look at is
the output because this is what we want
to see toggling you know with each clock
pulse you can see our clock is pulsing
here again it you know twice per second
so each of these pulses we would expect
to see we would expect to see our output
toggling and right now it's not toggling
although
yes I kind of hold my hand at the right
place I don't know it's kind of kind of
flaky but sometimes the toggles so I'm
gonna look at the output here and see
what that looks like and here's our
output and it looks like it is actually
doing something up and there you can see
it actually toggled and now it's high
okay so it is it's kind of inconsistent
and there at toggled again so when it is
toggling it toggling at these o'clock
rising edges which is what we want but
where it gets interesting is if we zoom
in alright so we zoom in and look at
that rising edge of the clock you see
there is something going on here and if
we zoom in even more what you see is
pretty interesting which is when that
clock goes high the output does in fact
toggle but it toggles back and forth a
bunch of times before then settling
somewhere and that's actually why this
is behaving so inconsistently is because
it is toggling which is what we want
right when that clock goes high but it's
toggling again shortly thereafter and if
we look at this you can see the period
here is 80 about 84-82 nanoseconds so
every 82 nanoseconds here this is
toggling on and off that actually makes
some sense if you look back at the
circuit diagram here because what's
happening is this pulses is coming in
and the output of toggling but as soon
as it toggles that feedback goes back
around to the input and it toggles again
it's you know because this this clock
pulse even though we're trying to look
at the the leading edge of the clock is
this pulse so the clock of course is you
know
for 250 milliseconds is on for quite
some time but this pulse should you just
be looking at just that very first
instant when it turns on but if this
pulse is too wide then and the output
switches before this pulse goes back to
zero
then it will switch again and will
switch again it will switch again and
this is a phenomenon called racing and
that's exactly what's happening here is
when this pulse goes high its switching
on but then it's immediately switching
off and on and off and on and if I get
this where it's toggling you see
sometimes it does toggle but it's
totally luck of the draw because it
switches on and off and on and off and
on and off and then eventually gets to
here and it's settled into whichever
state happens to be in and so sometimes
we get kind of lucky sometimes and a
toggles but not always and the reason
for that is this RC circuit now I
mentioned before that the capacitor I'm
using is a point zero zero one micro
farad capacitor and the resistor is a
1000 ohm resistor and so if you multiply
those together you get the time constant
of this RC circuit which is effectively
gives you some indication of the width
of this pulse and in this case this time
constant is going to be I think it's a
100 micro second so we can actually
measure it so let me look at the clock
or the pulse input here for the circuit
and put that here on channel 2 and here
you see that pulse and so if we beam out
it looks great right the you know this
is this is kind of what we're looking
for right when the clock is high this
pulse just quickly pulses the problem is
that that pulse is not is not quick
enough
and so you can see here oh it's one
microsecond so one microsecond pulse and
for that one microsecond we get this on
and off and on and off and then finally
that gets back down to this area here
where it's considered a zero and then it
finally settles down so what can we do
about this one a couple things we can do
one is we can try to make this pulse
shorter so right now this is one
microsecond you know we saw that we zoom
in here measuring a period here of this
on and off it's 80 nanoseconds you know
we can try to get this pulse down so if
we you know we can get it to 100
nanoseconds pretty easily if we go from
a 1000 ohm resistor to 100 ohm resistor
so only try to swap that out this is the
resistor here so way and put the 100 ohm
resistor in and so here you see okay we
have a much smaller pulse but it's still
not quite working and you know we're
frankly getting into the limits of what
we can do on a breadboard you know these
this kind of high-speed you know tens of
nanoseconds type types of stuff you know
these breadboards really really aren't
made for that because you know within
this breadboard you have all sorts of
stray capacitances and and inductance
and all sorts of stuff and that's why
you know just me kind of waiting my
hands over at one where who is changing
the behavior of it just now you see it
went low
yeah so it now looks like it's going
high then low and staying low but I bet
if I stick my hand in just the right
place I can maybe get this to toggle
yeah
I'm not changing any I'm just kind of
moving my hand around and it's just
because my hand is changing the
capacitance because I'm grounded yeah
and you can see there it's now it's
toggling but now stop hogging so really
we're getting into and you can even see
you know this this rising edge of our
clock is not you know on this timescale
it's not a real sharp rising edge and
again that's just because you know the
breadboard does limit to what we can do
this pulse
we're not detecting a nice clean we're
not we're not generate a nice clean
pulse like we were when we have the
larger resistor in there and again it
all comes down to you know we're really
pushing the limits of what we can do on
a breadboard you know in general this
this particular way of detecting the
rising edge by using an RC circuit like
this is is pretty fraught in in a JK
flip-flop like this because of this
racing condition you have this you have
this racing where you know if this if
this pulse isn't narrow enough and it's
you know it needs to be you know just a
few nanoseconds really then the output
is going to feedback in and it's going
to toggle more than once per rising edge
of the clock so what can we do about
this well in the next video I'll show
you a much better way to build a JK
flip-flop that doesn't have this racing
problem at all and that's something
called the master slave JK flip-flop
it's much more robust and we shouldn't
have any problems getting it working on
a breadboard