[WDC65C02] STA writing when it feels like it?

Building your first 6502-based project? We'll help you get started here.
Doko
Posts: 9
Joined: 08 Jul 2021

[WDC65C02] STA writing when it feels like it?

Post by Doko »

Hello everyone

I'm currently following Ben Eater's tutorial on 6502 Hello world programming and I'm facing an issue with the STA instruction :(

It seems that sometimes, the STA doesn't execute itself and I don't know why!

This is the kind of output I get:

Code: Select all

1111111111111100 00000000  fffc r 00 y
1111111111111101 10000000  fffd r 80 y
1000000000000000 10101001  8000 r a9 y
1000000000000001 11111111  8001 r ff y
1000000000000010 10001101  8002 r 8d y
1000000000000011 00000010  8003 r 02 y
1000000000000100 01100000  8004 r 60 y
1000000000000101 10101001  8005 r a9 y ; there should be a write here!
1000000000000110 10101010  8006 r aa y
1000000000000111 10001101  8007 r 8d y
1000000000001000 00000000  8008 r 00 y
1000000000001001 01100000  8009 r 60 y
0110000000000000 10101010  6000 w aa n ; here is a write
1000000000001010 10101001  800a r a9 y
1000000000001011 01010101  800b r 55 y
1000000000001100 10001101  800c r 8d y
1000000000001101 00000000  800d r 00 y
1000000000001110 01100000  800e r 60 y
0110000000000000 01010101  6000 w 55 n ; here is another write
1000000000001111 01001100  800f r 4c y ; jumping back
1000000000010000 00000101  8010 r 05 y
1000000000010001 10000000  8011 r 80 y
1000000000000101 10101001  8005 r a9 y
1000000000000110 10101010  8006 r aa y
1000000000000111 10001101  8007 r 8d y
1000000000001000 00000000  8008 r 00 y
1000000000001001 01100000  8009 r 60 y
0110000000000000 10101010  6000 w aa n ; here is another write
In this example there have been actually a lot of write, but the behaviour is really erratic, sometimes it will write 10% of the time, other times 80%

Any idea how I can debug this? :(

Edit: I'll add a picture of my setup, even though it's not very tidy :oops:
Image
User avatar
Dr Jefyll
Posts: 3525
Joined: 11 Dec 2009
Location: Ontario, Canada
Contact:

Re: [WDC65C02] STA writing when it feels like it?

Post by Dr Jefyll »

Welcome, Doko. :)

The project seems incomplete, in the photo at least. I don't notice any clock source. And you've not included a schematic for us. BTW, on this forum you can attach images with your post. This is preferable to using a third party image hosting site.

As for the troubleshooting, I guess you used a Logic Analyzer to collect the data you posted, is that right?

Possibly it's the LA -- not your project -- which is failing to operate as expected. So, here's a question.

Is it always the write cycle of the STA which fails to appear in the listing? Or, do you sometimes notice that other cycles are absent?

-- Jeff
PS- schematic, please!
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: [WDC65C02] STA writing when it feels like it?

Post by BigEd »

Indeed welcome!

I wonder if perhaps you are single-stepping? The thing with that is that you need to know that you are indeed always single-stepping and not sometimes double-stepping. Physical keyswitches, buttons, relays or just touching two wires together turns out not be a clean make-or-break. When a very fast circuit is reacting to such a keypress, it may see multiple make-and-break cycles.
User avatar
Dr Jefyll
Posts: 3525
Joined: 11 Dec 2009
Location: Ontario, Canada
Contact:

Re: [WDC65C02] STA writing when it feels like it?

Post by Dr Jefyll »

Regarding Logic Analyzers, in this post John West explains the point I am concerned about.
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html
Doko
Posts: 9
Joined: 08 Jul 2021

Re: [WDC65C02] STA writing when it feels like it?

Post by Doko »

Thanks for the welcome guys :)
Dr Jefyll wrote:
I don't notice any clock source.
I'm using a hand made clock made out of 555 in astable for a 1Hz clock and monostable mode to single-step the clock
Dr Jefyll wrote:
And you've not included a schematic for us
I'm kind of beginning electronics and don't know a good website to make schematics do you have a recommandation?
Dr Jefyll wrote:
on this forum you can attach images with your post
Noted :)
Dr Jefyll wrote:
As for the troubleshooting, I guess you used a Logic Analyzer to collect the data you posted, is that right

I use an Arduino Mega
Doko wrote:
Is it always the write cycle of the STA which fails to appear in the listing? Or, do you sometimes notice that other cycles are absent?
Sometimes the jump instruction won't be processed, or even right now I got this output :
Quote:
1111111111111100 00000000 fffc r 00 y
1111111111111101 10000000 fffd r 80 y
1000000000000000 10101001 8000 r a9 y
1000000000000001 11111111 8001 r ff y
1000000000000010 10001101 8002 r 8d y
1000000000000011 00000010 8003 r 02 y
1000000000000100 01100000 8004 r 60 y
1000000000000111 10001101 8007 r 8d y
1111111111111111 11101010 ffff r ea y ; where does that come from??
1000000000000111 10001101 8007 r 8d y
It feels like my contacts aren't right sometimes, if I touch the wire
BigEd wrote:
I wonder if perhaps you are single-stepping?
I'm single stepping but in the example I sent i was running with my custom clock at 1hz. Maybe my clock isn't working that great as well :s

