is it a good idea to build an entire
computer from scratch on bread boards
like this well it might seem like a
strange question for someone who's
basically made an entire youtube channel
out of doing precisely that and I sell
kits with all the parts so you can do it
yourself
so obviously I'm a pretty big fan of
building computers on bread boards and
the big reason I really like it is that
it forces you to think through how
everything works you know what I felt
like something was missing with these
projects where you get a premade circuit
board and you just solder a bunch of
components to it
and don't get me wrong it's great if you
want to learn how to solder but once you
know that I I just don't see how
attaching a bunch of components to a
circuit board teaches you much about
electronics in fact the typical
experience is that you solder the whole
thing together plug it in and it it just
works the first time there's nothing to
troubleshoot there's no need to
understand how it works and so you don't
this on the other hand you know it
really forces you to think about each
individual connection to each pin and as
you build each section testing it you
know each as you go there's a very good
chance things aren't going to work
perfectly the first time and that's a
good thing
you know forces you to think about why
and it helps you build a deeper
intuition for how it all works and so
that's what I really like about doing
big projects like this on bread boards
but aside from being a lot more work
which which i think is a good thing
there are definitely some caveats to be
aware of when building complex projects
like this on bread boards first not all
bread boards are the same there's a big
difference in quality between the cheap
$2.00 bread boards you can get and a
higher quality you know eight or nine
dollar bread board and it's true they
look pretty similar but let's take a
look inside each row on their bread
board is connected with a metal strip
that grabs the wires that are inserted
and if I dig under the backing here I
can remove that metal piece so we can
take a closer look at it and here it is
is what it looks like if we take a
closer look you can see the wires are
inserted like this here and make contact
with with the metal here and in a good
quality breadboard these this metal is
nice and flexible and you can see even
if you insert the wire it kind of a
weird angle like this it it flexes like
that and then pops back nicely you can
also see it's nicely shaped so that when
you insert the wire from the top which
is which is what you'd be doing you know
it kind of finds its way in there nicely
so these make very good contact with the
wire
bring back so they last a long time and
everything else now let's take a look at
the cheaper breadboards a construction
on the cheaper breadboard is pretty much
the same so it's actually pretty hard to
tell the quality just by looking at a
breadboard which is unfortunate because
it means it's easy to pay for a
high-quality breadboard and end up
receiving one that's lower quality and I
may not even be the fault of the person
selling it to you since they may just
not realize that there's such a big
difference but anyway here's the same
piece from the cheap breadboard so let's
take a look at the difference and so you
can see it's the same basic shape but
right away you can see there's a huge
difference here you know the metal is
just not not as springy and so it
doesn't snap back together and so it may
not make great contact with the wire as
you can see here and it actually gets
worse you know over time if you you know
insert something big you can actually
bend this out of shape and I mean that's
maybe a little bit extreme for what you
might stick into a breadboard but once
that's bent out of shape you know
nothing you know you're not going to
make great contact there and so the
quality of this breadboard and the
quality of the connections you're going
to get is is much worse so there's a big
quality difference and you can even see
the you know just the shape of the of
the the top there where the wire goes in
is very different and and much less
consistent on the lower quality one so
the quality of the breadboard matters
you can run into a lot of problems
building a more complex project like a
computer on these cheaper bread boards
because he just can't be assured that
all the wires are making good contact
and you can check out my website for
more information on what bread boards I
recommend and of course if you get any
of my kids they're all gonna come with
these high quality bread boards but okay
even with the best bread boards there's
still a lot of limitations to building a
complex design like a computer on bread
boards versus a custom printed circuit
board or even these you know soldered
prototyping boards and that's because
the physical properties of the
conductors in a circuit whether that's
the traces on a printed circuit board or
the wires and and bread boards in in
something like this you know those
conductors and everything have physical
properties that affect the circuit for
example it's easy to look at two wires
like this you know let's say these two
wires here and think well okay you know
this wire connects this point here to
this point here this wire connects this
point here to this point up here and
maybe they don't really have anything to
do with each other
and that's not entirely true you know
anytime you have two pieces of metal
close together like you have these two
wires that are close together maybe you
actually have a capacitor and that's why
the schematic symbol for a capacitor is
two plates next to each other but not
touching and the way a capacitor works
is you have a difference in electrical
potential on either side and a charge
builds up between these two plates and
another way of saying that you have a
difference in electrical potential
between two points is saying that you
have a voltage across those points
that's you know that's what a voltage is
it's always you know sort of a voltage
measured between two points and it's
just the difference in electrical
potential between those points but with
a capacitor in here if you try to change
that voltage the capacitor will will
actually try to prevent that you know so
if you try to increase the voltage by by
you know adding more charge to one side
the capacitor is actually going to
absorb that charge and charge up a bit
before the the voltage between these
points actually changes and then if you
try to decrease the voltage here by by
pulling some of that charge away the
capacitor will discharge as much as it
can to keep the voltage from dropping
and you know sometimes you want that so
for example on the power rails you
actually don't want the voltage to
fluctuate right we have five volts
coming in and you know we want five
volts everywhere on our power rails to
be actually 5 volts we don't want it
dropping and things like that so if if a
chip is switching circuit on and off and
it has to draw more current to do that
we don't want the voltage on that power
rail to drop and so it's actually a good
practice to add some capacitors just
across the power rail like this so
actually add a couple of point 1 micro
farad capacitors here across the power
rails to help stabilize the 5 volts that
are on those power rails and really the
the best practice here is to have one of
these capacitors for every chip that's
on on in your circuit so for example we
could have a capacitor here directly
from 5 volts to ground across this power
rail for for this chip here like this so
that means that if this chip has has any
change in the amount of current it needs
to draw from them from its power rails
it's always going to see a consistent 5
volts or as close as close as we can get
to that and so the closer you can put
the capacitor to the power inputs for
any particular chip the the more the
better stabilized the power is going to
be for for that chip and that's I guess
one of the other maybe drawbacks of
breadboards is that it's it's you know
kind of hard or at least inconvenient to
get these capacitors directly across the
power rails of a chip like this you've
got to kind of put it across and some of
these chips they're the powers are just
gonna be an inconvenient place but I
think you know for what we're doing it's
probably good enough just to have a
couple capacitors here these will still
help stabilize the power rails without
you know really getting in the way too
much so that's fine you know we can add
capacitors here if we want to stabilize
the voltage and keep the voltage from
changing like we do on our power rails
but elsewhere you know we have signals
that need to change voltage rapidly you
know any of these signals need needs to
change voltage rapidly because they're
you know carrying signals and and and
and that has to change
and so the stray capacitance that
inherently exists in the breadboard or
even a printed circuit board can cause
problems and you know since one factor
that determines how much charge a
capacitor can hold is the is actually
the physical area of the conductive
plates in that capacitor you're more
likely to have a lot more capacitance in
a breadboard circuit just because you've
got a lot more metal in here you know in
the breadboard and in all these wires
then you might have in other types of
circuits now another related phenomenon
is inductance and if you've learned a
little bit of physics you might know
that anytime you have a current flowing
through a wire like this there's a
magnetic field that is generated around
that wire of course if you have a lot of
wire especially wound up like this you
can use that magnetic field to do work
and that's how a motor works and that
actually works in Reverse as well so
right now I'm using current to generate
a magnetic field that's pushing against
this fix magnet here
but any motor is also a generator and
that's because a changing magnetic field
around the wire will induce a voltage in
the wire so when I spin this the
magnetic field from the permanent magnet
changes relative to the wire and induces
a voltage in the wire so what does this
mean for a breadboard computer well you
know if you've got a wire
with a current going through it you're
gonna have a magnetic field around that
wire and if the current flowing through
the wire changes then the magnetic field
is going to change so if we go from a
smaller current to a larger current
we're gonna go from a smaller magnetic
field to a larger magnetic field but
remember if you have a changing magnetic
field around the wire then the voltage
that'll induce a voltage in the wire and
it just so happens that the voltage
that's induced will oppose the change in
current and say you've got capacitance
which opposes a change in voltage and
inductance which opposes a change in
current and both effects are relatively
small
unless that voltage or current is
changing very rapidly
well how rapidly you know if we take the
6502 computer that we're building I've
said that I plan to run this at one
megahertz so are we gonna have any
issues with one megahertz signals you
know so that's potentially alternating
between zero and five volts a million
times per second you know that can be a
problem well we can run a little
experiment I've got a breadboard here
with a bunch of connections and I can
feed a signal in on one side and you can
see I'm measuring that signal as well
and we look on the oscilloscope you can
see there's this 100 kilohertz sine wave
that we're measuring going in and so
that goes in on this side and then it
goes through a whole bunch of
connections and then we can measure it
coming out over here now I also have a
resistor here to kind of isolate the
input and output measurements and aside
from that induced current that we're
going to be looking at that I mentioned
I don't expect any current flowing
through that resistor so Ohm's law says
no current flowing through it means no
change in voltage so we should measure
the same voltage going in here and
coming out over here so here's the
signal going in it's a 1 kilohertz sine
wave and we're measuring that over on
the left here but we'd also measure the
output on the right and so if I overlay
that you can see it's pretty much the
same thing and you know that's not too
much of a surprise since we basically
just have a wire going through the
breadboard but if we increase the
frequency and can dial this up so that
was 100 kilohertz
so if we keep going up when got to one
night one megahertz zoom in here and it
still looks like pretty much the same
signal going in and out but if we keep
going higher and higher frequencies zoom
in here you actually start to see
something happening here you see the
output which is the yellow actually now
the yellow is the input so you see so
you see the green which is the output is
actually shifting a little bit from the
yellow so there's there's a phase shift
happening there which is kind of
interesting and that is perhaps because
that inductance and capacitance that I
talked about is going to resist a change
in voltage it's going to resist a change
in current and so it may delay and
actually cause that phase shift so we're
starting to see that and if we go higher
and higher frequencies you'll see not
only does the phase shift increase but
you also see the green which is the
output is actually decreasing so it's
starting to attenuate and so if we go
higher and higher frequencies and that's
about as high as we can go up to 20
megahertz as this is as high as I can go
with this but you can start to see that
the green signal which is our output is
being attenuated it's being phase
shifted and it's being attenuated and
actually what I can do is I can
automatically sweep through all of the
frequencies here so to do a let's see
frequency response analysis and run
analysis and what this will do is I'll
actually sweep through all the
frequencies from a hundred Hertz all the
way up to 20 megahertz which is as fast
as this will go and what you're seeing
is it's plotting the phase shift which
is I believe the red line so you can see
that's staying pretty close to zero and
then it's also plotting the gain or in
our case attenuation which is the blue
line and that's also staying pretty
close to zero and here we are at 100
kilohertz and still pretty close to zero
as we approach 1 megahertz you see the
phase shift is starting to change and
that's you know what we saw when we were
looking at it ourselves
and then as we get you know looks kind
of 5 megahertz or Beyond we're starting
to see the blue line is also dipping by
you know a few decibels and so that's
showing that at higher and higher
frequencies we're starting to lose some
of our signal integrity something else
is kind of interesting if we go back and
just look at the waveforms here remember
that the attenuation and phase shift
that we're seeing is
result of both capacitance between
conductors here as well as inductance
which is actually a magnetic field
that's generated around these conductors
so if we actually change sort of the
physical shape here or properties or you
know sort of relationships between the
different wires you can see just as I
poke at this the the phase shift and the
the attenuation that we're seeing is is
changing a bit as well and you know this
is at 20 megahertz but I think that's
pretty interesting to see that so you
can see at higher frequencies we are
starting to see some signal integrity
issues but you know we want to run our
computer at 1 megahertz here and 1
megahertz looks like you know no problem
right we're you know still zero
attenuation our phase shift here hasn't
shifted by very much at all 1 megahertz
and even the attenuation that we do see
is exaggerated quite a bit because of
that resistor I added to make this more
of a worst-case demonstration so even in
this you know pretty messy scenario that
we've got here things look pretty clean
up to 1 megahertz so we ought to be fine
right well it's not so simple that a
clock for the computer is 1 megahertz
but it's not a sine wave like we've been
looking at it's a square wave
you know just toggles from 0 to 5 volts
but in reality any signal including a
square wave is actually made up of sine
waves so here's a 1 megahertz sine wave
and I'm generating with this first
formula here which has a frequency of 1
million and so you can see the period
here is 1 times 10 to the minus sixth or
one microsecond so that's 1 megahertz
but of course it's a sine wave and we're
looking for a square wave well we can
get closer to a square wave by adding
another sine wave to it so here is a 3
megahertz sine wave and I've made it
one-third of the amplitude and if I add
these two together so f of X and G of X
if I add those together we get this
which is a little bit more square shaped
but if I add to that H of X which is a 5
megahertz square wave at 150 amplitude
so if we add H of X you can see it gets
a little more square shaped and we can
keep going I can add this next sine wave
which is 7 megahertz and you can see it
gets even more square shaped you know
the slopes are a little bit steeper here
the tops are a little bit flatter and in
fact to get a true square wave we could
add up all of the odd-numbered multiples
of the fun
mental frequency which in this case is
one megahertz and if we add all of those
up all the way to infinity and that
would give us a true square wave so
let's take a look at this other set up
here that I've got it actually got a
formula here that represents the sum of
odd-numbered multiples of a 1 megahertz
sine wave and I've got this 2k minus 1
factor in here as well as dividing by 2
K minus 1 so if K goes you know 1 2 3 4
5 then 2k minus 1 is going to go 1 3 5 7
9
so that gets all of the odd multiples
and then we're summing up all of those
for K going from 1 all the way up to N
which right now n is also 1 so right now
we're only getting the first term which
is why we just see that 1 megahertz sine
wave then I've got some other stuff in
here just to kind of scale this up and
we're adding 2 and a half here just so
that this this wave overall goes from
you know around zero at the bottom to
sort of around 5 at the top just to kind
of give us something like that 0 to 5
volt square wave that we're looking for
but now this makes it easy for us to add
more terms because I can just change
that N and so this is where we were
before with n equal to 4 with 4 terms
but we can keep going and the more and
more terms that I add the more and more
it looks like a square wave but also the
more terms that we add the more the
higher the frequency so this looks like
a nice sharp square wave but the
frequency you know their maximum
frequency that I'm using to get that is
over 100 megahertz so you know in
reality because high frequencies like
115 megahertz are gonna be very
susceptible to you know small amounts of
capacitance from small amounts of
inductance like we've got in a
breadboard circuit we're definitely not
going to see you know perfect square
waves with you know perfectly steep
slopes like this or anything like that
in real life so the question is you know
is that a big deal
well my last video we looked at this
timing diagram for the 6502 cpu and we
figured out that we weren't going to
have any problems come complying with
all of the constraints that are set out
in here but there's one natural timing
requirement that I kind of glossed over
that actually turns out to be one of the
hardest constraints to meet and that's
you know this time here this T
which is the fall time and TR which is
the rise time of the clock so what is
that requirement fall time and rise time
well we flip over here we can see full
time rise time is a maximum of five
nanoseconds five nanoseconds is not a
lot of time and just to get a picture of
that I can add two lines here that are
five nanoseconds apart so I'll add these
two and these are centered around you
know five times ten to the minus seventh
which is half a microsecond so it's
centered around this point you know sort
of half way through which is where we
have this transition and then it's
bracketed you know plus or minus two and
a half nanoseconds basically ten to the
minus nine so you know minus two and a
half to two plus two and a half is going
to give us a gap here between these two
lines of five nanoseconds and so as you
can see you know five nanoseconds is
really short so let me zoom in here and
see if we can you know see what's going
on a little bit better so I'll change
the x-axis to go from four times ten to
the minus seven to six times ten to the
minus seven so there we can see things a
little bit better and you can see we're
going from you know five volts down to
zero volts within that five nanosecond
window but remember for this signal to
exist that we're graphing here this red
signal there must be a component of it
that's you know a hundred and fifteen
megahertz so if we don't think our
breadboard circuits gonna handle 115
megahertz signal all that well then we
shouldn't expect to see a square wave
with slopes you know quite this steep so
if we go down to you know let's say
we're maximum frequency is closer to you
know maybe thirty megahertz you can see
here you know even in theory we
definitely can't transition from five
volts down to zero volts within this
five nanosecond window but you know one
piece of good news is we don't actually
have to get all the way from five volts
down to zero volts in that timeframe you
know we just have to get from high to
low and it turns out that high is really
anything above about three and a half
volts and low is anything below about
one and a half volts so really you know
something like like this would be in
spec right because we're going from from
the absolute minimum of what's
considered high to the absolute maximum
of what's considered low we're doing
that within that five nanosecond window
so this would technically be in
and so maybe that maximum frequency is
really something more like you know it's
hard to see but maybe it's maybe it's
like 40 43 45 megahertz and of course
this is just a model that shows all of
the frequencies up to forty five
megahertz and then none of the
frequencies above that in real life you
know we'd still have all of the
frequencies it's just that as we get
higher they become more and more
attenuated not to mention phase-shifted
as we saw but it you know the point is
that the model you know isn't perfect
here but hopefully it gives you just you
know some sort of idea of what's going
on the other reality is that this 555
timer clock module that I've been using
is not exactly great at meeting that 5
nano second requirement either and it's
been working fine if we take a look at
it you can see you know this is 5
nanoseconds per division so you know
going from you know let's say it's 1 and
a half volts here up to the 3 and a half
volts which is actually about as high as
it gets is a little bit more than 5
nanoseconds so you know it's not
technically in spec but it's been
working fine
so for you know an educational or hobby
project like this you know particularly
if we aren't running close to the 14
megahertz limit of the processor or we
aren't at any temperature extremes or
anything like that
yeah there's plenty of Tolerance and and
close enough is probably good enough but
let's hook up this 1 megahertz
oscillator and measure it and see how
close we really are now I've run out of
room so I'll need to add another
breadboard here you know connect the
power rails and add the oscillator here
and the oscillator is pretty
straightforward you know we just connect
power and ground to it so power goes
here to the sort top left pin ground to
the bottom right pin over here and that
powers it up and then this top right pin
we're just going to get a 1 megahertz
square wave coming out of that so let me
hook up the power here and we can take a
look at that
obviously the computer is not going to
do anything because we have no clock
connected to it now let's measure the
output of our oscillator so with the
oscilloscope probe here rather than
using the ground lead the best way to
measure this because the ground lead I
mean this is a wire it's got inductance
in it it's gonna have all the same
problems that all these other wires have
so to get the best measurement you want
to get rid of this you also want to get
rid of the clip
and you just want to use the probe and
then actually this little ring here is
is also ground so you can use this
little ground thing stick that on there
like that and then you've got a ground
and then the probe so I'll put the probe
here on the output that we want to
measure and then the ground thing is
just going to connect or sort of you
know be stuck to the case here and
that's that's gonna be ground because
the case is grounded so that's the best
way to get a really accurate measurement
of what's coming directly out of the
oscillator here and if we take a look at
that we can see we've got a 1 megahertz
square wave here and if we zoom in a
little bit you can see there is a little
bit of overshoot and a little bit of
ringing there kind of like we expected
but overall it's a pretty sharp edge so
let's zoom in here too so this is now 5
nanoseconds per division so between
these vertical lines here these vertical
gridlines is 5 nanoseconds so you can
see the actual rise time is much less
than 5 nanoseconds for the for the whole
thing we kind of shift things over here
so let's say our rise is starting right
there we're already up to 5 volts within
about you know 2 and a half maybe 3
nanoseconds so measuring what's coming
directly out of the oscillator like this
we've got a really great signal but of
course we're kind of avoiding as much of
the breadboard as possible but with this
measurement technique in reality by the
time our signal gets to our processor it
might be a degraded a little bit but
let's let's take a look at that let's do
that so what we'll do is I'll connect
the clock in to the rest of our clock
signal from the rest of our computer so
that's there and we'll connect that down
to our clock there and so you can see
we're taking the output of the clock and
it's going in or directly into both the
interface adapter as well as up to the
the CPU here and so the question is
going to be what is our clock look like
as it's going into the CPU here so we
can do the same thing I can measure get
this little ground probe into our ground
and then get our regular probe into that
part of the breadboard and that'll
measure the the clock signal up here
and if you notice it's it's really not
that bad again you know this is five
nanosecond per division here so we're
getting you know all the way from zero
volts up to five volts in you know maybe
it's got taken a little bit more time
you know maybe this the slopes not quite
as steep perhaps I'll edit this video to
overlay the two of these so you can so
you can really compare but at least to
my eye looking at this just my memory of
what the other one looked like it looks
like the slope is a little bit less
steep but not terribly so and this is
actually really encouraging because you
remember that when we were looking you
know theoretically at the just doing the
math we needed you know 100 megahertz
plus signals to get from zero volts to 5
volts within 5 nano seconds so this is
this is a very steep so we must actually
be able to maintain those those really
high frequency or at least enough of
those really high frequency signals to
be able to get something like this
so this is very encouraging though of
course I've done everything I can to get
the best possible case here you know
obviously I'm using high-quality
breadboards these wires are as short as
they could possibly be and they route as
directly as I could make them route and
I think that is important for the clock
circuit here so if you know some of
these other signals maybe you know you
can have longer wires or whatever but
the clock signal is one where you know
because the datasheet has that spec of 5
nanosecond rise time 5 nanosecond fall
time in order to meet that spec it seems
like it's worth you know going to a
little bit of extra effort to make those
connections nice and neat and as short
as they need to be so everything looks
good and we're running a clock at 1
megahertz so let's reset and it looks
like there is still one problem which is
the our program to display hello world
doesn't actually seem to be working
anymore
so if we reset you know we could try to
disconnect reconnect power but it's just
not working though it is sort of doing
something so let me actually disconnect
and reconnect power disconnect this
reconnect it and you can see the LCD
comes up and it's not initialized but if
we reset the computer so the hello world
program runs you can see the LCD does
appear to initialize you know it gets
set to to line mode the carcere shows up
but it doesn't do anything else
so it looks like there still might be
some sort of problem running the
computer at this higher speed of one
megahertz so what's going on well
there's something I remember seeing in
the datasheet for the LCD controller you
know a while ago when we first hooked it
up and that is that there there are
several places in the datasheet where it
says you have to be sure that it's not
in the busy state before sending an
instruction right and when instructions
being executed no instruction other than
a busy flag read instruction can be
executed the busy flag is set to 1 when
instructions being executed check it to
make sure it's zero before sending in
another instruction you know be sure
it's not in the busy state before
sending instruction and at the time we
first hooked the LCD module up I kind of
glossed over this because we're running
the clock so slowly that there was
basically no chance that the LCD would
still be executing one instruction by
the time we sent it the next instruction
in fact I don't even know if I mentioned
at the time but I do remember seeing
this in the datasheet and making a
mental note that I could you know
probably ignore it while we were running
the clock really slowly but that
eventually I need to come back and
actually add the code to read the busy
flag and wait before sending each
instruction or character to the LCD
module but now that we've got a good
clock signal it looks like everything
else is working because the LCD is being
initialized in the first instructions
sent to the LCD is the one that
initializes it and sets it to two line
display mode you puts it in this state
it's just that all the rest of the
instructions are probably coming too
quickly before it's ready for any of
them so these instructions you know
turning the display on cursor on
clearing the display these party aren't
actually working even though the cursor
is on and the display is cleared it's
just that those are the defaults when
the LCD first powers on anyway and then
of course these commands were it
actually prints each character aren't
working either you know all of these
instructions are being sent so quickly
that the LCD isn't actually done
executing the first instruction before
the rest of them are sent and that's
because we don't have any code to check
for that busy flag and wait to send the
next instruction and the LCD is ready
and at 1 megahertz it's just going too
fast for the LCD so since we've got a
good clock signal I I think all we need
to do is just add the check for the busy
flag and we can do that entirely in
software and that's what I'm going to do
in the next video and remember if you
want to follow along with these videos
you can get all the parts I'm using over
at my website Eater net slash 6502
and for now at least we're still able to
ship kits during the ongoing quran virus
at pandemic and I'll keep my website up
to date if that changes but you know if
you're stuck inside looking for
something to do got you covered
you