so in previous videos we've looked at
the or gate which if you remember in
this case we have two inputs if one
input or the other or both are on then
the output is on otherwise the output is
off in this video I want to start
thinking about scenarios where we have a
gate where the output is connected back
to the input or or some series of gates
where the output is connected back to
the input and so you might think well
maybe we can just come up with a truth
table like this or the input it can be
there a 0 or a 1 if it's a 0 then the
output ought to be something and if the
1 and the output might be something
different but what we'll see is is that
it's not quite as simple as that so to
build a little bit of intuition for
what's going on here I think it's
easiest to kind of build a circuit and
and kind of see what happens so this is
that circuit it's got a this chip is
this as a 74 LS 32 chip which has four
or gates on it and this is the pin out
for it and you can see with the four or
gates you've got a B and why are the
input a input B and Y is the output so
that the first three pins and this chip
is is upside down so it's these first
three pins here and what we've got just
like the diagram here is input a is
connected to the switch input B is
connected via this little blue wire to
the output and then we also have an LED
connected to the output and you might be
wondering if we need a resistor for this
LED but if if we look at again at the
data sheet for the 74 LS 32 there's
already on the output there's already a
resistor here connected through this
transistor and so when this is switched
on into the gates on we already have 120
ohm resistor built into the end of the
chip here in this in this case that's
going to limit the current so we should
be okay with that led the input is
connected to the switch which it's
actually connected across this resistor
to ground and then when we push the
button the button will will connect us
to this 5 volt source here so if we're
not pushing the button
it's inputting a 0 if we push the button
it's inputting a 1 and this is a
momentary switch so let's hook the power
up and see what happens so cut the power
up and you can see the output is off and
so that kind of makes sense maybe the
inputs start as zeros and so zero and
zero should give us
give us a zero output and of course if
that's a zero then that's going to feed
it another zero back into this B so it
just stays everything's a zero does that
make sense so now let's see what happens
if we change the input to a 1 by pushing
the button so if we push the button the
inputs a 1 so 2 1 and a 0 and we get a 1
as the output we see the output comes on
but actually this output is now coming
back into this input so B is a 1 as well
now so actually we've got we're pushing
the button so we got a 1 coming in a
we've got a 1 in being in so the output
is still 1 but now if I let go of the
button 2 a is now 0 B is still 1 and so
the output is still 1 so this this stays
on even though I've now let go of the
button and in fact if I keep pushing the
button there's really nothing I can do
to get this to turn off once this input
turns on even if it turns off later the
output stays on and it latches on
essentially it's a really the only way
to reset this is to disconnect power
from the entire circuit and then you
know we can reconnect it and of course
it starts out at 0 again but if at any
point after this thing is powered up
that input ever goes to a 1 even if it's
just momentary if I just hit it really
quickly that output latches on and
remembers that that input was at one
point a 1 so this is pretty interesting
you can imagine why we can't just come
up with a simple truth table like this
like we might like to but what would be
even more interesting is if we had some
way to turn it off again some other way
to reset this other than having to
disconnect power from the entire circuit
because that might not be you know too
practical so what I want to do is look
at another circuit that actually does
work that way and this is this is that
other circuit and this might look a
little confusing at first you know but
we'll walk through it one thing you'll
notice is different we're using nor
gates instead of or gates so it's the
same as an or gate but the output is
inverted we'll talk a little bit more in
a minute about that and again I think
you know a good way to build some
intuition for for this is to actually
build the circuit and so I've done that
here this this chip now is that quad nor
gate it's a 74 LS 0 2 chip which has 4
nor gates of course we're just using two
of them and to kind of walk through
what's going on in here the bottom pin
here is this bottom input and then the
next pin up is the
is input here and you can see the yellow
wire is connecting it to the output of
the topic or gate the third pin is the
output of the bottom nor gate here and
you can see that's connected to an LEDs
we can see what the output is and you
also see this little yellow wire is
connecting it to the input of the top
nor gate the other input at the top of
nor gate is connected to this blue wire
to the switch here so we can set the
input there and then finally the output
of the top nor gate as we saw we've got
a hook to an LED here and it's also
going back down to an input on the
bottom or gate and again these switches
are hooked up so that they're normally a
zero and when we're pushing them they're
a 1 so let's say you know before we
think too too much about this let's
let's just sort of power this up and see
what happens I was like to kind of build
the thing and see what happens good plug
it in and the top LED comes on so this
nor gate on the top is is switched on so
this is basically what is happening here
so I've kind of drawn exactly what
states different things are in to kind
of make this a little bit easier to
understand and also as a reminder it got
the truth table for an or gate so again
if either input 1 input or the other or
both are on then it's off otherwise it's
on so sort of the opposite output of an
or gate so in this case the top or gate
is on and so we see the LED there and
that implies that this input down here
must also be on and so if we just kind
of Reason through this so hopefully
it'll make sense so the bottom nor gate
we've got a 1 and a 0 and of course this
one for some reason this top LED came on
we'll talk about why a little bit later
but for now we'll just sort of take it
on faith that it's on because we can see
that it's on and the bottom is is 0
because we're not we're not pushing this
button so that's a zero so one in a zero
means that the output is a zero and that
makes sense do we see the bottom LED is
off and so then that's being fed back
into the top nor gate and of course we
know we're not pushing the top switch
either so it's a zero and a zero going
in here which means that the top nor
gate should be on and that's what we see
so this hopefully makes some sense so
now what happens if we start changing
these inputs so the bottom input is
fairly straight forward if we turn the
bottom input on then this gate will be
the inputs will be one and one
and we could see the output then is
still zero so this doesn't change which
means this top nothing else changes so
if if we change this bottom we if we
input a 1 if we push this button nothing
should happen and in fact nothing
happens we can push this button as much
as we want nothing's changing because
we're just going from 1 0 to 1 1 you can
see 1 0 1 1 the output stays the same
here
doesn't change this nothing changes now
the top one is a little bit more
interesting so if we push the top button
we're basically changing this here to a
1 so this I've just redrawn the circuit
here and I'm changing just this top
input to a 1 if we do that the top gate
now has inputs of 1 and 0 and so 1 and 0
it ought to change it ought to turn off
in output a 0 here if it does that that
puts us here so 1 0 and 0 so that makes
sense but now that changes the input of
the bottom gain so now the bottom gate
is getting a 0 and a 0 coming in well if
a 0 and a 0 are coming in the bottom
gate ought to be outputting a 1 so then
it's going to switch on and when it
switches on that changes the input on
the top gate again so now the top gate
is getting a 1 and a 1 well in that case
a 1 and a 1 is still a 0 so the top gate
doesn't switch it's already off and so
now the circuit is stabilized in this
configuration but what you see happens
is before we had the top LED on or the
top gate on and at the end of this whole
sequence of events the bottom gate is on
the top gate is off so let's give it a
try I push the button here on top indeed
we see the top goes off the bottom comes
on so we're now in this state and really
it did actually flip through all three
of these states it just happened very
quickly I mean on the order of
nanoseconds really to get to this state
here well now if we release the top
button and this goes to a zero that puts
us in this state here
and a 0 and a 1 input on the top gate is
still going to output a 0 0 and a 1 is
still 0 and so nothing changes and so
now with both inputs off we've swapped
which of the gates is on so this is
essentially a mirror image of where we
started so we started with the top gate
on the bottom gate off now we have the
bottom gate or excuse me the top gate
off and the bottom gate on and since
this is the mirror image of this you
know now pushing the top button doesn't
have any effect whereas before remember
when pushing the bottom button it didn't
have any effect but pushing the bottom
button is basically going to run through
this same sequence of events but sort of
in mirror image and flip from the bottom
to the top and now the bottom is now in
effect and so you can see by pushing
these buttons we can kind of flip it
between one state and the other and then
once it's in that state it stays in that
state until we until we push the button
again or don't we push the other button
I should say and so this is a fairly
common circuit and it has a name it's
called it's called an SR latch an SR
stands for set reset because the the
latch can essentially be set or reset
and so these inputs are labeled you know
typically labeled R s and then the
outputs are labeled Q and inverse Q or
not q and the way to sort of think about
this is that if you want to set the Q
output then you input a 1 on the on the
s input or the set input so this sets it
in the sense that the output Q is on and
then this resets it in the sense that
the output Q is off and then inverse Q
is just always the opposite of whatever
Q is and so sometimes you might see this
this SR latch in circuit diagrams just
as a box will draw it like this and it
will have these inputs and they'll be
labeled R and s and that's how you'll
know it's an SR latch and it'll have the
outputs Q and not Q and then usually
they'll have a little bubble here to
show that that's an inverted output and
so if you see this in a circuit diagram
you can basically think of it as this as
this circuit or
thing that works equivalently in the
sense that if you press the if you or if
you input a one on that on that set
input then the queue will latch high and
if you input a one on the reset input
then the queue will latch low and then
the not queue will sort of do the
opposite and you might be wondering you
know what happens if you input a one on
both the set and reset at the same time
and you know in that case the outputs
are both you know both Q and not Q go go
low and you know sometimes you might see
this referred to as an invalid state
because you you you know if you're sort
of using this as a set reset latch you
should only be setting it or resetting
it at any point in time shouldn't be
doing both so sometimes you might see
that as an invalid State the other
question you might have is you know when
we first when we first powered this up
you know it started with this top gate
on and the bottom gate off and you might
be wondering well why you know why does
it prefer the top gate this thing is the
circuit is fairly symmetrical and really
it's it's just kind of almost random or
arbitrary which one which one turns on
first because when it first starts up
all of these inputs are zeros and so if
both inputs are zeros both gates want to
turn on and in fact both gates might
turn on but what will happen is one of
them will turn on maybe a little bit
faster and this signal will get to the
other gate and this other gate will now
have this one input and a 1 and a 0 will
turn one of the gates off and so it's
really just a question of which one
turns on first and it's you know usually
probably on the order of a few
nanoseconds or one it's just a little
bit faster than the other and so it just
sort of arbitrarily one of them is going
to turn on first and so if you're using
the circuit in and using this you know
this SR latch in a circuit you're going
to want to make sure you you have some
way of resetting it or setting it or
getting it into some known state before
you rely on its output I suppose and so
because the SR latch has this property
that you can set and reset it and it
remembers the state that it's in you can
imagine it might be useful in all sorts
of computer memory and other
applications and so in future videos
we'll we'll build on this and look at
some other types of latches and and
other components that are used in
computers