Page 2 of 4

Re: Issues with 6502?

Posted: Sat Jul 19, 2025 5:55 pm
by Dr Jefyll
Lots of advice coming at you, Niek6502, and the situation may seem rather murky. But one or two important points seem clear to me.

Things sound pretty crazy when you talk about "completely derailing (nonsensical addresses, weird read/write pin outputs etc)," but let's take that apart a bit. For starters, there's nothing weird about the read/write pin going low for 3 cycles.

Code: Select all

8005 r 1 8d      sta $7abc
8006 r 1 bc
8007 r 1 7a
7abc w 0 7a      --> still seeing 7a instead of 01
800c r 1 00      ---> and here things go completely off the rails - it skipped 4 bytes ???
800c r 1 00 
800d r 1 00
01fa w 0 00  **read/write pin!
01f9 w 0 80  **read/write pin!
01f8 w 0 0e  **read/write pin!
It's going low because a BRK instruction is executing -- it fetched the $00 BRK opcode from $800C. (And yes it appears to have skipped 4 bytes to get to $800C, but perhaps it got there incrementally and we don't see that because some samples are failing to appear -- just an alternative theory to keep in mind.) But it certainly seems to be executing a BRK, and that would very readily explain the "weird" read/write pin output.

It also may seem weird that the expected write data fails to appear in the recorded samples. Instead what the recorded samples show is the data which was read in the immediately preceding cycle. (Example: $8007 and the cycle that follows) That's consistent with my suspicion that the samples were taken too soon. Virtually all 65(C)02 systems (including yours, I infer) do not drive the data bus during the first half of a write cycle -- ie, during the PHI2-low portion. Since the bus isn't being driven, what will remain there is whatever state most recently *was* driven... and that's the last byte of the instruction that generated the write. We clearly see that several different times.

It remains because of the storage effect resulting from the capacitance of the bus lines; this phenomenon is well known. And it won't disappear until the 2nd half of the cycle when the CPU drives write data onto the bus. This supports my conclusion that the samples taken by the Arduino were taken too soon, while PHI2 was still low and the CPU hadn't yet driven write data onto the bus. But why?

Electrical noise is always present to some extent, and it has potential to induce hiccups. For example, a signal (like PHI2) that rises from low to high may, with noise impressed upon it, appear to go low->high->low->high! IOW, there's an illusion of multiple transitions. And that includes both high-to-low transitions and low-to-high transitions! This means there's potential for the Arduino to take its sample on the opposite edge to the one you intended.

I agree with BDD that you'd do well to buffer the output of the 555, as that'll result in much faster rise & fall times (the transitions will occur more snappily). An 'AC14 would be ideal, but even just one of your existing inverter sections -- 74HC04, not 'LS04 -- would probably suffice. And yes that'll help satisfy the CPU spec as he noted.

But more important, IMO, is that it'll result in more reliable sampling by the Arduino. Your samples clearly are getting taken at the wrong time. There may be multiple factors at play, but certainly the slow rise & fall times from the 555 make it easier for noise to falsely trigger the Arduino.

-- Jeff

Re: Issues with 6502?

Posted: Sat Jul 19, 2025 8:04 pm
by Niek6502
Thanks all for keeping to chime in! I will need some time to get a schematic drawn (currently dealing with some down time due to dental surgery...).

I do understand the request for a photo, but I don't know how to directly attach one to a post. I did however link to a photo in post #12 - http://www.qwertyboy.org/files/6502-001.jpg (if there is a different way of supplying pics, please let me know).

The components used:
- An 65C02;
- An AT28C256 EEPROM;
- A 74LS04 hex inverter (I will swap that out for a 74AC14).

As you can see, the 65C02 has its RESB tied high with a resistor (and can force it low by pushing the button). Pins SOB, BE, RDY, IRQB, NMIB and VDD are also tied to 5V. Pin VSS is tied to ground. From the 65C02, A15 goes to an 74LS04 - the inverted A15 is tied to CEB on the EEPROM. A0-A14 on the 65C02 are tied to A0-A14 on the EEPROM, as are D0-D7. The pic shows a gap between the 65C02 and the EEPROM - that is where later the SRAM will slot in (the address and data ties are already in place, so only the glue, ground/5v etc needs to be added).

I tested all current wiring by removing the EEPROM and testing all connections from the 65C02 pins to the breadboard holes where the EEPROM would sit - all connections show up OK. I also tested adjacent pins for all pins to make sure there isn't a short - all OK.

I think I will simply forego the Arduino (to eliminate "false readings" all together), use a 1MHz oscillator as clock (get the 555 out of the way), and hook up a 6522 to get some proper visual output. Might not be before tomorrow though - too many ibuprofens in my system.

Quick question - should I also use a 74AC14 between the 1MHz oscillator (an MCO-1510A) or will the oscillator behave properly as input for PHI2?

Thanks again!

-Niek.

Re: Issues with 6502?

