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

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: NMI idle timing
PostPosted: Tue Feb 17, 2004 9:21 pm 
Offline

Joined: Fri Aug 30, 2002 2:05 pm
Posts: 347
Location: UK
Is there a minimum time that NMI must be idle, e.i. high, before the next edge?

In trying to couple a 3Com 3C509B to my Vic 20 it will work but eventually it seems to miss an NMI interrupt and then stops working (because the interrupt is missed it is never cleared, effectively blocking further interrupts).

I suspect that the NMI returns high for less than 500ns if another interrupt from the card is pending when the previous one is cleared, trouble is it happens too infrequently to see/measure with what I have.

The annoying thing is it works /most/ of the time.

Lee.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Feb 17, 2004 10:12 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1748
Location: Sacramento, CA
Lee,

I do not have a firm answer to your question. I do have a possible "working theory".

The WDC W65C02S docs on the NMI say:
Quote:
A negative transition on the Non-Maskable Interrupt (NMIB) input initiates an interrupt sequence after the current instruction is completed. Since NMIB is an edge-sensitive input, an interrupt will occur if there is a negative transition while servicing a previous interrupt. Also, after the edge interrupt occurs no further interrupts will occur if NMIB remains low. The NMIB signal going low causes the Program Counter (PC) and Processor Status Register information to be pushed onto the stack before jumping to the interrupt handler. These values are used to return the processor to it's original state prior to the NMIB interrupt.


So, for this nesting to work properly, the first NMI must have time to push the PC and SR onto the stack and load the NMI vector into the PC before a second NMI can be processed (7 cycles). Assuming a 1MHZ clock, then 7us is needed in between each NMI.

I wish I had some proper test gear to validate that.

Good luck!

Daryl


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Feb 17, 2004 10:39 pm 
Offline

Joined: Fri Aug 30, 2002 2:05 pm
Posts: 347
Location: UK
I've been browsing the datasheets as well - still no enlightenment.

The problem is not the time metween successive interrupts, that is many 10's of ms but the time between NMI returning high and the next -ve edge.

As each interrupt is generated the NMI routine sets a flag and exits with the NMI line still held low. The main routine sees an interrupt flagged and processes it, once this is done the interrupt is acknowledged by writing to the card which releases the NMI line. If there are any further interrupts pending a new interrupt is generated almost immediately. It's this time which I suspect is too short.

I've tried to test the NMI response using a routine that generates an interrupt repeatedly under software control butthat works all the time. Unfortunately you can't queue the software interupts on the card like it does the FIFO interrupts.

I've had an idea to use a 74LS74 as a resettable external NMI latch, I'll try that tonight.

Cheers,

Lee.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Feb 17, 2004 11:47 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1748
Location: Sacramento, CA
I understand better now. What value of pull-up resistor is used on the NMI line? Purhaps its not rising fast enough for the 6502 to recognize a valid high. The docs recommend 3k ohm. Maybe a lower value (2.2k) will improve the response??

I wish I had access to a scope!!!

Daryl


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Feb 18, 2004 12:05 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8545
Location: Southern California
Hi Lee,

The slow float-up of a newly released IRQ or NMI line is why WDC made their 65c22 with an active pull-up transistor.  It no longer allows wire-ORing, but the RC time-constant problem is fixed.

The processor samples the interrupt lines on the falling edge of phase 2 at the end of an instruction, and there's a small setup time required—around 20ns.  If it finds the NMI\ input low, it will begin the sequence only if the previous look (a whole instruction ago) had found the line high.  So if the line is low at the end of an instruction, and goes up and then back down before then end of the next instruction, the processor will not have seen it, and will not respond.

I just finished the 6502 interrupts primer, so I ought to be able to document that and tell you exactly where you can read it for yourself in their literature.  Unfortunately right now I just have to say I can't remember where I read it, respond quickly so you can keep going on your project, and come back and edit this later if I find I had any inaccuracy.

Garth

