6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Wed Sep 25, 2024 4:29 am

All times are UTC




Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 55 posts ]  Go to page Previous  1, 2, 3, 4
Author Message
 Post subject: [85.55] Tip of the day
PostPosted: Sun May 26, 2002 6:11 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8517
Location: Southern California
Tip of the day, #42: Ghost interrupts

Tonight I had some puzzling "ghost" interrupts.  My 65c02 workbench computer's Forth interrupt handler was going through the list of installed interrupt-service routines (ISRs) and none of them claimed responsibility to take care of the interrupt.  The error message was "missing ISR".  What's going on?  I wrote and installed an ISR with the lowest possible priority so it would get executed only if the higher-priority ones failed to service the interrupt.  Instead of servicing a mysterious interrupt, this low-priority ISR's job was to look at the status registers and interrupt-enable registers of everything that had the ability to produce an interrupt.  It too said everything was clean.

The project used an interrupt every 20 microseconds (a rate of 50,000 per second) from a 65c22 VIA's timer, and the program running in the foreground turned the interrupting off and on several times per second, producing one-tenth-second bursts of interrupts.  What was happening was that sometimes the VIA would pull the IRQ line down during the instruction that was telling the VIA to disable that interrupt.  The line came down quickly, but the pull-up resistor takes a few clock cycles to get the line back up to a logic 1 again.  (See tip #2.)  The processor responded to the interrupt and took the vector; but by the time the first ISR could check to see if it was this VIA that caused the interrupt, the VIA's interrupt flag register said "None here!"-- like ringing the doorbell and running.

Attachment:
cartoon_5.gif
cartoon_5.gif [ 40.75 KiB | Viewed 2757 times ]

My immediate solution was to make the ISR sequence assume that a "ghost" interrupt like this came from the source that was just disabled.  In other words, for a few microseconds after the interrupt source is disabled, it's ok to exit the ISR sequence without action when no cause of interrupt was found.  Another possibility would be to do SEI, then disable the VIA's interrupt, then do CLI again after a safe amount of time.  After some discussion on the Yahoo 6502 forum, I believe this SEI/CLI method is best.  You may need to save the information as to whether the processor was accepting interrupts right before the SEI, so you don't CLI if it was temporarily inappropriate.  Another method suggested, which I see problems with for certain scenarios, is that the main routine just use a semaphore to tell the ISR to disable the source of the interrupt the next time the interrupt occurs.  This would probably be more useful in true multitasking, which I was not doing.  (Multitasking, by the way, is quite doable in Forth on a 6502, with minimal overhead.)

The fact that the ghost interrupt problem could occur is something simple I should have thought of long ago, but previous projects never had me disabling interrupts several times per second during a fast stream.  The less-than-handful of times it happened, it just seemed like a freak thing that was not repeatable, and it wasn't worth my time to hunt it down.

WDC's VIAs' IRQ outputs are not wire-ORable open-drain outputs, so they may produce less trouble of this kind.

Garth



I will keep improving these existing tips; but for further tips and more info on the ones above, see my 6502 primer.  The "circuit potpourri" page (which I keep adding things to) has so far, including diagrams and links to code to run them:
  • a very basic whole-computer schematic
  • Using the 6522's shift register for tons of output bits
  • Using the 6522's shift register for tons of input bits
  • Using the 6522's shift register for both input and output
  • SS22: Using the 6522's shift register for a link between computers
  • Converting to and from higher-voltage logic
  • driving relays from logic-level signals
  • High-voltage shift registers
  • Interfacing to I²C
  • Interfacing to SPI and Microwire
  • Keypads and keyboards
  • Displays
  • Printers
  • Digital-to-analog (D/A) converters, or DACs
  • Digital potentiometer
  • Analog-to-digital (A/D) converters, or ADCs
  • A note about A/D and D/A jitter (and other performance considerations)
  • Jeff Laughton's circuit tricks, for ultra-fast I/O (single-cycle!), and re-mapping op codes
  • Non-typical power-supply circuits run by the 6522 and digital components
(and I intend to add some analog supporting circuits)

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


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 55 posts ]  Go to page Previous  1, 2, 3, 4

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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:  
cron