Posted: Sat Jul 19, 2025 8:35 pm
by GARTHWILSON
Niek6502 wrote:
I will need some time to get a schematic drawn (currently dealing with some down time due to dental surgery...).
Teeth can be a pain sometimes.  As for a schematic, there's seldom a need to put everything in one schematic.  See my post at viewtopic.php?p=79892#p79892 .  Further, a hand-drawn one done well can be more legible than a lot of the ones done in schematic-capture software that people post, even on this forum.
Quote:
I do understand the request for a photo, but I don't know how to directly attach one to a post.
Below the window where you write your post, there's a portion to browse and attach a file to the post, as well as to inline it if you want to.

Re: Issues with 6502?

Posted: Sat Jul 19, 2025 8:39 pm
by BigDumbDinosaur
Niek6502 wrote:
(currently dealing with some down time due to dental surgery...)

Sounds like you are really sinking your teeth into this project.  <GROAN>

Anyhow...

Quote:
I do understand the request for a photo, but I don't know how to directly attach one to a post. I did however link to a photo in post #12 - http://www.qwertyboy.org/files/6502-001.jpg (if there is a different way of supplying pics, please let me know).

Right below the [Submit] button that is immediately below the post window in which you are typing your text is a section for uploading an attachment.  It should be self-explanatory.  Linking to off-site images creates the potential for broken links in the future.  Attaching your images and other files, e.g., PDFs, here assures they will always be available to anyone who reads your post.

Quote:
The components used:

- An 65C02;
- An AT28C256 EEPROM;
- A 74LS04 hex inverter (I will swap that out for a 74AC14).

As you can see, the 65C02 has its RESB tied high with a resistor (and can force it low by pushing the button).

Your RESB circuit is unreliable.  A push button exhibits contact bounce that will look like multiple closures to the MPU.  The problem is the MPU requires that RESB be held low for a minimum of two consecutive Ø2 cycles, followed by a clean transition to high.  Each time the push button’s contacts bounce, that sequence is disrupted.  RESB on the 65C02 doesn’t have Schmitt action, so a positive means of debouncing the push button is de rigueur to achieve a reliable reset.  Garth has a page on his website devoted to reset circuits, which I suggest you peruse.  The Ben Eater-style reset you apparently are using is a faulty design.

Quote:
Pins SOB, BE, RDY, IRQB, NMIB and VDD are also tied to 5V.

Do not connect RDY directly to VCCRDY is bi-directional and is driven low by the MPU when it executes a WAI instruction.  Even though you may not have entered a WAI into your program, an error somewhere could cause the MPU to execute a stray $CB byte, which is the opcode for WAI, causing the MPU to try to short VCC to ground.  Connect RDY to VCC with a resistor...3.3K is a good value.

Quote:
Quick question - should I also use a 74AC14 between the 1MHz oscillator (an MCO-1510A) or will the oscillator behave properly as input for PHI2?

All depends on the specs of the MCO-1510A.  Main things to look for are output transition time between opposite states, e.g., low to high (should be no more than 5 nS) and the VOH rating (should be at least VCC × 0.7).

Re: Issues with 6502?

Posted: Sat Jul 19, 2025 9:07 pm
by Niek6502
Jeez - how could I miss that? Must be getting old... Thanks guys!

Anyways, the pic of my test setup is attached. I will work on an Arduino-and-555-free setup with an added 6522 (but as said that will likely have to wait a bit). Thanks for the comments on the reset button (ah - more wisdom to ingest) and the RDY pin (goes to show I really need to read the datasheets, as is obvious with many other comments). I do have two gates on the 74AC14 available, so probably won't hurt to feed the oscillator into one of those just to be on the safe side.

Really appreciate the time you guys take to help me out! Swing by and I will bake you all some cookies.

-Niek.

Re: Issues with 6502?

Posted: Sun Jul 20, 2025 12:00 am
by BigDumbDinosaur
Niek6502 wrote:
I will work on an Arduino-and-555-free setup...I do have two gates on the 74AC14 available, so probably won't hurt to feed the oscillator into one of those just to be on the safe side.

Doing so will result in a sharply-defined signal with single-digit transition times, which is what the MPU likes.  The idea is to eliminate “gotchas” from the circuit that can create undefined conditions within the MPU and fool you into thinking your design isn’t working.

Re: Issues with 6502?

Posted: Wed Jul 23, 2025 5:41 pm
by Niek6502
Success! The setup (a 65C02, an EEPROM and a 65C22) are working fine (eliminated the 555 clock and the Arduino test). Thanks all! I will post a "lessons learned" later.
BigDumbDinosaur wrote:
Doing so will result in a sharply-defined signal with single-digit transition times, which is what the MPU likes.  The idea is to eliminate “gotchas” from the circuit that can create undefined conditions within the MPU and fool you into thinking your design isn’t working.
Attached is a scope monitoring the oscillator pin directly (the yellow line) and the signal directly after going through a 74AC14 gate while a "blinking LEDs" test program is running (the blue line). They look almost identical, so the 74AC14 for cleaning up the oscillator signal is likely not needed, but I will leave it in as I have that gate available anyways.

Again, thanks all for putting this HW newbie straight!

Next is putting back the SRAM, then adding a second VIA, and then I will be at the point I wanted to be at the start of this rebuild.