* * * * * EDIT:  See my next post, four posts down, for new information from an experiment. * * * * *

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


Last edited by GARTHWILSON on Sat Feb 21, 2004 9:16 am, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Feb 18, 2004 12:08 am 
Offline
User avatar

Joined: Sun Dec 29, 2002 8:56 pm
Posts: 460
Location: Canada
Even though NMI is edge triggered, it is probably synchronized internally to the processor clock to avoid metastability issues. Meaning it may need to have a high period of at least one processor clock period in order to be able to recognize another interrupt. (The edge is likely detected using a clocked circuit.) Since the VIC is only running at 1MHz I'd make sure the NMI is high for at least 2 cycles or 2us. Could use some sort of pulse extender.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Feb 18, 2004 11:41 am 
Offline

Joined: Tue Sep 03, 2002 12:58 pm
Posts: 336
It's all in the timing diagram: page 20 of the W65C02 datasheet. NMI is sampled on the falling edge of phi2. There's a 10ns setup and 10ns hold time. You'll need to synchronise it yourself.

NMI is not edge triggered in the sense that the hardware is looking for an edge. It's looking for a steady state at particular moments in time. A change in the state triggers the interrupt, not the state itself (as in the level-sensitive IRQ input).


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Feb 18, 2004 6:38 pm 
Offline

Joined: Fri Aug 30, 2002 2:05 pm
Posts: 347
Location: UK
Well much tearing out of hair and gnashing of teeth has gone on.

Rise and fall times were suspect at first but measuring them revealed <20ns rise and 8ns fall, plenty fast enough.

I couldn't think of a way to repeatedly trigger the successive interrupts under software control so I couldn't measure the NMI high time with any great certainty.

I built an NMI latch using half a 74LS74, this is edge triggered and is arranged in such a way that it is reset under program control, this is done as the first operation in the NMI routine after saving the registers. Guess what? It worked! The program now fell over in a completely new and subtle way - doh!

The final answer seems to have a lot to do with how the 3Com cards respond in 8 bit mode and what happens when you poll status registers.

While I'm not thrilled with the fix, it means the processor sitting idle for 1ms on every packet, it is working at the moment. Before work I left the Vic 20 being repeatedly pinged (ICMP echo request) by three PCs and it hadn't missed a beat in 40 minutes or so.

All this will eventually be posted to my site, I've done 20 or so pages (including picture pages) on this so far.

Who'd have thought getting ISA cards to work with the 6502 bus would be so fraught?

Lee.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Feb 21, 2004 9:11 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8545
Location: Southern California
Ok, to pick up from my earlier post:

I couldn't find a straight, definitive answer from my books on the cycle-by-cycle response to the NMI input, so I tried it on a Rockwell 65c02.

I found that whether the NMI line is doing a short negative pulse or a positive one, as long as the processor can see a high state at one phase-2 falling edge and a low state at the very next phase-2 falling edge, regardless of where those edges are in the progress of an instruction, the NMI is registered and the sequence will begin when the instruction is finished.  IOW, it's not just the last ph2 falling edge of an instruction that looks at the NMI input (as I previously thought), but rather every ph2 falling edge.

The NMI-high time in Lee's case would not have to be even a whole cycle long (let alone a whole instruction long) if it went up shortly before a ph2 falling edge and was pulled back down right after the same edge.  So if it were timed just perfectly on a processor whose NMI set-up and hold times were 10ns, it is conceivable that an NMI pulse hardly longer than 20ns would indeed be recognized.  If the exact timing is not known however, the pulse needs to be over one cycle in length to be guaranteed any recognition.

Of course if you're using a passive pull-up resistor on the NMI\ line, the greater concern will be whether the line had time to float (charge) up to a logic-high state before being pulled back down.

It would be too tedious to test this single-clock NMI pulse matter on all clocks of all instructions and all manufacturers, but I expect I'd get the same 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?


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

All times are UTC


Who is online

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