And right now as I'm writing, the CPU behave perfectly normal :s That's really strange.
Could static electricity be the problem? Or should I unplug the power in a particular way? Does the proximity of my hands to the breadboard has an incidence?
Every time I plug / unplug the power I have a different behavior

The whole setup (clock + cpu breadboard) is plugged to the 5v output of my arduino
ThisWayUp
Posts: 49
Joined: 03 Jul 2021

Re: [WDC65C02] STA writing when it feels like it?

Post by ThisWayUp »

I'm a newbie too, but I would definitely recommend powering the project from an external power. I notice you are following Eater's build, I am too. He uses an external supply for the breadboard and seperate power for the Mega and ties them together with a common ground. If you are using the power from the Mega 5V pin this could be noisy or not providing enough current. I would definitely provide the breadboard with its own dedicated power as a start.
Doko
Posts: 9
Joined: 08 Jul 2021

Re: [WDC65C02] STA writing when it feels like it?

Post by Doko »

You're probably right! Only problem is I only have a 9v power supply on which I can plug a 9v battery, what should I get to generate a 5v supply?
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: [WDC65C02] STA writing when it feels like it?

Post by BigEd »

How does the Arduino know when the clock transitions will happen? Ideally, the logic analyser needs to capture all pins at the time of the clock transition - just before or just after should be the same, if you are close enough in time.
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: [WDC65C02] STA writing when it feels like it?

Post by GARTHWILSON »

Welcome, Doko. You seem to have several problems that I think will be solved if you go through the 6502 Primer which seems to be where Ben Eater got some of his ideas, but he ignored others, and his followers have problems as a result.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
User avatar
Dr Jefyll
Posts: 3525
Joined: 11 Dec 2009
Location: Ontario, Canada
Contact:

Re: [WDC65C02] STA writing when it feels like it?

Post by Dr Jefyll »

Whoa! A flurry of responses while I was typing. But I'll post this anyway.
Doko wrote:
I'm kind of beginning electronics and don't know a good website to make schematics do you have a recommandation?
There are lots of possible solutions. The most basic is to draw on paper, then take a picture. Often there are details that can be omitted, or at least simplified -- such as a data bus whose 8 lines all connect in a similar way.
Quote:
And right now as I'm writing, the CPU behave perfectly normal :s That's really strange.
No, not really.
Quote:
Could static electricity be the problem? Or should I unplug the power in a particular way? Does the proximity of my hands to the breadboard has an incidence?
None of this should matter... although it in reality it may. "Funny" symptoms are actually routine in the presence of certain design and construction shortcomings. :!:

Before we begin detailing THAT list, more photos might be helpful.

-- Jeff
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html
Doko
Posts: 9
Joined: 08 Jul 2021

Re: [WDC65C02] STA writing when it feels like it?

Post by Doko »

BigEd wrote:
How does the Arduino know when the clock transitions will happen?
The clock is plugged to the Arduino and an interrupt method is called on the rising edge of the clock cycle to read the addresses and data pins
GARTHWILSON wrote:
Welcome, Doko. You seem to have several problems that I think will be solved if you go through the 6502 Primer which seems to be where Ben Eater got some of his ideas, but he ignored others, and his followers have problems as a result.
Thanks for the reminder, I started reading it a while ago but didn't finish, I'll read some more right now
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: [WDC65C02] STA writing when it feels like it?

Post by BigEd »

You can pick up 5V from a USB cable, which might be adequate. Bear in mind that your various power supplies need to share a ground connection - connecting just one wire can't work.

You might solve several problems if you drive the clock input from the Arduino - it will be under your control, it will have fast edges (important!) and the Arduino will know the state of the clock when it samples the pins as a logic analyser.
ThisWayUp
Posts: 49
Joined: 03 Jul 2021

Re: [WDC65C02] STA writing when it feels like it?

Post by ThisWayUp »

Want to give the chap a moment to breath, quite the rush of replies, but I am also seeing a lack of decoupling capacitors. A 0.1uF capacitor on each of the power rails as a bare minimum is a must. These help to kill noise and smooth out any jitters or sags on the powerrail. Different values of capacitor deal with different types of issues but 0.1uF is good for starters.
Doko
Posts: 9
Joined: 08 Jul 2021

Re: [WDC65C02] STA writing when it feels like it?

Post by Doko »

ThisWayUp wrote:
Want to give the chap a moment to breath
That's amazing :D would never have thought such an old CPU had still a so active community

I just made myself a 5v power supply from a USB cable like suggested by BigEd and ThisWayUp and well, things are looking much better! I'm having a really consistent flow of instructions running now !

Seems like the 5v given by the Arduino were indeed the root cause of the problems.

I'll keep you posted if things go south again but works like a charm right now.
ThisWayUp wrote:
but I am also seeing a lack of decoupling capacitors.
I read about those capacitors but indeed didn't put any on my setup. I guess I will put them on as well :)

A big thank to all of you guys
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: [WDC65C02] STA writing when it feels like it?

Post by BigEd »

Good catch - it might not behind the immediate observation, but if it makes the machine unreliable it's going to be a cause of great head-scratching.

I had an idea: these are threads which mention 'eater' in the first post - often they will be relatively new joiners, seeing similar or related problems to each other. Might be a source of commonly-addressed-issues.
Post Reply