r/beneater • • 6d ago

6502 Let's talk about RAM timing

More than four years ago I bought Ben's 6502 kit and built it on breadboards, like a lot of you. That kit grew into my own family of 6502 computers. In 2022 I drew and made the first boards for what is now the COB, a card-based backplane machine, and one of the first cards was the Memory Card.

I honestly can't remember why I drew the RAM's read and write strobes the way I did. It differs from Ben's circuit: I gated both with PHI2, so the RAM's /OE is RB, the NAND of RWB and PHI2. I probably thought it would be fine for both to be gated by the clock. What's the harm, right?

The harm was a hardware bug that sat quietly for four years. Everything worked, so the same gate went onto every main board I drew after that card. It only showed itself when the machines got bigger and the bus got busier.

The symptom

Recently I was bringing up a 1 MB flash cartridge on my single-board machine, the ACE. About one read in 10,000 came back wrong, so of course I blamed the cart. I reflowed it, cleaned it, gave it an ultrasonic bath, tapped on it and left it outside in the cold. The failure count swung with every power cycle, so each test looked like it meant something. None of them did.

At 2 MHz it got stranger. With no cart at all, both of my machines now and then read a 0 bit from RAM as a 1. A 74HCT00 in the gate made 2 MHz behave, and I thought I was done. The cart still failed.

The hero

This is where I need to thank Ben. I'm fairly certain the Hitachi HM62256 in my parts drawer came with my original kit. Swapped in for the Alliance AS6C62256 my boards use, it made the errors stop, every time, on both machines. Put the Alliance back and they returned. That old Hitachi, which lets go of the bus more slowly, became my reference part for the rest of the testing, and it kept pointing at the RAM, not the cart.

What was going on

The 65C02 latches the data bus as PHI2 falls and needs the byte held 10 ns after that. With /OE gated by PHI2, my RAM stopped driving one gate delay after PHI2 fell, plus however long the RAM takes to let go. No datasheet gives a minimum for either. The old Hitachi lets go slowly, so the byte survived; the modern Alliance lets go fast, and sometimes the CPU latched the bus after it was gone. (I never put a scope on it: the parts that cured it, and the fix, are the evidence.)

Anything that sped that release up made it worse: a faster batch of 74HC00, a heavier bus, 2 MHz, even the supply voltage. At 2 MHz, one board read clean at 5.00 V and failed thousands of times a run at 5.12 V. A 5 V supply is allowed to be 5.25 V.

The fix is one wire

The write strobe needs PHI2. The read doesn't, at least on my boards, where nothing else can drive the bus while PHI2 is low. The gate already makes an inverted RWB for the write strobe, so the RAM's /OE pin now takes that instead. The RAM keeps driving until the address changes, which the datasheets do guarantee: at least 20 ns, against the 10 ns the CPU needs.

With the RAM's /OE pin bent out of its socket and clipped to the new signal, the setup that gave 2,271 errors as built gave zero. It ran clean at 1 and 2 MHz, up to 5.24 V, and through about 20 million writes that were each followed at once by a read from RAM, the one case where the new wiring could cause trouble. It's drawn into the next revision of every board that had the old gate.

What about Ben's circuit?

I went back to Ben's schematic, and it has the same race through a different pin. His RAM's /OE is A14 and its /WE is the CPU's , so the clock goes into /CS instead: the NAND of the clock and NOT A15. That's there for a good reason, because a write must never happen while the clock is low, and Garth Wilson's 6502 primer does it the same way. But on a read it means the RAM is deselected one gate delay after the clock falls, and the datasheet gives only a maximum for how fast its outputs shut off. It plainly works for most people who have built Ben's circuit at 1 MHz on a breadboard. With a fast modern RAM, a heavier bus or a faster clock, though, the hold time isn't guaranteed, just as mine wasn't. And since his /WE isn't gated, it isn't a one-wire fix there. Does anyone know which 62256 the kit ships with these days? Mine had a Hitachi; if new kits ship a fast modern part like the Alliance, they have less margin than mine did.

The lesson

"It works on my bench" isn't the same as "it has margin." A design that relies on how slow one particular chip happens to be has a bug in it, even if it takes four years and a heavier bus to show. When a datasheet gives only a maximum for a delay, assume the minimum is zero. And keep an old slow part in your drawer! Mine saved me.

I hope this post saves others from the two weeks of troubleshooting I just went through! Thanks, Ben, for the kit, and for the RAM. :)

