6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 23, 2024 11:14 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Sun Jan 07, 2024 11:49 pm 
Offline

Joined: Tue Sep 26, 2023 11:09 am
Posts: 109
I've made a little arduino setup to teach myself about the 6522 shift register. I want to use it to shift in a key from a keyboard device, generating an interrupt once the key is available. I've been using the "shift in under external CB1 clock control". Things seem to work if I set my bit value on CB2, set CB1 high, and then either delay() about two phi2 clock periods or explicitly watch for a sequence of low/high/low/high on PHI2 before clearing CB1 again. But what's the minimum I need to do?

The datasheet says "Note that data is shifted during the first PHI2 clock cycle following the positive going edge of the CB1 shift pulse. For this reason, data must be held stable during the first full cycle following CB1 going high."

But what does that "...first full cycle..." actually mean? rising edge to rising edge on phi2? The timing diagram doesn't seem very explicit.

I guess I also need to watch out for the shift bug here? It didn't look like the other modes supported an externally initiated shift with an interrupt on completion, unless I'm misreading?


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 08, 2024 12:47 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
A 6502 cycle is falling edge to falling edge of Φ2.  Since the external clock and data sources are asynchronous to the Φ2 clock, it could take up to a full clock cycle to "register;" so two cycles will be plenty of insurance to make sure that it always works—except that yes, there's the bug to contend with, the only one in the '22, which is regarding external clock source for the shift register.  I describe it and give a workaround in Tip #8 of my tips column at viewtopic.php?p=2310#p2310, and it is also mentioned in the I/O ICs page of the 6502 primer, at http://wilsonminesco.com/6502primer/IO_ICs.html .  Other than that bug, I've never had any trouble with the SR—and I've used it lots.

_________________
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?


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 08, 2024 2:59 am 
Offline

Joined: Fri Jul 09, 2021 10:12 pm
Posts: 741
pdragon wrote:
I guess I also need to watch out for the shift bug here? It didn't look like the other modes supported an externally initiated shift with an interrupt on completion, unless I'm misreading?

Another option is to have the Arduino pull CB2 low (for example) to initiate an operation, and have your code pick up an interrupt from that and initiate a shift input operation with the 6522 generating the clock signal on CB1 - then use that to drive the Arduino's shifting. It is two interrupts per byte rather than one, but it is still interrupt-driven so might suit your goals.


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 08, 2024 6:48 pm 
Offline

Joined: Tue Jul 05, 2005 7:08 pm
Posts: 1043
Location: near Heidelberg, Germany
The shift register bug is happening exactly in the shift in under cb1 clock control that you are using.

However, what you quote looks like from the WDC65C22 datasheet. Which, as I understand, has the bug fixed. So, to make sure you don't get hurt, you have to use the WDC device.

Regarding the timing. The bit is shifted in at the next phi2 falling edge. I believe the diagram at page 49 of the wdc datasheet clarifies this: https://eater.net/datasheets/w65c22.pdf (tSR3)
At least that is how I read it.

I am not sure if any complicated logic is needed if the SR CB1 in clock is just slow enough.

Hope that helps
André

Edit: I just read that WDC may not have fixed the bug. Which would be an absolute bummer! http://wilsonminesco.com/6502primer/IO_ICs.html

_________________
Author of the GeckOS multitasking operating system, the usb65 stack, designer of the Micro-PET and many more 6502 content: http://6502.org/users/andre/


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 08, 2024 8:10 pm 
Offline

Joined: Tue Sep 26, 2023 11:09 am
Posts: 109
thanks, all this is very helpful!

I hadn't digested that diagram on p49, but I agree that's what it looks like.

Am I correct that Garth's flip-flop fix is basically ensuring that the CB1 transition is always delayed to just after a rising phi2 edge, to keep it from coinciding with a falling edge? I should be able to mimic the same thing from my rp2040 keyboard by waiting for a rising edge before setting CB1. then counting one or two falling edges before unsetting it again.


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 08, 2024 9:54 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
It's not particularly the delay that's important, but just that you keep the CB1 input clock edge from coinciding (within a few nanoseconds) with the falling edge of Φ2.

_________________
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?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 37 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: