6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Mon Oct 07, 2024 12:35 pm

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: 6522 - exact timing
PostPosted: Thu Feb 28, 2013 10:30 am 
Offline

Joined: Wed Oct 06, 2010 9:05 am
Posts: 95
Location: Palma, Spain
Hi,

Does anyone know if there is any latency (even half a cycle) in pulling nIRQ high when a timer interrupt is acknowledged (either by reading T1C-L/T2C-L or by writing T1C-H/T2C-H)?

I'm trying to do a very accurate simulation, specifically to handle a case similar to Garth's "ghost interrupts", in which an IRQ is taken the cycle after a read from T1C-L, even though this read would have acknowledged the IRQ, and it seems to me that the only way this can make sense is if there's some kind of latency.

Supposing T1C-L is at $FE44, here are a couple of Visual6502 simulations of an IRQ being generated while reading from $FE44:

  • In this first case, the interrupt is acknowledged at the last possible moment that would stop the interrupt from being taken.
  • In this second case, the interrupt is acknowledged at the first possible moment that would allow the interrupt to be taken anyway.

If the second case represents more or less what has been observed in the past, this must mean that a cycle passed between T1C-L being read and nIRQ going high. Has anyone ever measured this with a logic analyser, or have any documentation to this effect (I can't see anything in the 6522 datasheet)? Or if not, does my interpretation seem sound there, and is this a reasonable assumption to make? I'm not 100% sure exactly when the read from $FE44 is done, but my best guess is last half of T3?

Anyone here more hardware-inclined than me who can make sense of this?


Top
 Profile  
Reply with quote  
 Post subject: Re: 6522 - exact timing
PostPosted: Thu Feb 28, 2013 11:26 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8522
Location: Southern California
None of my data books specify that for the timers, but they do show that there is negligible delay (hardly a fraction of a half cycle) on the parallel-port handshaking when the condition is met to release the IRQ\ output.  I could try it in hardware if my plate weren't so full right now, but the situation that caused my ghost interrupts mentioned in the interrupts primer and in the Tips had a different cause.  The bigger delay will be the time required for a passive pull-up resistor to charge the capacitance on the line if you are not using WDC's 65c22 with and AND gate to combine outputs.  Even a couple of clocks' delay would be fine though because you should be clearing the interrupt in the VIA before the end of the ISR (don't make it the last instruction), and then the RTI takes 7 clocks anyway.

_________________
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  
 Post subject: Re: 6522 - exact timing
PostPosted: Fri Mar 01, 2013 4:56 pm 
Offline

Joined: Wed Oct 06, 2010 9:05 am
Posts: 95
Location: Palma, Spain
Thanks Garth!

One thing I don't quite understand is, in your case of ghost interrupts, you said that it happened when an interrupt happened during an instruction to disable that interrupt. Presuming that was a store to the IER, that shouldn't have affected the IFR, so do you mean that in your interrupt service routine you were doing the 'well behaved' thing of LDA IFR / AND IER and using that result, which was consequently yielding nothing? Just trying to understand this weird behaviour properly.

I'm not hardware-minded enough to really understand your explanation of a 'pull-up resistor needing time to charge the capacitance on the line' (I wish I knew where to start :? ) but I get the idea that it's common that it should take a little time before the line goes high again. In any case, I'm going to go with the model that the 6522 takes at least half a cycle to pull nIRQ high, and see if my simulator yields the same results as real hardware. If not, back to the drawing board...


Top
 Profile  
Reply with quote  
 Post subject: Re: 6522 - exact timing
PostPosted: Fri Mar 01, 2013 8:52 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8522
Location: Southern California
Wow, that was a lot of years ago, and I tend to remember the conclusion (what I need to do next time to stay out of trouble) much better than the details that led there.  After squeezing my head, this is what I come up with.

For disabling T1 interrupts, you do LDA #$40, STA VIAIER.  The STA takes four clocks, and the actual store is in the last clock; however, if the interrupt hit during the STA (and probably before the last clock), the IRQ\ line got pulled down, and the processor noticed.  At that point, it doesn't matter if the VIA responded to the IER change immediately or not, because the processor already took the order and plans to fill it.  I had at least two other interrupts endabled, so the ISR did have to poll to make sure it did the right thing.  Instead of ANDing with the IER though, I usually make the ISR to poll only the sources I've enabled anyway.  (Actually the effect is virtually the same, but the software approach is slightly different.)  When the "ghost" interrupt hit, it was still legitimately enabled and got noticed by the processor but then got pulled before the ISR got far enough to see who did it.  Regardless of whether you still poll the now-disabled source, everything still says, "Wasn't me!"  A few possible ways to handle it are given in the primer.