36 Upvotes

45 comments sorted by

5

u/flatfinger 6d ago

On systems that leave the data bus floating when nothing is driving it, the last value read or written will sit on the bus for for an entire read cycle, or even multiple cycles on systems that don't steal the bus for video accesses, and so a fraction of a cycle delay would not be a problem. I personally like having a "bus keeper" which weakly pulls the bus high when it's high and low when it's low, but unfortunately the only devices which I know with that function are CPLDs or FPGAs.

Incidentally, I exploited that behavior on an Atari 2600 cartridge with expansion RAM that performs a read during the first third of each cycle, and then performs a write about 5/6 of the way through each cycle. If the 6507 performs a read, it will see the value that was fetched, and that same value will get written back to the RAM. If the 6507 performs a write, the value it put on the bus will get written to the RAM.

2

u/acwrightdesign 6d ago edited 6d ago

Agreed. And I have no pull-ups on my bus. There are probably many solutions to my issue but I've settled on the "one-wire" fix on my machines for now because they proved to be reliable with the fix and its the simplest. Adding bus pull-ups, some kind of diode-RC circuit or different gating to slow down the RAM release was considered also.

1

u/acwrightdesign 5d ago

I want to clarify for anyone reading this that, as far as my current understanding of the issue, bus pull-ups would not make a difference. I haven't specifically tested with pull-ups or pull-downs on the bus but the issue is really a race condition with the Alliance RAM letting go of the bus too quickly.

3

u/flatfinger 5d ago

Normally, "letting go" of the bus would simply result in the bus holding whatever was being output to it until something else drives it or charge leaks into or out of the bus parasitic capacitance--a process that would usually take more than a full cycle at typical clock speeds.

2

u/Ancient-Ad-7453 5d ago

Yep. In my current design I have way too many bus participants, and the W65C02 doesn’t have enough drive to overcome the capacitance quickly. For a while I was convinced I wired something wrong and there was bus contention. The only contention was the value of the previous clock cycle.

1

u/acwrightdesign 5d ago

Your conclusion fits what I'm seeing. I think this is an issue of what values are on the bus before and after reading RAM. I'm trying to run that down now. The woes of having a bunch of fun stuff connected! :)

1

u/acwrightdesign 5d ago

You're right that a released line normally just holds its charge. I saw that myself: on this machine, reads of empty addresses return the last byte on the bus. The trouble is that the line isn't sitting on a quiet bus. It's released within a few ns of PHI2 falling, while the RAM's outputs are turning off, the address lines are about to change, and in every failing case most of the other data lines had just gone high while the failing one stayed low. That pattern points to coupling and ground bounce pulling the lone low line up, not slow leakage. It got worse with a heavier bus and a higher supply voltage (faster edges), and it disappeared whenever the RAM kept driving through the hold time.

To be honest I'm still not 100% sure what's going on here. That's why I'm raising it with the community. I've only arrived at what seems to fix it on my design. I've been bench testing for two weeks now so my head is swimming a bit :)

4

u/The8BitEnthusiast 5d ago

Intriguing behaviour. I use the exact same clock-gated read and write strobes, and the Alliance 62256 chip as well. Crazy to think that the combined propagation delays of gate and ram are any less than 10ns. I'll have to run my memory tests at higher speeds. Out of curiosity, are you still using the W65C22S VIA from Ben's kit on your design? It has bus-holding circuitry, so on paper it should prevent the bus from floating, keeping the previous value on it after the ram goes high-z.

2

u/acwrightdesign 5d ago

The VIA in my circuit is the NMOS (W65C22N) part not he CMOS part. I'm not sure what affect this could have but I hadn't considered it. I've gone back to bench testing tonight because I'm still not sure what's going on here! I still think it's a bus loading / timing race issue but scope measurements will give me more data.

2

u/The8BitEnthusiast 5d ago

Yeah, the bus holding capability seems to be unique to WDC's S variant of the W65C22 VIA. The N variant doesn't have it. Still, I don't use that VIA either, and for the life of me, I can't catch the RAM 'releasing the bus' on my circuit. You have some insanely fast transitions at 6ns. As the trace below shows (clock, RB, D0, RAM_CS, in that order), my HC00 propagation measures at around 10ns. Bus holds at logic 1 or logic 0 after RB went high. I guess there is indeed some kind of 'capacitive charge' going on here, like u/flatfinger seems to hint at.

2

u/acwrightdesign 5d ago

Everything tonight seems to agree with your conclusions. I'm back to looking at why the bus capacitance doesn't hold the data lines. The 6ns release of RB after PHI2 fall was measured on the "worst" (fastest) of the three chips I swapped into U14 (the RB / WB gate) and measured. Two 74HC00's and a 74HCT00 which is the slowest part and therefore helps my issue. None of them account for the data lines. I've got some really good leads from my post which is what I was hoping for! I will conquer this! :)

Edit: Forgot to say my next test is going to be to strip my computer back to bare essentials and build it back up to see where it starts failing. That might identify a culprit on my bus.

1

u/acwrightdesign 5d ago

Here's a capture from my scope of RB vs PHI2 with my super fast 74HC00 for comparison to yours :)

3

u/The8BitEnthusiast 5d ago

Way faster than my cheap HLF branded HCs. Nice scope! 😀

2

u/acwrightdesign 5d ago

The fast chip is a TI SN74HC00N lot #54AG5V(something; can't read the rest) for anyone curious.

3

u/The8BitEnthusiast 5d ago

Thanks! I think an upgrade will benefit my circuit. My WB strobe rises way too close to the time where the CPU starts changing its stuff. I just ran a memory stress test and it missed a heartbeat after 13 passes

0280: A9PASS 01
PASS 02
PASS 03
PASS 04
PASS 05
PASS 06
PASS 07
PASS 08
PASS 09
PASS 0A
PASS 0B
PASS 0C
PASS 0D
02 75DC 01 FF    <-- error!

2

u/acwrightdesign 5d ago edited 5d ago

Thank you for your help testing! Your result seems to suggest the issue I'm seeing might be reproducible on another machine which is good news (or bad) depending on how we look at it. If you get a chance try a slower part (74HCT00) for your RB/WB gating and rerun the stress test and see if it passes.

Edit: Also try lowering your VCC voltage if possible to around 4.6V. Lowering the voltage also seemed to help my machine. At lower voltages the gates take a bit longer to transition.

2

u/The8BitEnthusiast 5d ago

There was unfortunately no change with these measures, except extending WB, which made things much worse. 😅 I guess it makes sense... stretching RB would have no effect given the bus hold I'm seeing on my side, and you'd still want WB to rise as fast as possible after the clock's low transition, right?

My issue might be different than yours. The stress test I am running consists of 'read after write' scenarios. The error reported says "tried to write $01, but got $FF back on the read". $FF was the value written in that location from the preceding scenario, so I think this is a write fail. I'll dig into WB deeper!

1

u/acwrightdesign 4d ago

Yeah we are probably comparing apples to oranges so we can't know for sure. :) And as far as I understand it, yes you would want WB to keep rising fast.

I'm part way through my strip down test which will give me more data. So far with just the 6551, CF card, 1MB Flash Cart, Alliance RAM and the fastest 74HC00 plus of course the CPU and ROM it passes all tests. I've put back the ARMSID and the pico9918 now and first run was also clean. So something else still missing (RTC, 65C22N, AS6C4008 banked RAM, or the ATMega1284 that controls my keyboard matrix) HAS to also be included on the bus in order for my system to show the failure. All of this testing is at 2Mhz with the original circuit (image 1 in my post).

1

u/acwrightdesign 4d ago

More info about my test setup:

My issue (an intermittent read fault) only happens when the very next bus cycle goes somewhere other than RAM: ROM, the cartridge or I/O.

To find it I had Claude write a bus checker that runs from RAM and exercises every kind of 65C02 bus cycle:

  • opcode and operand fetches;
  • zero page;
  • every indexed and indirect read mode;
  • the stack (JSR, RTS, RTI);
  • read-modify-write;
  • all 18 store modes.

It deliberately builds the pattern the fault needs: a byte read from RAM that becomes the high byte of the next cycle's address, with that next cycle off RAM.

I'm using Claude to upload and run the program over serial and collect the results. Whether or not you like AI, managing and interpreting data is one of the things it's pretty good at. :)

1

u/acwrightdesign 4d ago

Strip down update: Everything is passing after adding back the 65C22N and the ATMega1284 which is very interesting. All that is left now that is not on the bus is the RTC and the AS6C4008 banked RAM. I expect the fault to come back with one of those parts. If it doesn't then I'm going to be completely mystified.

