Placeholder Image

字幕列表 影片播放

  • In my last video, I optimized this Assembly language program quite a bit.

  • It just prints out Hello World.

  • But it was over 170 lines long because it had tons of redundant code that I was able to remove by factoring it out into a couple subroutines.

  • But then when we tried running the program, it didn't work.

  • And as we saw in the last video, it didn't work, because when the computer jumps into a subroutine, it pushes the return address on to the stack, which is in memory.

  • And then, at the end of the subroutine, it pulls that return address off stacks so it could jump back from where it came.

  • Now our problem is that our computer doesn't actually have any RAM in it.

  • At address 0100 through 01 f f where the stack needs to be, or anywhere else, for that matter.

  • So let's fix that.

  • Let's add some ram.

  • This is the 62 to 56 parallel Ram chip.

  • Which of the 2 56 in the name indicates that it can store 256 killa bits, which, with eight bits per byte, means we get 32 kilobytes of data, so let's hook it up right now.

  • I'm just disconnecting the Arduino Omega Tau just to get that out of the way.

  • We can reconnect it later, but just to make it easier for you to see what's going on, I'll get it out of here right now.

  • And now if we look at the pin out for this Ram chip, we see it's actually very similar, in fact, almost identical to the wrong ship we have, which is which is very convenient because just like the rahm chip, it's got 15 address lines because it's also, you know, 32.

  • We have 32 K rahm and then a 32 K ram, and it's got the data lines, and the pin out is actually exactly the same.

  • So if I want to connect the Ram chip here to the data bus and the address bus, really adjusting to connect all the data lines over and all the address lines over, it's the way the Ram chip is hooked to the address bus and data bus, just the same as the Rahman and everything else.

  • We'll start by connecting power and ground, then I'll connect the address lines and the data lines.

  • Some hooking up, 15 address lines, a zero through a 14.

  • And, of course, we already have thes connected from the microprocessor, a 03 14 hooked to the rahm a zero through a 14.

  • And now I'm just hooking them the same.

  • A zero through a 14 lines over to the Ram chip.

  • Okay, so those are all the address lines connected Now, I just need to hook up the data lines and same thing here.

  • You know, we've got the eight data lines, of course, Already going from the microprocessor to the wrong chip.

  • I'm just extending those same 88 lines over to the Ram chip, and then we go in.

  • Now we've got all of the 15 address lines, plus the eight David lines hooked up.

  • So I've got all of our address and data lines plus course, our power and ground and the only pins now that are not hooked up are the right enable the chip select and the output enable pins.

  • That's right.

  • Enable output enable and chip select those control signals.

  • We need to hook up a swell.

  • So right enables pretty easy because that hooks right to the reed right pan on the microprocessor because the microprocessor has a read right signal that it outputs along with the data bus to say whether it's reading from the data bus.

  • We're writing to the data bus and that goes low when it's writing.

  • And then the right enable is an active low here.

  • So we could just hook that right.

  • Enable signal from the or the right of the rewrite signal from the microprocessor over to the right.

  • Enable input over here on the Ram chip.

  • Here we go.

  • So that's the right enable pin.

  • But how about output enable and chips elect?

  • Well, when do we want the Ram to actually be active?

  • Well, we only wanted to be active when the microprocessor is actually reading or writing from some address.

  • That's within the range for the Ram.

  • And of course, we know we want that to include our stack, which is 0100301 f f.

  • But you know, we want a larger range than that for Ram.

  • So this is the memory map that I've come up with for the computer right now where we've got you know the addresses because there's 16 bits of address coming off the microprocessor, So the address can go from 0000 through F f f f.

  • And right now, the way we've got this hooked up is the Rahm chip is taking up the upper half.

  • So any time that that most significant address bid and, you know, address 15 in time, that is high than the rahm is active.

  • And so the Rahm is taking up addresses from 8000 all the way through F f f f.

  • So the easy thing to do would be just to have the ram enabled whenever the rahm is not enabled.

  • That way, the Ram would take up the lower half of memory and Ron would take up the upper half of memory.

  • The only problem with that is that we need to have some address space here for for Io.

  • And in previous videos, we have this versatile interface adapter hooked up here on address 6000 through six years, their F 16 addresses that it responds to.

  • So we can't just stick our ram on this whole first half here, so the sort of easy thing to do is just to take up the first quarter of the address space with RAM from 00023 FFF.

  • Which means, you know, even though this is a 32 K RAM chip, it could potentially provide 32 k of address space.

  • We're actually only gonna use 16 K, and the reason to do that is, is, you know, frankly, because it's just easy to d'oh Essentially, what we can do is we can say, you know, the ramp should only be active when Address 15 and address 14 are both zero because of address 15 and 14 or zero.

  • Then that means were in this range from 0000 through three FFF.

  • So from a hardware perspective, it's It's very easy to detect.

  • When we're in that range and activate the Ram, you might say, Well, that's inefficient.

  • You know, there's there's, you know, we're wasting half of the ram that's on this chip.

  • We also have all of this address space here between fours years or zero and seven FFF that we're not using, except for the 16 addresses for for Io here and, you know, fair enough that is somewhat inefficient.

  • But you know, the trade off that we're making there is that the address decoding is easier.

  • You know, if we were to try to detect, you know, when the Rams should be active throughout this entire space except for that one little block there for Io Or maybe, well, maybe a little bit extra.

  • Um, the address decode logic that we would need to build to do that would be more complex.

  • And so there's a trade off to be made there, you know, how complex do we want her address decode logic to be versus how much Ram do we actually need?

  • And, you know, I think 16 k of RAM is probably going to be enough for anything that we would build with this computer.

  • But, you know, if you end up writing a program for this computer that needs more than 16 k of ram A, I'd be surprised, but being in haIf, it better be a pretty cool program, so I'd love to see it.

  • But until then, I I think no one needs more than 16 cave of memory.

  • So let's let's go ahead and do this.

  • That means right Now, this is what we've got hooked up.

  • Right?

  • We've got address.

  • Zero through address.

  • 14 of the ram hooked up to address your arthritis.

  • 14 of the processor.

  • We've got the data bus hooked up D 0 37 And then we hooked up the reed right pin on the microprocessor to the right.

  • Enable pin.

  • And what we're saying is we want the Ram to only be active when address 15 and address 14 are both low because of both of those are low.

  • Then that means were in this ranger at the first.

  • The top two bits of this address are both zeros.

  • Then that would mean that our address is gonna be somewhere between 0000 and three f f f.

  • So you know, that seems like it be easy enough to do.

  • We could simply hook up something like this because we've got the output enable, which is active low.

  • And we've got the chip select, which is active low.

  • And in order for the ram to actually out put anything on the bus, both of those have to be low.

  • So if we hook output unable to address 14 and we hook chip.

  • Select address 15.

  • Then the Rams not gonna output anything.

  • Unless where in, you know, again, we're in that range of, you know, that we want the ram to be from 0000 through three f f f now.

  • Technically, if address 14 is high and address 15 is low.

  • So we're in this range, then output enable wouldn't be active.

  • So would the ram would never out put anything on the bus, but potentially if if the processor is writing to an address in that range, it would actually write to RAM.

  • But, you know, we don't really care about that cause would be writing to a part of the ram or not using.

  • So that's fine.

  • So this this seems like it would be a pretty good approach.

  • Just hook address 14 brother microprocessor up to the output.

  • Enable signal and hook.

  • Address 15 up to the chip select signal.

  • And this should ensure that the ram is active on Lee in this address range.

  • Ah, but not so fast.

  • All this sounds good, but of course, reality is always a bit more complicated if we look at the data sheet for the 62 to 56.

  • The Ram chip.

  • It's got these timing diagrams that show various limitations in the timing of signals when doing a read or write under very circumstances.

  • And the 65 to processor also has timing diagrams where that show very slimming limitations.

  • And you know, we ought to take some time to study these timing diagrams to make sure we understand what those various limitations are to make sure that we're meeting them.

  • Otherwise, we could end up with them really hard to debug problems down the road.

  • For example, this is the reed cycle timing diagram for the Ram chip that we're using and what it's showing us isn't showing us how we would actually do a read from the Ram chip and you think about how Reed would work.

  • You think?

  • Well, okay, the microprocessor wants to read some data from the RAM, and so what it's gonna do is what wants to read from a particular address, puts that address out on the address bus, and that's what these green wires are.

  • And so those air hooked up ways hook those up to the ram.

  • So the Rams gonna have that input there from those address lines saying, OK, this is the address one read from, and then ultimately what we want is they want the Ram chip to then output.

  • Whatever data is stored at that address on the data bus, which of these blue wires that'll go back where the microprocessor could read it?

  • So on the surface, that seems pretty simple, right?

  • The microprocessor puts an address on the address lines, and then it reads the data from the data lines.

  • And of course, there's a couple control signals.

  • It also needs to get set up.

  • So the reed right signal that we just hooked up that's hooked up here to tell the Rand reading, not writing on.

  • And then we have the CIP Select and Output enable that activate the Ram when we're in the right range.

  • But it's not quite so simple, is just setting all those address lines and control signals and then immediately reading because it might actually take the Ram chip a little bit of time to get the data and haven't output on that on the data bus.

  • In a way, that is, that is valid.

  • And that is actually ah, bit of ah sort of an access delay that the Ram chip imposes.

  • So when the processor sets the address, it wants to read from and sets the control signals on the bus, the president actually still wait a little bit before it can read the valid data from the Ram.

  • And that's what this timing diagram is showing us.

  • What this is showing is that, you know, as time moves from left to right here, the process has got to set up the address lines before it can read the data.

  • And what what?

  • What we're seeing here is this is a representation of all 15 address line because the processor may not even set all 15 address lines instantaneously at the same moment.

  • But what this says is that at this point here, they're all set correctly, and what it says is a little bit later, The trip select line is set low, and then a little bit after that, the output enable Linus set low, and then we have to wait some additional time before the data is finally valid.

  • And in our case, we're saying Trip Select is connected to a 15 and output enable is connected to a 14 But notice that, you know, once the address line address is set correctly and the chips elect is low and the output enable is low, the Ram chip doesn't immediately spit out the data.

  • That's at that address.

  • It actually takes some amount of time before it starts spitting out any data and then a little bit more time before it actually spits out the right data.

  • The question is, how much time does it actually take here?

  • You know, we can see sometimes marked here.

  • So there's this ta a from when the address is set to when the data is valid, there's a T A C s from when chips like goes low toe when there's valid data.

  • And then there's this t o E.

  • From when output enable goes low toe when there's valid data.

  • And really, since both of these in our cases are connected, address lines a 14 and 15 we can really think of all of these things.

  • All of these events kind of happening at the same time because at some point the process is going to get the address set correctly and they'll have a valid address, including a 15 and a 14.

  • And so then the time between when the processor sets that address and when the data is valid is just whichever is sort of the longest of those three times, you know this Ta the t A C s or the T o e.

  • So what are those times?

  • Well, data sheet has this other table here for the read cycle times for under a sea characteristics.

  • And here we got TA, which is address access Time T A C s, which has chips elect to access time and T o E, which is output unable to output valid.

  • And each of those has a couple of times, depending on which actual, particular variety of the chip were using.

  • And I think I'm using the Dash seven version or actually says Dash 70.

  • But I I think that means we're looking at this middle column here, the Dash seven.

  • So those three times are 70 nanoseconds, 79 seconds or 40 nanoseconds.

  • The last one's a little bit quicker.

  • It doesn't matter.

  • We still have to wait for the longest of them, which is 70 nanoseconds.

  • So that means when the processor wants to read data for memory once it's set the address lines, including address 14 15.

  • In our case, it could take up to 70 Nana seconds before the Ram chip actually spits out valid data.

  • So how do we know if that's gonna be a problem for the 65 02 microprocessor?

  • Right?

  • Because you know, if there's any chance that the microprocessor sets the address lines and then tries to read the data right away without waiting that 70 nanoseconds, then you know there's no guarantee it'll read the right thing from Ram, and you know this is gonna work, right?

  • So how do we know if that's gonna be a problem or not?

  • Well, the data sheet for the 65 02 also has a timing diagram, and we could take a look at that to see what it expects.

  • And I have to say this timing diagram here is a little bit confusing when you first look at it because they've essentially tried to combine a bunch of different scenarios into a single timing diagram.

  • So it could be a little bit challenging to figure out exactly what parts we care about.

  • You know, if we look back at the time and diagram for the Ram.

  • This is nice because it just there's a single timing diagram here just for Reed.

  • And they actually have separate time in diagrams that cover writing and other things in different scenarios.

  • Where is here?

  • They try to give you just one timing diagram that covers every possible scenario.

  • We've gotta just figure out which parts of it we care about.

  • We're interested in reading data, right?

  • So the process is going to set the address lines a zero through a 15 and then it's gonna read from the data bus so we can actually ignore the right date.

  • A part of this.

  • We can ignore this set overflow bit.

  • We can ignore the interrupt request stuff and basically all this other stuff.

  • And so that tends to simplify things quite a bit.

  • We're just looking at this top part here and then at the top, we have this fee to which is the system clock.

  • And so we certainly care about that because the clock drives the timing for everything else.

  • So we definitely care about that.

  • And now for the 65 02 processor that I'm using, the Western design W 65 Caesar or two.

  • It supports a clock speed up to 14 megahertz.

  • But, you know, I'm ultimately planning on just running it at one megahertz.

  • So that means each clock cycle.

  • So from the falling edge here to the falling edge here is gonna be 1000 nanoseconds, right?

  • If we're running at 11 megahertz.

  • So if this is time zero here, this would be 500 here and then 1000 nanoseconds over here.

  • And I think it's helpful to write in some of these times that we know for our design to help make sense of what this diagram is telling us.

  • So to start with, we can see there's some timing limits shown for the clock.

  • So there's this T p w l and T P W H and P W L refers to pulse with low.

  • So how long this low part of the clock can be?

  • And P.

  • W.

  • H refers to pulse with high, which is how long this high part of the clock cycle could be.

  • And if we look at the table here on previous page, we could see a clock pulse with high clock pulse with low, and it says that the minimum is actually 35 nanoseconds.

  • Actually, the timing is interesting.

  • It depends on the voltage that you're running it at.

  • So we're running at five volts actually gives us faster times, but at any rate, clock pulse with high and low or both 35 nanoseconds.

  • And that's actually what creates the limit of 14 megahertz for this processor, right, because of each clock cycle is 35 plus 35 nanoseconds or 79 seconds for each clock cycle.

  • That means you can have about 14 million clock cycles per second.

  • You know, each one takes 70 nanoseconds any any more than that, and you'll violate.

  • You know, this timing limitation?

  • Well, I guess if you're into over clocking, you could give it a try.

  • Hope for the best.

  • But in our case, of course, we've got other limitations, right?

  • Because, remember, the ram, um, can take up to 79 seconds just to spit out data once it gets a valid address.

  • So forget about any other timing limitations that might be in here if you know, just getting just just just when we read data.

  • If we have this 79 a second wait in here.

  • Um, then, you know, clearly our entire clock cycle is gonna have to be more than 70 Dana seconds.

  • So we're not gonna be able to run this at 14 megahertz with with this ram chip.

  • But one megahertz.

  • We've got 1000 nanoseconds to work with per clock cycle, which, which will hopefully work, assuming there aren't any other timing limitations.

  • Um, so let's take a look at the rest of this we're trying to figure out, you know, that once the processor sets the address, when does it read the data?

  • Because what we really want to know is whether we're gonna have a problem with this 70 nanosecond access time.

  • So, you know what we're wondering here is when exactly is the processor setting the address?

  • And then when exactly is it doing the read?

  • And they don't really come right out and tell us that on here.

  • You know, the ram diagram was nice because it says Okay, here's where the address is valid.

  • Here's where the data is valid.

  • Yeah, but the microprocessor doesn't really say that.

  • It has all this stuff here, but doesn't say well is this is the address of out here.

  • Is it valid here?

  • You know what's what's going on here?

  • Where exactly is the data being read?

  • Because you would think that the reed would be at a particular point.

  • Rights gonna set the address and the address will be valid at some point in here, and then it will do a read at a particular point.

  • But they don't really come right out and say that.

  • So we have to do a little bit of detective work.

  • And the clue that they give us is the different time intervals that are marked and what those time intervals are called.

  • So, for example, we've got this t 80 s here, and if we look at the chart, we can see you know, T 80 s is on here somewhere.

  • Address set up time.

  • So tedious is address set up time, and then we've got this Ah, th over here and th is address.

  • Hold time, and then we've got t d s r, which is data set up time for Reed and ah t d h r, which is read a data hold time.

  • And these are these are all important clues because the question I'm asking myself is okay, When is the address actually valid in here?

  • And then when exactly is the CPU actually reading the data?

  • And so finding these times that referred to a set up and hold is an important clue.

  • Because generally when you have set up in hold times those air sort of common terms that refer to how much time before an event, a signal needs to be set up and stabilized.

  • Or how much time after an event, a signal needs to be held in a stable state before it's allowed to change.

  • So because they tell us that this is the data set up time here, this interval here is, you know, data set up for Reed.

  • And they tell us that this is the data hold time.

  • Do you know data?

  • Hold for Reed.

  • We can deduce that there is some kind of important event right here in the middle, right, set up time and then a hold time.

  • And so there's there's some important event here in the middle, and I don't really come right out and say it anywhere.

  • But the only thing that makes any sense is that this moment right here This is the moment where the data is actually read.

  • Because what they do tell us is that the data has to be valid for some period before that moment and has to remain valid for some period after that moment.

  • And if we look at the chart, we can actually see Thea read data, hold tight, or read a to set up time and read a the whole time or both.

  • 10 nanoseconds.

  • So whatever else is going on here, the data has to be set up at least 10 nanoseconds before this point and remain valid at least 10 nanoseconds after this point in order for the processor to reliably read data at that point.

  • So to be able to read data from Ram, the question we need to ask is, is the Ram gonna be out putting data for this entire period?

  • Well, that depends on when the address lines are valid.

  • And again, the clue here is set up in hold times.

  • Except here We see the address set up time here.

  • So this is you know, t 80 s address set up.

  • Time is this period here and then th the address hold Time is up here, so maybe it doesn't look like the setup and hold times are sort of book ending an event like we saw with data.

  • But then there's another, you know, address.

  • Hold time over here.

  • Th So what's going on?

  • Why is there why are there to address hold times here?

  • Well, remember, the clock is cycling on and off, on and off.

  • And so this address hold time over here is actually the hold time for the previous clock cycle.

  • And so what we've really got here is we've got an address, set up time, and then we have some period here in the middle, and then we have a whole time and again, they don't quite come out and say it.

  • But we've got to assume is that in this case, the setup time is how long it takes the processor to spit out a valid address, at which point the address is valid for this entire period here, up to this moment where the data is actually read and then the address continues to be valid for this address.

  • Hold time.

  • In other words, this section here is where the address is valid, which again they don't quite say is nicely as the as the Ram does.

  • But But we have to assume that based on just knowing that this is the set up time and this is the whole time, we we kind of deduce that so we could do is start filling in some of these times.

  • So let's look at this address set up times the address set up Time is ah, a maximum of 30 nanoseconds.

  • So if this is zero here than this point here, where the address is set up, this would be 30 nanoseconds.

  • And then, of course, it's at 500 a second's the clock pulse goes up and then back down again in 1000 and eight seconds and then our data has to be set up because the data set up time is a minimum of 10 nanoseconds.

  • So this has to be set up 10 nanoseconds before this point here, So that would be at 990 seconds.

  • So that means that from when the address is valid at 30 nanoseconds to when the data needs to be valid at 990 nanoseconds, we've got 960 Nana seconds for the Rams essentially get its act together and spit out the valid data.

  • But of course, you know, that's plenty of time because we saw the worst case for the Ram is gonna be 70 nanoseconds.

  • So no problem getting the data set up.

  • And we got plenty of margin.

  • What about this whole time at the end?

  • Because we need to keep the data valid for some period of time.

  • Well, we can look back at the data sheet for the Ram, and you can see that when the address stops being valid, there is an output hold time here.

  • So where the data remains valid.

  • So if we look at what that is, that's t o H and T O H is output hold from address change, minimum of five nanoseconds.

  • So So this data will be held for at least five nanoseconds after the address changes.

  • So is that gonna be long enough?

  • Well, the processor requires the data to be held for 10 nanoseconds after the point where it reads.

  • But the processor also conveniently has this address hold time.

  • So let's take a look at what these times are.

  • So the address hold time is 10 nanoseconds.

  • Okay, So from after it reads, it'll hold the address valid for 10 nanoseconds.

  • Which means that the Ram will will actually hold the data valid for you know that entire time.

  • Plus, it's hold time, Which is which is another five seconds of the ramble.

  • Hold it for 15 Nana seconds.

  • And the requirement here is that the read data hold time needs to be at least 10 nanoseconds, so that'll be That'll be fine.

  • The Ram will hold the data valid for 15 Nana seconds after the reed point here, even though the processor only requires a toe, hold it for 10 nanoseconds.

  • And that's pretty much the bottom line is that reading from the Ram ought to just work.

  • And, you know, maybe going through all this seems a bit tedious, you know, just to find out that you everything's gonna work.

  • Fine.

  • But it is really important to make sure you understand all these limitations and make sure you're staying within the margins because, you know, if you're close to the edge on some of these margins, you might have something where you build it and it works.

  • Fine.

  • But then the temperature changes or something changes the voltage fluctuation.

  • Something like that.

  • And it's just enough out of spec that it starts behaving strangely, and you can quickly find yourself in a situation that's pretty much impossible to debug.

  • So it's important to really dig into the data sheets for hardware you're using and understand all the limitations that are involved and make sure you're not exceeding any of those limitations.

  • For example, let's take a look at writing to the Ram and see if that's gonna work.

  • If we look at the timing diagram for writing to the Ram chip, we see something similar.

  • Address lines are valid here, and then Chip Select is low, which for us is just a 15 address 15 and then this entire diagram assumes that output enable is low.

  • So for us, that's a 14.

  • So by this point, the processor is set up the address it's writing to, and then we see the right enable signal going low.

  • And you know this comes from the reed right signal from the processor.

  • So the processor says it's writing, and then it looks like the data on the bus here.

  • Valid data is actually written to the Ram over here at the end of the right enable pulse, cause it seems like we have kind of, ah, period of validated here.

  • And they're sort of a set up and hold style thing here and then right when that right pulse goes high, that seems to be right in the middle there.

  • So that seems to be the puke.

  • The point at which the data is actually written to the ram.

  • And if we look at the times for all of this, we can see this T c w So when the chips select goes lows at this point, our address is valid to the actual time where the right happens.

  • This T c W chip selection.

  • End of right is a minimum of 60 Deanna seconds.

  • Okay.

  • And then the right enable pulse.

  • Here.

  • This t W P is a minimum of 59 seconds, and then we've got the data set up time and date.

  • A hold time.

  • So the data set up Time is a minimum of 30 nana seconds, and the data hold time is a minimum of zero nanoseconds.

  • Oh, that seems to fit very comfortably in our 1000 a second clock cycle.

  • but not so fast.

  • It's really tempting to assume this will work, but let's take a closer look.

  • So when does the right actually happen?

  • Well, it looks like right enable goes low.

  • Then there's this period here, this right pulse time and it looks like the right is happening here.

  • So you know this right?

  • Pulse time is a minimum of, Ah, 50 Nana seconds.

  • So does that mean that the right is happening after 15 seconds?

  • Or does that mean that the right is happening at the end of this right pulse?

  • However long it happens to be, even if it's more than 15 seconds because 59 seconds is the minimum, there is no maximum.

  • Well, if we look here, there's a notes column and note for down here, says a right occurs during the overlap of a low chip select and a low right enable a right begins at the latest transition of chips like going low or right enable going lo and then a right ends at the earliest transition of chips.

  • Select, going high or right, enable going high.

  • So this says a right occurs during the overlap of low chip select and low right enable.

  • So any time chip, select and right enable are both low.

  • So this entire period it says it's writing and it says the right ends at the earliest transition of chips, select or right enable going high.

  • So the right ends at this point.

  • But the right is happening this entire time, I guess from from this point here, where both of these air low to the end here, where really either of them goes high.

  • What does that mean?

  • If it looks like at least during part of this right, there's either no data on the bus or there's no sort of garbage data on the bus.

  • What does that actually mean?

  • Well, that's actually fine, because if there's nothing on the bus, then the Ram might be storing random garbage.

  • Or if there's incorrect date on the bus, the Ram might be storing the incorrect data.

  • But at the end of the day, once the data becomes valid in the RAM stores, the valid data, that's really all we care about.

  • That's what we want.

  • You know, we just want the valid the right data to be stored at the right address, and that's what they're showing here is they're showing that for some period of time you could have no data on the bus or its fine its And that's fine.

  • And it's fine to have garbage gate on the bus as long as the right data shows up during this period.

  • You know, 39 seconds before the end of either of these pulses, then the rights gonna work.

  • Now, if we look back at the timing diagram for the CPU and here we're interested in the right data portion here, we can see the address becomes valid here, Right, Because this is our address, set up time and the address becomes valid at this point, and and actually this point, the right data might be invalid.

  • But that's fine, because the data becomes valid over here, and at this point, the address is still valid.

  • So for this part of the Wright cycle, we were writing the right data to the right address for the correct dated to the correct address.

  • And then over here the same time, the address becomes invalid, the reed right signal becomes invalid and the data becomes invalid.

  • So basically everything becomes invalid at the same time, so Is that gonna cause us any problems?

  • Because, you know, we've got our addresses are read, right.

  • Signal everything becoming invalid at the same time as the data.

  • Where is here?

  • We have Chip Select, which is address 15 and right.

  • Enable, Which is, you know, our read right pin.

  • Those are becoming invalid.

  • Seems like before the address becomes invalid or before the data becomes invalid.

  • So is that a problem?

  • You know, what about this right?

  • Recovery time is T W r.

  • This data hold time.

  • TDH Well, if we look at right recovery time t w r.

  • It's a minimum of zero nanoseconds.

  • And if we look at data, hold time TDH.

  • That's also a zero.

  • A minimum of zero nanoseconds.

  • So if this time is zero Nana seconds this time zero Nana seconds then it seems like all of this going invalid at the same time oughta work, right?

  • Well, actually, it doesn't.

  • There's a subtle detail in here that it's actually really easy to miss.

  • And if you want to challenge, I'd encourage you to pause here and see if you can figure out exactly what the problem is.

  • Well, if you did pause and you've given it some thought.

  • 11 clue is that this data recovery time and this data hold time.

  • And I said, There's zero Nana seconds, but the limitation that's that's published here is actually that they are a minimum of zero Nana seconds, and that's that's really important.

  • It can't be less than zero nanoseconds.

  • In other words, this chip select and right enable have to go high before any of these other things change before any of the other address lines changed before any of the data changes.

  • And in our case, since we're saying the chip select is connected to address Line, 15 were saying address 15 has to go high at least zero nanoseconds before any of the other address lines change.

  • And you know, that's that's not guarantees.

  • The processor just says, You know, up until this point here, all of the address lines will be valid for for this clock cycle.

  • But then at this point they'll start changing for the next clock cycle.

  • But it doesn't say address 15 is gonna change before all the other ones, and there's so there's no guarantee that the chips like line, which we've hooked.

  • Address 15 is gonna go high before the address becomes invalid.

  • And same thing with the right enable signal, right, Because we're hooking are right.

  • Enable signal up to the reed, right pin on the on the processor and in the timing diagram here, they've just lumped this read write signal in with the rest of the address lines.

  • So again, there's no guarantee that the Reed right signal is gonna change before the address lines either.

  • So neither of these is necessarily going to go high at least zero nanoseconds before the address becomes invalid.

  • And that's bad.

  • Because if these air delayed and the address changes first, then we'll still be writing data.

  • But whatever data we've got, valid or otherwise, whatever it is is gonna be written to some invalid address.

  • Because if the's address lines start changing and we're still writing, we're just gonna write to whatever they change, too.

  • And so we'll just be writing, you know, arbitrary data into sort of random addresses and and we certainly don't want to do that.

  • And that's gonna be a big problem.

  • And actually, it's worse because we have the same problem at the beginning of the right to because we have this address set up time here which says that the address has to be valid before either chip select or right enable goes low.

  • Because again, if both of these happened to go low too early, then the Ram could just start writing whatever garbage is on the data bus to whatever garbage address is on the address bus and again that will just end up corrupting some random part of memory, which is definitely a bad thing and would be no fun to troubleshoot.

  • How do we solve this?

  • How do we make sure you got all these address lines and all these address lines and the reed right line?

  • Everything all set up before the chips like line goes low.

  • So the address is valid, you know, right around here, Um, could we somehow delay the chip select line going low until, you know, maybe somewhere a little bit later and then same thing in reverse.

  • Could we have the chips, like line go high a little bit before the address and data?

  • Uh, where's the data become?

  • Invalid.

  • So maybe right around here.

  • So that would actually kind of work if we could ensure the chip select only goes low in this interval here, sort of between this line and this line.

  • So So how could we do that?

  • Well, what are these lines?

  • These lines correspond to, uh, this fee to which is the system clock.

  • So that's actually very convenient, because we have this nice signal that is only high during this little interval here.

  • And, of course, our address on and and read right signal are valid, you know, well before that and a little bit after that.

  • So if we could somehow make sure that our our chip select, which is address 15 if we could somehow make sure address 15 only goes low during this interval here where the clock is high, then that ought to solve our problem because that ought to ensure that Chip select goes low after the address is valid and it goes high before the address becomes invalid or before the data becomes invalid.

  • So, as is often the case, understanding the problem is the hard part.

  • But the solution and actually turns out to be pretty straightforward.

  • We've had to make sure Chip Select doesn't go low unless the clock is high during this interval, and we could do that with just a few logic gates.

  • So if we look back and how we were contemplating cooking up the Ram chip, we could see, obviously we've got it right.

  • Enable We've got our data, our address lines.

  • And then we had address 14 Going to the output enable an address.

  • 15 going to chip Select.

  • That way, the ram would only be selected when addresses 14.

  • 15 r zero.

  • And remember, we're doing that so that the Ram would only be active when the processors addressing you know, these these addresses here from 0000 through three FFF, which corresponds to win those top two bits or zeroes.

  • But after looking through the timing diagrams we saw, this almost works.

  • Except we have this caveat where we need to make sure that Chip select is only low when the clock is high.

  • And we could do that with just a couple logic gates.

  • And so something like this auto ought to do the trick.

  • And so here at just 14 the same same as before.

  • So, you know, address 14 of course, needs to be zero in order for us to be addressing a ram and 15 also needs to be zero.

  • And so what I'm doing is I'm inverting it here.

  • So when address 15 is a zero, then this will be a one over here.

  • I'm just using a NAND gate to invert because we actually already have this in our circuit, and then I'm ending that with the clock.

  • So if the clock is high and this is high, which means I just 15 to 0, then this NAND gate will output a zero, which will, you know, because Chip Select is active low will select the chip.

  • And so this has the effect of essentially having address 15 tied directly, chips elect, except that it only goes low when the clock is also happens to be high, which should be all we need to make sure we, uh, fit within those timing constraints for writing and, you know, don't find ourselves in a situation where we corrupt data.

  • So you might be wondering if we're adding these to Nan Gates to the circuit.

  • Are they gonna affect the timing at all?

  • And yes, actually they are.

  • Because if you think about what an and it's doing, is it's taking these two inputs and then it's coming up with an output.

  • But that output doesn't change instantaneously with the inputs.

  • There's actually a slight delay, and it's called propagation delay.

  • You can see on the data sheet it says here, typical propagation.

  • DeLay is eight nanoseconds through a gate, and that's not very much, but it's also not nothing.

  • If we dig a little bit deeper in the data sheet, they give us a worst case as well.

  • So they have this maximum propagation delay, and these are actually specified for particular conditions.

  • S o.

  • You know, we're running it at five volts.

  • The ambient temperature is 25 degrees, but but in any event, they do say the propagation delay is typically eight nanoseconds.

  • Guaranteed limit is 15 nanoseconds.

  • And if you really want to take a worst case, you know, if you go outside those parameters, they give you some other things here and they say, Well, if your voltage fluctuates or if your temperature fluctuates, you can actually look up in this table and see how bad it might get is the absolute worst case you Somehow, if our voltage drops all the way to two volts, which would be pretty far, far out of spec for a five fold circuit.

  • And our temperature is within, You know the range all the way from negative 5525 C's.

  • That's a huge range.

  • Yeah, Then propagation Delight could be up 234 nanoseconds.

  • But even assuming you know the voltage drop slightly to four and 1/2 volts air, we're in this, you know, narrower range of minus 40 to 85 which would cover pretty much any normal operating range.

  • You know, it's only 23 nanoseconds, but really, the bottom line is that for us, it doesn't matter.

  • Even if we take, like, a really worst case and say it's 25 nanoseconds and you know we have to Nan Gates in our circuits.

  • So let's say it's 50 Nana seconds from when address 15 changes over here toe Winship Select changes.

  • So 59 seconds to be our worst case.

  • Really?

  • What that saying is we're delaying this chip select line going low by 15 anuses, sort of moving that 15 seconds to the right worst case, and that could effect when the data becomes valid, right?

  • Because that would that would push all of this to the right by 50 nanoseconds if we had a delay in there.

  • And so the data would be valid 59 seconds later than it otherwise would be.

  • But of course, that's no big deal, because we've got, you know, 970 Nana seconds from when our address and everything goes valid to win the right actually occurs.

  • So we've got you 979 a second here to work with So an extra 50 nanoseconds not gonna not gonna affect us at all.

  • And then as faras the delay here because the you know when ships select goes high is also gonna be delayed because address 15.

  • If we're running it through that, let's say worst case 59 a second delay chips, let goes high 59 seconds later.

  • Is that going toe?

  • Put us into this zone where you know, OK, the address is no longer valid and we're writing the garbage data.

  • Well, no, because the right enable doesn't have that delay.

  • It's a right enable will go high on time and the ramble stop writing.

  • So bottom line is even some of the worst case propagation delays here from the Nan Gates aren't gonna cause that big of a deal.

  • But it's definitely something to be aware of because, you know, if we had more complex logic in here or we wanted to run our processor significantly faster than one megahertz, which, of course, would shorten this whole window.

  • So instead of having 1000 and a second to work with, we'd have you know something less.

  • If we wanted to run this faster, those things could start to cause a problem.

  • So if we really wanted to, you know, get a CZ much speed as well as we could out of the processor, then you know, we would have to We have to pay more attention to this, but by planning to run it at one megahertz has a nice, safe speed where this is gonna be quite safe.

  • So with this design in mind, the next step is to wire up these control signals and test everything out.

  • So in the next video, that's what I'll do.

  • I'll connect everything up just like this.

  • And if we got all the timing right, our program with subroutines auto work, as always, I want to thank my patrons for your support in particular for this video.

  • I got a lot of really good feedback before I released it, which I think has made it a lot better.

  • Anyone who supports me on Patri on gets early access to videos before they're released.

  • And in fact, much of the next video is already available to patrons.

  • Right now, If you go to a patriot in dot com slash ben eater and support my work for just a couple dollars, you'll get access to it.

  • And again, thank you.

In my last video, I optimized this Assembly language program quite a bit.

字幕與單字

單字即點即查 點擊單字可以查詢單字解釋

B1 中級

RAM和總線定時 - 6502第6部分 (RAM and bus timing — 6502 part 6)

  • 9 0
    林宜悉 發佈於 2021 年 01 月 14 日
影片單字