clock issues

Building your first 6502-based project? We'll help you get started here.
Post Reply
djenn
Posts: 5
Joined: 01 Jul 2022

clock issues

Post by djenn »

I am following Ben Eaters 6502 project and build the clock and connected an w65c02 and the resistors on the databus for the NOP command (without eeprom or ram I'm still waiting for those components).
When monitoring the "program" running with an Arduino i noticed that the cpu executes each instruction twice.
Even if stepping manual through the program I must push the cock button twice before the cpu advances one instruction.
To be sure I connected leds to the adress lines d0..d3 so i could see the adress bus advancing and i have to push the clock button twice.
I checked all the connection multiple times and far as I can see everything is connected as it should.
I've tried shorter and longer clock pulses whitout succes, the pulses themself are clean, no rebounce whatsoever (impossible they come from 555 timer).
Is there something else i can try to solve this riddle?
tmr4
Posts: 147
Joined: 19 Feb 2022

Re: clock issues

Post by tmr4 »

djenn wrote:
When monitoring the "program" running with an Arduino i noticed that the cpu executes each instruction twice.
Even if stepping manual through the program I must push the cock button twice before the cpu advances one instruction.
It's not executing twice, the NOP instruction just takes two clock cycles to execute. That's just the way Ben's monitor works. He mentions this at 25:03 in his first 6502 video.
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: clock issues

Post by BigDumbDinosaur »

djenn wrote:
I am following Ben Eaters 6502 project and build the clock and connected an w65c02 and the resistors on the databus for the NOP command (without eeprom or ram I'm still waiting for those components)...I've tried shorter and longer clock pulses whitout succes, the pulses themself are clean, no rebounce whatsoever (impossible they come from 555 timer).

Firstly, all 65xx instructions require a minimum of two clock cycles to execute. As TMR4 said, NOP is a two-cycle instruction, which explains what you are seeing.

Secondly, the 555 is not a good clock source for any WDC device, as the 555 cannot meet the 65C02's requirement for clock rise and fall time (5ns maximum). For testing purposes you could run your clock signal through a 74AC14 or 74AHC14 Schmitt trigger, which will transform the somewhat lazy output of the 555 into a sharp and well-defined clock, although not necessarily symmetric.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: clock issues

Post by BigEd »

Welcome, djenn! As noted, you'd be well-advised to look at a table of opcodes - how many bytes, how many cycles.
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: clock issues

Post by GARTHWILSON »

Welcome.

If you want to see it advance one address per clock cycle, use something like LDA #$A9. (The LDA# op code is also $A9.) The load-immediate instructions are among the two-byte, two-cycle instructions.

And I concur that a 555 is not a suitable clock driver for the W65C02S. It may work; but since it doesn't even come close to meeting the data sheet's requirements, it's just that it's not guaranteed to work.
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?
djenn
Posts: 5
Joined: 01 Jul 2022

Re: clock issues

Post by djenn »

Thank you all for helping me out!
It's clear to me now, whitout looking at the instruction set I assumed that a nop instruction was a one cycle instruction.
And while I'm waiting for the memory chip i cannot run a real program to see the difference.
The 55 is slow indeed, I'll add an hc414 for to be sure.
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: clock issues

Post by BigDumbDinosaur »

djenn wrote:
The 55 is slow indeed, I'll add an hc414 for to be sure.

HC414? What I recommended is either a 74AC14 or a 74AHC14. 74HC is too slow.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
djenn
Posts: 5
Joined: 01 Jul 2022

Re: clock issues

Post by djenn »

BigDumbDinosaur wrote:
djenn wrote:
The 55 is slow indeed, I'll add an hc414 for to be sure.

HC414? What I recommended is either a 74AC14 or a 74AHC14. 74HC is too slow.
I meant to write that, i guess I was not fully awake.
User avatar
Michael
Posts: 633
Joined: 13 Feb 2013
Location: Michigan, USA

Re: clock issues

Post by Michael »

It looks like someone modified the Arduino sketch (program) to monitor a new connection from the SYNC pin on the 65C02 so that the Arduino Mega will display the opcode mnemonic during the SYNC (opcode fetch) cycle.

link: https://github.com/dpm-343/6502-monitor
Aloha6502
Posts: 69
Joined: 17 Feb 2021

Re: clock issues

Post by Aloha6502 »

djenn wrote:
Thank you all for helping me out!
It's clear to me now, whitout looking at the instruction set I assumed that a nop instruction was a one cycle instruction.
And while I'm waiting for the memory chip i cannot run a real program to see the difference.
The 55 is slow indeed, I'll add an hc414 for to be sure.
viewtopic.php?f=1&t=7117

These quick reference charts show you the clock cycles.

Note the caveat about this being NOT the 65c02.

But close enough for the purposes of understanding this concept.

The "C" column shows clock cycles for each instruction.
Post Reply