View Single Post
  #3   Spotlight this post!  
Unread 13-08-2003, 19:03
Lloyd Burns Lloyd Burns is offline
Registered User
FRC #1246 (Agincourt Robotics)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Toronto
Posts: 292
Lloyd Burns is an unknown quantity at this point
Skip over the next paragraph - goto '2'

'1' - Write your thoughts out and store them, you'll want 'em later. On the PIC's (Microchip's abbreviation of "Programmable Interface Controller"), when an interrupt request is sensed, the program counter, which has the location of the instruction being executed, is saved, and refilled by the PIC with "4", the location at which you've cleverly put a small program which saves the registers, figures out which interrupt has occasioned this call, and the "services" the interrupt with an appropriate action. Then it stuffs the old values back in, and resets the program counter to what it was, and goes on from where it left off. Read your thoughts so you recall them, then Return From Interrupt.

'2' - You cleverly put a jump to a location beyond your interrupt service, so the PIC will jump to an executable program on start-up. Before you go on, service an interrupt by going to '1': remember what we're talking about, and where you came from. Carry on with '3'

'4' - At the risk of hearing from interrupt junkies, if you have a loop in your program which is fast enough that you won't notice the time it takes to act on an arising external condition, you don't NEED to use interrupts if you poll your inputs regularly. Return From Subroutine.

'3' - interrupts are available on demand - meaning you program the PIC to respond to things like internal timer overflows, internal watchdog timer timeouts (same thing-different time reg), change in the state of a chosen input pin, overflow from the count associated with a particular pin; all depending on the model of PIC and how you've designed your circuit. As mentioned, some communication processes are capable of generating interrupts, too. Do subroutine '4', now: remember where you are so you can come back. On return, goto '5'.

'5' - You may have noticed that the interrupt service was little different from a subroutine, except that a subroutine is called during the flow of a program, and you have an idea of what you're doing. Time is not as important, so finish what you're doing, and gosub. In an interrupt, it is important to do it NOW - the delay from int to service is called the "Latency" of the interrupt. Just store everything, service it, recall your "thoughts', and get back smoothly to what you were doing before. You want to make the service take as little time as possible, too, because multiple interrupts are sometimes possible.