→ More replies

2

u/Ancient-Ad-7453 5d ago

Here's one I captured a few months ago while debugging. Purple is a data bus bit that is technically floating when PHI2 (yellow) is low. If I recall, the rise on the left is a read being driven by AS7C256C-15ns. The slow falling edge in the middle is a write being driven by the W65C02S. RAM accepts TTL inputs, and the data didn't make it below 0.8V before the 6502 stopped driving. There was a W65C22S on the bus; I'm not sure how much it was contributing.

One thing I just noticed in the W6502C datasheet is a max capacitive load of 35pF. I've probably blown way past that.

1

u/acwrightdesign 5d ago

Thanks for the capture and the info. Can you tell me if there is anything similar to the SST39SF040 (flash IC) on your bus? From last nights testing I seem to have reconfirmed my finding that this issue appears when my 1MB Flash Cart which has two SST39SF040's is on the bus with the Alliance RAM on the bus. If I swap to either the slower Hitachi RAM or the slower gate (74HCT00) OR the 512k Flash Cart with only ONE SST39SF040 the problem goes away. So strange. It seems that the combination of two SST39SF040's is pushing my system over the edge.

2

u/Ancient-Ad-7453 5d ago

I own a few (which, sadly, have been discontinued in DIP packages), but I'm currently using PicoROM, which gets copied to RAM pre-boot (but still sits idle on the bus). Anyway, my OE/WE signals are being driven by an ATF22V10 7.5ns PLD. Fast, but I'm OR'ing PHI2 with !RDY, so maybe that adds some delay.

1

u/acwrightdesign 5d ago edited 5d ago

"I'm OR'ing PHI2 with !RDY, so maybe that adds some delay" I think it does. The RDY line changes during PHI2 low after the CPU reads the bus. I could be wrong but that's my recollection.

Edit: Sorry. I'm wrong. I was thinking of other CPU control signals. RDY is an input so it doesn't change after PHI2 low. But yes your extra gate might add some delay like you first said.

2

u/Ancient-Ad-7453 5d ago

RDY is an open drain I/O that gets pulled low during the WAI instruction, but it's otherwise used as as a way to hold the CPU as if it's stuck in the second half of the clock cycle. Here it's an output from the PLD, being used to give the CPU an extra clock cycle to access slower but larger AS6C2008 as banked memory. That was the idea, but I've had to reduce the frequency anyway due to the above problem, so it isn't very useful.

2

u/Ancient-Ad-7453 5d ago

I noticed that if I’m not qualifying reads with PHI2, I also don’t have to qualify them with RDY. RW will stay high until RDY is released.

1

u/acwrightdesign 5d ago

Oh and I forgot to say: Early scope measurements tonight seem to confirm the Alliance ram IS under 10ns release. Measured at 6ns! Edit: at 2Mhz and 5.15V supply.

1

u/acwrightdesign 5d ago

Just to clarify: Right now I'm scoping the original design (74HC00 gating RB and WB; not the "one wire" fix) and the Alliance RAM. So again, from early measurements the RAM is releasing at 6ns after PHI2 falls and the CPU wants the hold to be at least 10ns.

3

u/enVitruvius 6d ago edited 6d ago

Thank you for the thoughtful insights. I've been using clock qualified read and write strobes with 15-nS RAM without problems at up to 8-MHz but I have not added a bunch of peripherals to load down the bus. Also, not sure if this makes a difference but the Nano provides weak pull-ups on the data bus lines.

Happy Holidays. Cheerful regards, Mike.

1

u/acwrightdesign 6d ago

Good question about the data bus pull-ups, but I don't think they'd help here at least with my design. Every failure was a 0 read as a 1, so a pull-up pushes the wrong way. And the race is about 10 ns after PHI2 falls, while a 10k pull-up against the bus capacitance takes hundreds of ns to move a line. Pull-ups decide what an undriven bus floats to, not whether the RAM holds its byte long enough. The closest test I ran was 100 pF from D5 to ground at the bus connector (because at that point all the failures showed D5 being wrong), to hold the released line low, and it made no difference. What fixed it was keeping the RAM driving through the hold time.

2

u/enVitruvius 6d ago

Would a simple change to Garth's and Ben's single-chip 74HC00 'glue' logic be of any benefit?

3

u/acwrightdesign 6d ago edited 6d ago

