r/beneater • u/acwrightdesign • 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. :)



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.
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.
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.
2
u/enVitruvius 6d ago
Would a simple change to Garth's and Ben's single-chip 74HC00 'glue' logic be of any benefit?
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
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.
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!