-Niek.

Re: Issues with 6502?

Posted: Sat Jul 26, 2025 10:58 pm
by Niek6502
Just an update - all is working OK with 2 VIAs (will need to rework the reset circuit as was advised). See attached for the current schematic. Hopefully it is not too messy.

-Niek.

Re: Issues with 6502?

Posted: Sun Jul 27, 2025 1:01 am
by Michael
Are you decoding and overlapping I/O address space at $4000..$7FFF with RAM in the $0000..$7FFF address space?

Re: Issues with 6502?

Posted: Sun Jul 27, 2025 1:21 am
by Niek6502
Michael wrote:
Are you decoding and overlapping I/O address space at $4000..$7FFF with RAM in the $0000..$7FFF address space?
Good catch - a14 should be tied to OEB on the SRAM (it is actually on my breadboard, I was trying to document after the fact). I will update.

-Niek.

Re: Issues with 6502?

Posted: Sun Jul 27, 2025 2:06 am
by BigDumbDinosaur
Aside from the decoding oopsie pointed out by Michael, what is the purpose of the Schmitt inverter connected to the clock oscillator?

Re: Issues with 6502?

Posted: Sun Jul 27, 2025 3:22 am
by Niek6502
BigDumbDinosaur wrote:
Aside from the decoding oopsie pointed out by Michael, what is the purpose of the Schmitt inverter connected to the clock oscillator?
That is actually because of your input - we discussed forcing the clock input to be sharp and snappy (see a few posts back). I also posted a picture of measuring the oscillator output and the output from the inverter. Looks like the oscillator provides a proper clock, but I had that gate available anyway.

Does that make sense?

-Niek.

Re: Issues with 6502?

Posted: Sun Jul 27, 2025 5:42 pm
by BigDumbDinosaur
Niek6502 wrote:
BigDumbDinosaur wrote:
Aside from the decoding oopsie pointed out by Michael, what is the purpose of the Schmitt inverter connected to the clock oscillator?
That is actually because of your input - we discussed forcing the clock input to be sharp and snappy (see a few posts back).

Ah-so!

Usually a flop is employed for that purpose, which gets clock symmetry right at 50:50 (within a nanosecond or two).  However, at the modest speed at which you are running, symmetry is unimportant and just about any sort of gate whose outputs meet requirements would work.

If you carefully read the data sheet, you will see that input hysteresis for Schmitt-triggered inverters can be all over the map.  It’s not uncommon for the input voltage at which the output switches from low to high to be substantially different than when the output switches from high to low.  Depending on the characteristics of the oscillator, the inverter could exacerbate asymmetry in some cases.  While that doesn’t matter in this case, it’s something to file away for future reference when you decide one day to build a 20 MHz special.

Re: Issues with 6502?

Posted: Sun Jul 27, 2025 7:34 pm
by Niek6502
BigDumbDinosaur wrote:
Usually a flop is employed for that purpose, which gets clock symmetry right at 50:50 (within a nanosecond or two).  However, at the modest speed at which you are running, symmetry is unimportant and just about any sort of gate whose outputs meet requirements would work.
That'scwhat I figured, and since that gate was already available on my board I used it.
BigDumbDinosaur wrote:
If you carefully read the data sheet, you will see that input hysteresis for Schmitt-triggered inverters can be all over the map.  It’s not uncommon for the input voltage at which the output switches from low to high to be substantially different than when the output switches from high to low.  Depending on the characteristics of the oscillator, the inverter could exacerbate asymmetry in some cases.  While that doesn’t matter in this case, it’s something to file away for future reference when you decide one day to build a 20 MHz special.
Thank you for all the valuable tidbits!

It has been a while since I was "intimate" with hardware. I have built a vast amount of networks and servers in the last 40-or-so years, but especially the last decade there is not much thinking about these low-level details. In the early '80s there was a fair bit of custom-cable-cutting, reprogramming MFM/RLL controllers to accept other drives, maximizing memory address space usage, writing the odd Xenix device driver, building and debugging serial lines, connecting thick ethernet transceivers, using a scope to pinpoint 10base2 cable failures etc. All skills that have almost no use now and will make most techies go "whut".

I thoroughly enjoy this "back to basics" experience and I very much appreciate all the time and advice you guys put into my queries!

-Niek.

Re: Issues with 6502?

Posted: Mon Jul 28, 2025 12:24 am
by BigDumbDinosaur
Niek6502 wrote:
In the early '80s there was a fair bit of...using a scope to pinpoint 10base2 cable failures...

Ugh!  I used to hate it when called upon to find a fault in a coax cable.  Reminded me of my Navy days when I had to do that cr*p while at sea on a rolling and pitching destroyer, usually while up on the mast.  :evil:

Those coax cables were all “armored” for protection from splinter damage caused by incoming enemy projectiles.  They were basically RG-8/U with an external stainless steel braid that was so tough it was said a 5 inch AP round would ricochet off the cable and end up hitting the ship that fired it.  :D  Dunno about that, but I did have to use a hacksaw when I had to cut a cable to splice in a new section.