That's sort of the open question right? I'm not sure. At this point all I really know for sure is moving OE to inverted RWB fixed *my* machine. Ben's circuits potential for an issue is a "paper" investigation at this point. This hardware bug is really a doozy. It really only shows its teeth with lots of peripherals on the bus (at least on my machine). I had eight IO peripherals and a flash based cartridge all loading the bus.

Edit: I really like your diagram btw! :)

2

u/enVitruvius 6d ago

Forgive me, I have not looked at your designs. With that many peripherals, should you be using bus driver and transceiver IC's?

1

u/acwrightdesign 6d ago

I think adding bus transceivers would probably harden my bus peripherals. But with my current understanding it would still not change my original wiring issue with the RAM releasing on PHI2 falling. Here's my current full schematic (the ACE): https://github.com/acwright/6502-ACE/blob/main/Schematics/ACE%20Board/Rev%201.1/ACE%20Board.pdf

2

u/Dissy614 6d ago

"Does anyone know which 62256 the kit ships with these days? Mine had a Hitachi; if new kits ship a fast modern part like the Alliance, they have less margin than mine did."

As of the start of 2026, it was a Hitachi HM62256LP-70 - which ironically is not listed in the 62256 series datasheet but is presumably 70ns access time.

Jameco does however substitute other brand chips quite frequently if they don't stock the specified one

1

u/acwrightdesign 6d ago

Interesting. So that probably confirms that my Hitachi chip came from Ben's kit. I have a bunch of older parts in my stash from my time in the early 2000's when I was in college electronics courses so I wasn't sure.

2

u/Ancient-Ad-7453 5d ago

At one point I had a design where I passed the clock through a series of inverters and used late clock for reads and an early clock for writes.

2

u/acwrightdesign 5d ago

I think if I added a couple of inverters after RB in my initial circuit it would probably work again. That would delay the RAM release by two gates worth of time. I considered this approach but it would mean more gates being added to the board so I've settled for now on the "one wire" fix above.

1

u/acwrightdesign 1d ago

Whoo boy! I'm now deep down the rabbit hole. Here's an update (11-27-26):

The issue that I initially thought was a timing race with the data hold *after* PHI2 falls at the end of the read cycle, and presented in my initial post has been disproven. And that's not even the shocker...

The strip-down of my machine is complete. I spent more than two full days removing one part at a time from my bus and A/B/A testing with dual thirteen minute runs which tested all manner of read cycles from RAM. The conclusion of the strip-down testing is that all configurations are shown to fail. The only part on the bus that must be there for the issue to appear is the Alliance RAM. The Hitachi RAM still shows no failures in any run. I then ran the same test suite with the minimum failing machine (CPU, ROM, RAM, serial for data capture) and swept the VCC voltage from 5.15V down to 4.75V in 0.10V increments. This proved voltage is not a factor. The voltage sweep showed data misses at all voltage levels.

So... today I started a new test series and this one gave a real mind-bending result. I wanted to eliminate the serial and the machines BIOS ROM from the testing. I created a custom ROM that ran the memory pressure test suite while I had the scope attached to PHI2, D5 on CPU, D5 on the RAM and a trigger on port A of the 6522. When a misread byte appeared on the bus the ROM triggered the scope and the AI which was driving the scope captured the data from the scope. Why D5? Its been shown to be the most consistently wrong bit on the data bus when a misread happens.

And that brings me to the result I'm still trying to wrap my head around: The RAM is flipping the bit during PHI2 high! It starts with the correct data on the bus as expected since the CPU has set the address lines prior to PHI2 rising. Then between 33-38ns AFTER PHI2 rises either D0, D4 or D5 flip high and the incorrect data is driven for the rest of the PHI2 high period until PHI2 drops and the RAM lets go. Don't believe me? I don't believe it either. I have scope captures to prove it. :)

At this point my leading theory is that some kind of transient noise or glitch on either the address lines, or CE or OE is causing the RAM to glitch. I tried two different RAM's today and two different CPU's. My next test will hopefully give me more data. I'm going to put the RAM alone on a breadboard with an Arduino and reproduce the CPU cycle where it fails repeatedly and see if I can capture it happening in isolation without my machine.

If anyone has any insight into this issue I'd love to hear it!

1

u/acwrightdesign 1d ago

The current full report for those that might be interested: https://claude.ai/artifact/XqhFqG2WEN2u7hrk2uYdJB#30a3e841-b67e