I will comment here that testing with the 65c02 (I think it was a Rockwell one), a falling IRQ\ line even in the last phase-2-high time of an instruction would make the interrupt sequence start immediately after that instruction, not carrying out another one first.  This is different from what was said in the link you gave which was apparently about the NMOS 6502.

The other thing is the open-drain IRQ\ output and the pull-up resistor.  Think of the capacitance on the line as a tank of water.  To bring the level down (as in pulling IRQ\ down), the VIA can in essence drop the bottom out of the tank, and it empties, very, very quickly; but for it to come back up, there's just a fawcet running that takes awhile to refill it.  WDC's totem-pole IRQ\ outputs will be able to yank the line up much faster.  Continuing the water tank analogy, WDC's have an aqueduct above the tank and can open a huge door and fill the tank very suddenly.  The open-drain IRQ\ outputs of the Rockwell and CMD parts I was using rely only on the pull-up resistor to make the capacitance on the line slowly leak back up to the high state, which took a couple of clocks' time as there were six ICs connected to it plus WW sockets and wire, possibly as much as 100pF of capacitance.

_________________
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  
 Post subject: Re: 6522 - exact timing
PostPosted: Tue Mar 05, 2013 11:17 pm 
Offline

Joined: Wed Oct 06, 2010 9:05 am
Posts: 95
Location: Palma, Spain
GARTHWILSON wrote:
When the "ghost" interrupt hit, it was still legitimately enabled and got noticed by the processor but then got pulled before the ISR got far enough to see who did it.

But what will have pulled it in this instance? Still not quite understanding the scenario, but I appreciate that this was ages ago and the details are undoubtedly fuzzy!

Quote:
I will comment here that testing with the 65c02 (I think it was a Rockwell one), A falling IRQ\ line even in the last phase-2-high time of an instruction would make the interrupt sequence start immediately after that instruction, not carrying out another one first. This is different from what was said in the link you gave which was apparently about the NMOS 6502.

That's interesting - do you have any detailed docs on the timing differences between the CMOS and NMOS versions? As we can see from Visual6502 in this somewhat exaggerated example, as long as nIRQ is low during the first half of T0, the interrupt sequence will begin, and this is the only place the CPU checks whether an interrupt should be taken or not. Its level during any other 6502 timing state appears to be irrelevant. Is the 65C02 different in this respect?

Thanks for the analogy. I'm very much a software guy (my current project involves writing a very precise 6502/6522 simulator amongst other things), but I'm interested in trying to understand what's going on underneath it all, and so these little insights are very useful!


Top
 Profile  
Reply with quote  
 Post subject: Re: 6522 - exact timing
PostPosted: Wed Mar 06, 2013 3:17 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8522
Location: Southern California
RichTW wrote:
GARTHWILSON wrote:
When the "ghost" interrupt hit, it was still legitimately enabled and got noticed by the processor but then got pulled before the ISR got far enough to see who did it.

But what will have pulled it in this instance?  Still not quite understanding the scenario, but I appreciate that this was ages ago and the details are undoubtedly fuzzy!

The interrupt-disabling write to the IER made the VIA quit pulling the line down, but the processor was already committed to starting the interrupt sequence and heading into the ISR.

Quote:
Quote:
I will comment here that testing with the 65c02 (I think it was a Rockwell one), A falling IRQ\ line even in the last phase-2-high time of an instruction would make the interrupt sequence start immediately after that instruction, not carrying out another one first.  This is different from what was said in the link you gave which was apparently about the NMOS 6502.

That's interesting - do you have any detailed docs on the timing differences between the CMOS and NMOS versions?  As we can see from Visual6502 in this somewhat exaggerated example, as long as nIRQ is low during the first half of T0, the interrupt sequence will begin, and this is the only place the CPU checks whether an interrupt should be taken or not.  Its level during any other 6502 timing state appears to be irrelevant.  Is the 65C02 different in this respect?

I found a printout of one experiment I did, and it has NMI but IRQ was left alone on this one.  (The driver code I found that goes with it says the purpose of the experiment was to see if the processor would respond to a short NMI asserted in the middle of an instruction.  It did.)  I would have to get my fixture out and set things up again to do it on an actual processor, but the workbench computer is busy doing something else at the moment which I really don't want to interrupt.

