there are a lot of ways to build a clock
circuit for our computer but you know we
want something that's relatively
flexible we can adjust the speed you
know we don't want it to run too fast we
want to be able to see what's going on
and so I'm going to use the the 555
timer this is a classic integrated
circuit here the the triple five timer
and this that's what this chip is here
and so you can tell pin one here is by
the the divet and one two three four
five six seven eight and right now I'm
powering this with just five volts
coming in from a cell phone charger that
I've cut into the USB cable pulled the
five volts out and to power the chip
power comes in five volts here on pin
eight and ground to pin one you can
actually go up to I think 17 volts or 16
volts or something with this chip but 5
volts works and to control the timing
you've got two resistors and a capacitor
and so the first resistor here is going
from 5 volts to pin 7 this is a 1k ohm
resistor and then from pin 7 to pin 6
I've got a 100k
ohm resistor and then pin 6 is connected
around to pin 2 and then from pin 2 to
ground I've got this capacitor and this
is this is 1 micro farad capacitor and
you can see the positive side is
connected here to pin 2 so the negative
side is connected to ground you'll make
sure that's in the right way and so
those resistors in the capacitor control
the timing we'll see how that works in a
minute but the output of this chip is on
pin 3 and so that's just connected to
this LED and you know the output can
drive a fair amount of current so we
want to make sure we have a current
limiting resistor this is just a 220 ohm
resistor here limiting the current
through the LED so we don't burn up our
LED so how does it work well good place
to start of course is the datasheet this
is the datasheet for the 555 timer and
you can see they they actually give you
a whole schematic of what's going on
inside that chip which we we won't go
through all that but they also give you
a bunch of other stuff in here one is
this sort of block diagram it gives a
little higher level view of what's going
on and so you can see there's a couple
comparators there's you know these three
resistors there's a flip-flop
that these comparators connect into and
then there's this output stage so this
is this is pretty interesting I don't
personally like the way that this is
drawn it's kind of drawn to line up with
the pins here they give you a different
version of it a little bit later on here
this is a sort of a different view of
the same thing but I don't really like
this one either
it doesn't share that actually should be
a connection from here to this
comparator and you don't really know
what these inputs are is like okay
there's three things going into the
flip-flop but what what are they I don't
know I don't particularly care for these
diagrams so I I drew up my own that I
think explains us a little bit better
and you can see just like those other
diagrams there's the two comparators
there's a flip-flop to actually an SR
latch I think it's probably a better way
to describe what this thing is and let
me just kind of walk through what's
going on here so everything inside this
blue box here is kind of what's going on
inside the inside the the timer itself
and then the green stuff that I've drawn
out here is is the rest of the circuit
so we can kind of go through and look at
what we've got so this this 1k this is a
1k resistor going from 5 volts to pin 7
and then between pin 7 and 6 that's this
100k resistor here and then you can see
pin 6 and 2 are connected that says a
little green wire going around here and
then between 10 2 and ground we have
this 1 micro farad capacitor and then
over here we have our LED and this is
our I think it was a 220 ohm resistor
over here so this is this is our circuit
and understand how it works we can kind
of look at what's going on inside the
the triple 5 timer so I just start by
looking at this this path through here
you can see we've got our +5 volts up
here and then of course our ground down
here is 0 volts and then there's these
three resistors and I think each of
these resistors inside here is 5 K so 5k
5k 5k I think it's a complete
coincidence that's a 5 5 5 timer but
anyway but what these do is they set up
a voltage divider and so at this point
here your you've got 1/3 of
voltage between zero and five volts so
that's you know one in two thirds volts
so one point six seven volts we'll call
it and then at this point here we've got
two thirds of our five volt supply so
this is two thirds is you know three
point three three volts and so you've
got this voltage dividers here five
volts you go through this resistor
you're down to three point three you
know this other resistor you down to one
point six six six seven whatever and you
go through this other resistor and
you're down here at ground zero and what
that does is that sets up these inputs
for these comparators and the way the
comparators work is there's a positive
input and a negative input and if the
positive input is above the negative
input then the comparator switches on
and output is a is five volts and if the
positive input is below the negative
input then the Curtis switch is off and
the output here is zero volts so let's
think about what happens when we when we
turn this thing on get this out of the
way here for a second so what happens is
let's assume that these inputs over here
this is all zero volts so we've just
turn this on stuff as zero volts so
we've got zero volts coming in here that
is below one point 6 volts and so this
comparator turns on and so that triggers
the set pin of the SR latch and if you
don't know what an SR latch is I've got
a video on that but basically it's going
to set in a reset and when the set goes
high then the output comes on and when
the reset goes high then the output
turns off and then of course if they go
low then it remembers its last state and
there's both the output here and then
there's the inverted output here which
is Arthi which is always the opposite of
our output so we have zero volts here
we've got zero volts here this
comparator will be on because zero is
below one point six and this comparator
will be off because zero is not above
three point three so this one's off this
one's on and so the latch is going to be
set which means our output will be will
be on so the LED will be on so we're
going to start on so we'll do a little
graph here and if our output is on then
that are not output or our inverted Q
here is going to be off and so this
transistor will be off and so nothing
nothing's going to happen here we can
kind of ignore this this whole discharge
think
for now so what's going to happen is
we're going to have current flowing
through this 1k resistor through the
100k resistor and into this capacitor
down here this 1 micro farad capacitor
and that capacitor is going to start to
charge and so if you look at the charge
on the capacitor which is also the
voltage here going into pin 2 it's going
to start move this you can see here it's
going to start here at 0 volts and it's
going to start to climb and it's going
to keep climbing and climbing and
climbing as this capacitor charges and
so what's happening is the voltage here
is increasing and at some point it's
going to increase above 1 point 6 volts
and if it's above 1 point 6 volts this
comparator will turn off because 126 is
no longer above whatever this voltage is
so the comparator turns off and that's
fine right because the latch is going to
latch its output so we're not we're not
asserting the set pin anymore this set
signal but you know if we haven't reset
it yet it's still going to be we're
still going to have a high output here
but eventually this voltage is going to
reach 3.3 volts it's going to it's going
to maybe go a little bit above 3.3 volts
and at that point you know that that
voltage is going to be above 3.3 volts
and this comparator will turn on because
the the positive input here is above the
3.3 volt negative input so this will
turn on and this will reset the latch
and I guess I didn't give myself enough
room here so nor that so this is our
output our output is going to get reset
when this hits 3.3 volts so yeah so this
is if this is like 3.3 volts on our
capacitor here maybe this down here is 1
point 6 volts and we'll say this is zero
so we started at zero we went through
one point six volts you know nothing
happened
we turn off the set pin but then we
stayed latched and then we get up to 3.3
volts and at that point our output turns
off but the other thing that happens is
our R naught output or inverted output
this turns on and that's going to cause
current to flow from here through into
the base of this transistor and that
will turn on this discharge transistor
and so then what happens is you know
current can now flow through the 1k
resistor through this discharge to
ground so okay that's that's not very
exciting but what's more interesting is
that current can also flow from the
capacitor through the 100k resistor you
know so before we were charging the
capacitor in this direction now we're
discharging the capacitor current is
flowing from the capacitor through the
hundred K resistor and through this
discharge and so the capacitor is going
to start to discharge and it will
discharge for for a while and of course
it'll you know as soon as it starts it
charging it will drop below the 3.3
volts and so the reset will turn off but
again this is latched so nothing happens
but eventually the capacitors a voltage
will drop below one point six seven
volts and now with this below one point
six seven the set comparator turns on
and it sets the latch again and so when
we set the latch when this gets down to
one point six volts we set the latch we
turn the output on we also turn the
discharge transistor off so we turn this
off and so we're no longer pushing
current through the base of this
transistor and so this transistor is off
and so no longer is the capacitor
discharging we're back into the state
where the capacitor is charging again
capacitor will charge our output is on
eventually the capacitor will get back
up to three point three volts this will
switch will start discharging again and
this will turn off capacitor will
discharge and it's off capacitor will
charge discharge and so we get the
capacitor is charging and discharging
kind of like this but our output here is
this nice clean square wave and that's
what we see when we look at the circuit
here we see our LED flashing and of
course we can control the rate that the
LED is flashing based on the values of
these resistors in the capacitor right
because you know the rate is is is a
set by how quickly this capacitor
charges and how quickly it discharges
and so how quickly it charges is you
know going to be dependent on you know
these two resistors and the capacitor so
the bigger these resistors are the
slower it's going to charge and of
course the bigger the capacitor is the
longer it's going to take to charge and
if these resistors are smaller than
it'll charge faster if the capacitor is
smaller it will charge faster and then
for discharging so the time when this is
low it's just discharging through the
one resistor here and so you know again
if this is a bigger resistor it'll take
longer to discharge and so this will be
low for longer if it's a smaller
resistor it will be faster and so by
adjusting these components we can kind
of control the the rate here and so one
thing you might notice is that you know
I chose a 100k resistor here and then a
relatively smaller 1k resistor here I
mean this is only one percent of this
and that's because because we're
charging we're charging through both and
we're discharging we're only discharging
through this one but I wanted this
square wave to be fairly symmetrical and
so by this only being like a 1%
difference in the charging from
discharging you end up with essentially
essentially the same time that it's off
that it is that is on that's sort of
what's called the duty cycle if you look
at the the datasheet they actually give
you some formulas here for for figuring
out the time that it takes to to charge
or discharge so charge time discharge
time and they actually show a nice
little graph it looks very similar to
the one that I just drew but you can see
you know they they give you they give
you the charge time is based on RA plus
RB I think they're calling this RA and
this is RB times the capacitance which
is C here
whereas the discharge time is just based
on our B right because we're only
discharging through that one resistor so
you don't see RA in there and then the
total period is RA plus 2 RB right
because it's RA plus you're going
through RB twice for the for the total
period times
our capacitance and so we can figure out
our total period just using this formula
we can pull out a calculator here and so
just sort of order of operations here
resistor B is a hundred thousand ohms
times 2 and then we can add in resistor
a is a thousand ohms as our 1k resistor
and then we'll multiply that by our
capacitor which is a it's a 1 micro
farad capacitor so I think that's that's
1 micro farad and then we multiply that
by this point 6 9 3 and yeah the reason
you're multiplying by that is you know
yeah the resistance times the
capacitance gives you the time constant
and that's used in the to sort of give
you this exponential
see what I'm doing here the curve for
this exponential function but you know
we're not we're not going the whole way
and you know we're just going from one
point six volts to 3.3 volts and so
they've they've done some of the math
for you to figure out what what
coefficient you need to use to get from
the time constant to the actual period
and so what we come up with is 139
milliseconds or 0.139 seconds and so
that's the the period that our that our
LED is flashing now if we want we can
double check all this for ourselves by
hooking up to an oscilloscope here so
I'll just hook up the ground for my my
probes here and then I'll connect one
probe to the output which is the pin
three here and then I'll hook the other
probe up to the capacitor so we can
watch the charge on the capacitor and
here we go we can see our output which
is which is this nice square wave and
then we can also see the charge and
discharge of the capacitor and so if you
look here ovo lire so this is one two
three four five volts so you can see the
charge and discharge the capacitor is
going from you know this is about one
and two thirds of a volt up to you know
one two three and a little bit three and
a third volts it's exactly what we'd
expect from that
you know that voltage divider is the
output you see is going from you know
zero volts here to one two three and a
little bit here three and a half volts
maybe you might expect it to go all the
way to five volts but but actually the
datasheet does talk about this it does
say if we look at the output voltage
here for five volt
it says typical as 3.3 volts and we're
getting you know a little bit more than
that but it says the minimum is two
point seven vials so we should be
getting at least a minimum of that which
is fine that's enough for a logic high
level so if we're feeding this into our
any kind of digital logic we'll we'll be
okay with that and then we should see
you know 139 milliseconds here so this
is 50 milliseconds per division so this
is 100 200 and huh so that's not quite
not sure why double check this well I
figured out the mystery so when we
calculated 139 milliseconds and we're
seeing about double that and the problem
turned out to be these capacitors so you
know looking ATS capacitor it says 1mf
d50 V so I would assume that that means
it's a 1 micro farad capacitor 50 volts
it's got this one 0 to 2 I assume that
that's a date code of some sort maybe
it's manufactured in 2010 the 22nd week
of that and that's all it says on it so
I would assume as the 1 micro farad
capacitor turns out when I hook it up to
my meter it measures had 2 micro farad's
so I don't know what's going on with
that I got a whole bucket of these
things and they all say 1 MFD on them
and they all released all the ones I
measured measure 2 micro farad's so
instead of 1 micro farad it's 2 micro
farad's and so you know if we if we plug
that into our formula we had 1 micro
farad there so we plug 2 we're basically
multiplying by 2 so multiply that by 2
278 milliseconds and you know we're
measuring 263 milliseconds period here
and that's
that's much more inline that's that's
certainly within you know we've got 5%
tolerances on this resistors and stuff
so 263 278 close enough so very
interesting I always assumed these were
one microfarad but apparently apparently
not if anyone knows why they're they're
marked that way maybe maybe I'm missing
something obvious but I would assume
that one MFD means one microfarad but
apparently one MFD means two microfarads
go figure
yeah so 263 milliseconds that's much
more what we'd expect and so if we take
one over 263 milliseconds we get about
3.8 and so that tells us this should be
flashing about 3.8 times per second and
that I don't know visually seems about
right so I think we're almost done with
this circuit it looks like it's working
I did want to talk just briefly there
are some power supply recommendations in
the datasheet and I want to talk a
little bit about the power supply we've
got this is just a cell phone charger
this is from Apple which is actually a
very good power supply if you get a
genuine Apple 1 but in any event you
know it looks like everything's working
fine you know our LED is flashing we've
got our nice clock output here so you
could probably use this and it would
work okay probably but there are a few
things that the datasheet recommends
doing to reduce noise and so one thing
it recommends doing is putting a
capacitor on pin 5 we're not using pin 5
it's control voltage for some other
features of the triple 5 timer that
we're not using and it recommends
putting a point 0 1 micro farad
capacitor from pin 5 to ground to reduce
noise so what is it talking about well
we see on the scope here we see this
nice transition from 0 volts to 5 volts
but if we if we zoom in on that or zoom
in oh what you see is that that nice
transition from 0 volts to 5 volts is
maybe not so nice there's some lot of
junk in there so if we add this
capacitor that they're recommending from
ground to pin 5 boom clears it right up
so definitely recommend that point 0 1
micro farad capacitor going from pin 5
to ground there's still some other noise
if we go in even further go into
run away go all the way into nanosecond
range you see there's some overshooting
here and what's happening is when the
when the output wants to turn on you
know there's a bunch of transistors in
here switching and doing whatever they
do and you know when they switch there's
a different current requirement so
they're pulling more current or they
want to pull more current from the power
supply and they're not able to pull that
current as as quickly as they would like
to and then at this point they're there
and they end up getting more current
than they then they wanted and it kind
of overshoots and it's probably don't
see more sort of back and forth
oscillations here that's fairly typical
but it looks like it levels out pretty
quickly here but we're overshooting
above you know right here this is 5
volts we're going up over 6 volts which
may not be good you know if we our
output is supposed to go between 0 and 5
volts and we're feeding into something
that's expecting 5 volts and we give it
6 volts that could be a problem and the
reason that this is happening is you
know our power supply is over here and
we've got all this wire that's
connecting it to the board you say well
the wire is just going to it's a
conductor you know just blocked rounds
flow right through no problem well
almost you know in a perfect world sure
that's how wire would work but we're
we're not in a perfect world and so this
this wire has some impedance it's
actually acting as an inductor so when
you've run current through the wire you
get a magnetic field that builds up
around it and that magnetic field is
going to resist changes to the current
that flows through that wire and so when
we try to pull more current we get a
little bit of an impedance that's
resisting that and straight this by
getting all this wire out of here and
hooking up this short short USB cable
that I've that I've hooked up and plug
that in and there you see this comes up
a lot faster is one thing you'll see and
you also see it doesn't go above 5 volts
still doesn't you know takes a little
bit of time to settle in but this is
much better we're staying in spec we're
not going above 5 volts it's turning on
pretty quickly and that's just because I
don't have all the impedance in this
wire we do still have impedance you know
from here through the tray
is inside this breadboard you know and
into the chip and everything so there's
it's still not still not perfect which
is why it doesn't look perfect here but
a lot better but of course we don't want
to have a short little power cable like
this we want to be able to not have our
extension cord run all the way up to it
so let's plug this back in and see what
else we can do so we're back to that
crazy overshoot the other thing we can
do is if we put a capacitor just across
our power connection here that capacitor
can sort of you know get charged and
then when this chip wants to pull more
current it can pull it from the
capacitor so we just take as a point one
micro farad capacitor and just stick it
right across those power pins boom we
get we get basically the same thing and
that's because you know the power supply
has capacitors in it it's doing
essentially the same thing that we're
doing with this capacitor here now
ideally what you want to do is you want
to get this capacitor as close as
possible to the chip and put it right
across the the power pins on the chip
and if you look in you know any any
electronics every chip is going to have
a capacitor or maybe multiple capacitors
sitting right next to it to smooth out
these current transitions you know I'm
not going to get too crazy with it I
think you know with this computer we're
building we're not running at a super
high speed so if it takes a little while
to come up and stabilize it's you know
not too big a deal so what I'm going to
do is just put one of these little point
1 micro farad capacitors on each
breadboard and hopefully that'll be good
enough ok so we've added our 0.01 micro
farad capacitor here to pin 5 and we've
also got a 0.1 micro farad capacitor is
just sitting across our power pins and
so I'm going to move that over here just
so it's a little bit more out of the way
but it's still connected to to the board
across the power pins which which I
think is good enough there's one other
thing that the datasheet recommends
which is pin 4 which we don't have
anything connected to and I didn't draw
it on the diagram here
but what pin 4 is is it kind of gives
you this other connection here to to the
reset of the latch so it gives you kind
of a direct connection in here to to
just reset this latch if you wanted to
actually I should draw it it's inverted
input it's not it does not hooked up
exactly like this but it this is
basically how it functions is if you
bring pin for low it'll just force this
latch to reset it overrides anything
that it's going on over here so normally
we wouldn't want to bring that low
unless we wanted to reset this and so
what the data tree recommends doing is
to prevent it from accidentally you know
going low if there's some stray voltage
or something it recommends if you're not
using it to just high it to five volts
so if we just connect that to five volts
then this will always be high which
means we're not going to be you know
inadvertently resetting this if there's
just some delays so that's just
something else will do and then the last
thing I wanted to do is I want to be
able to control the the speed of this
thing so we have it blinking at this you
know three point eight times per second
or whatever it is which is which is
great but it would be nice to be able to
control it of course you can change out
the capacitor change out these resistors
and you know hopefully you you know you
can you can kind of see how to do that
and but what would be really nice is to
add you know change this hundred K
resistor to a variable resistor and so I
have this one mega ohm
variable resistor and you just turn this
and get a different resistance and it
goes from zero ohms so just short all
the way through one one mega ohm which
is ten times more than this and so what
we can do is we can add this to the
circuit here and what we can do is we
can hook that up in place of this this
hundred K or this hundred K resistor so
if I take 100k resistor out and what
I'll do is just hook up some jumper
wires from you know pins six and seven
right I want to connect between pin six
and seven and I'm just sticking it over
here with the jumper wires because this
is too big to just jam right in there
like the little resistor was but the
other thing I'll do is I'll put it
instead of just hooking this variable
resistor between pins and six and seven
by itself you know because when you turn
it down it goes down to zero volts that
would be a direct short between six and
seven which would mean that when
our clock turns off the capacitor
instead of discharging like this the
capacitor will discharge almost
instantly through here if there's no
resistor there at all and so then you
know basically this would never go low
because as soon as this goes low it
would instantly almost instantly go high
again so we don't really want that so
what we can do is we can put another
resistor in series with our variable
resistor and that will essentially act
as a minimum value so I'm going to put
in this 1k resistor between the other
pin of our variable resistor and pin
seven there so you know if this is
turned all the way down it's one it's
one K and if it's turned all the way up
it's one mag or one point zero zero one
make or whatever whatever it is
so let's hook that up again let's see
what we get and it looks like it's all
other it goes yep it's just going really
slowly and of course we can turn this
knob and get it to go faster there's
going a little bit faster and we can
turn it even more in it goes even faster
and if we turn it all the way it's I
don't know if you can see that I can see
it's basically flickering because it's
just going so fast because right now
with this turned all the way down we
just have a 1k resistor and so when it's
charging it's charging through 2k of
resistors and then it's discharging
through 1k and so you could probably do
the math and figure out how fast that's
flashing but I like that now you can get
it kind of dialed in to whatever speed
we want if we want to go really slow you
know again we're using this as a clock
for a computer so we may we may want to
go really slow to see exactly what's
going on we can do that but we might
also want to just manually control the
clock by by pushing a button so we can
go as you know slow as we want and so
we'll look at that in the next video