What's on this printout however is that in one place there's an STA $1234 (8D 34 12), and I pulled the NMI down after it started reading the 34 and brought it back up before it was done reading the 12, and it started the NMI sequence immediately after the store at the end of the instruction.  This is repeated in another place with a different store address.  In another place, I pulled the NMI line down in the second cycle of a CLC instruction, ie, in the last cycle of the instruction, and after phase 2 rose, and it again started the NMI sequence immediately in the very next cycle.

I don't have detailed docs on the timing differences between CMOS and NMOS.  After I started using CMOS in about 1986, I didn't want to ever use NMOS again.

_________________
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  
 Post subject: Re: 6522 - exact timing
PostPosted: Wed Mar 06, 2013 7:21 pm 
Offline

Joined: Tue Jul 05, 2005 7:08 pm
Posts: 1041
Location: near Heidelberg, Germany
Some relatively good simulation can be found in the VICE Commodore emulator, that also emulates the VIC-20 with its dual 6522. And this VIC20 emulator is used for demo coding etc, before going to the real machine, so it should be good.

(... and I put a lot of thought into the VICE CIA and VIA timer emulations back then.... B-)
(but they sure have been improved in the meantime as well)

André

_________________
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  
 Post subject: Re: 6522 - exact timing
PostPosted: Thu Mar 07, 2013 8:23 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8522
Location: Southern California
GARTHWILSON wrote:
None of my data books specify that for the timers, but they do show that there is negligible delay (hardly a fraction of a half cycle) on the parallel-port handshaking when the condition is met to release the IRQ\ output.

I found an SY6522 ap. note, AN-5 from Synertek from March of 1982, with this diagram:
Attachment:
T1IRQ.jpg
T1IRQ.jpg [ 58.05 KiB | Viewed 1319 times ]

_________________
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  
 Post subject: Re: 6522 - exact timing
PostPosted: Thu Mar 07, 2013 10:01 pm 
Offline

Joined: Wed Oct 06, 2010 9:05 am
Posts: 95
Location: Palma, Spain
Ah, that's a great find, thank you for posting that! So according to that, there's absolutely not a delay in pulling nIRQ high after a read from T1C-L, which is a shame as it means I have to come up with another theory as to how these "ghost interrupts" occur :( I noticed in the full datasheet for the SY6522 that the IRQ\ output is open drain, so it surprises me that the rising edge occurs so quickly, given what you've previously said about how this works. The VIA in the case I'm trying to understand was an R6522AP, but this is more-or-less identical as far as I can tell.

Thanks fachat, I already took a look at VICE, but it seems that these real subtleties of the VIA operation haven't really been described anywhere before, and are really only necessary for absolutely precise simulation.


Top
 Profile  
Reply with quote  
 Post subject: Re: 6522 - exact timing
PostPosted: Thu Mar 07, 2013 10:53 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8522
Location: Southern California
Quote:
I noticed in the full datasheet for the SY6522 that the IRQ\ output is open drain, so it surprises me that the rising edge occurs so quickly, given what you've previously said about how this works.

It just means it releases it that quickly.  How quickly it actually comes up will depend on the time constant formed by the pull-up resistor and line capacitance.

_________________
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  
 Post subject: Re: 6522 - exact timing
PostPosted: Thu Mar 07, 2013 11:10 pm 
Offline

Joined: Wed Oct 06, 2010 9:05 am
Posts: 95
Location: Palma, Spain
Ah OK, thanks Garth for the clarification!


Top
 Profile  
Reply with quote  
 Post subject: Re: 6522 - exact timing
PostPosted: Mon Mar 17, 2014 1:55 pm 
Online
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10949
Location: England
RichTW wrote:
... [In the NMOS 6502,] as long as nIRQ is low during the first half of T0, the interrupt sequence will begin, and this is the only place the CPU checks whether an interrupt should be taken or not. Its level during any other 6502 timing state appears to be irrelevant.

Just for the record, I think that branches behave differently - there's a discussion at viewtopic.php?t=1634

Also note that the tabulation in visual6502 has been corrected since some of the prior experiments. We now see that the usual case is that an interrupt input must be low at the start of a T0, normally, or low at the start of a T3, for branches. By "low at the start of" a cycle, I mean "low during the end of the previous cycle".

Attachment:
6502-IRQ.png
6502-IRQ.png [ 42.53 KiB | Viewed 1214 times ]


Cheers
Ed


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 15 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: