Processing Multiple Interrupts
This example uses a Timer2 interrupt to blink the LEDs. The time interval used by Timer2 is determined by the value of the analog potentiometer connected to AN8. The conversion routine collecting the value on AN8 is triggered by an interrupt. This sample program does the following:
- Initializes the I/O ports
- Internalizes Timer2 and the ADC modules
- Implements Timer2 and ADC interrupt service routines
- Enable interrupts

Support Functions

main() and Interrupt Service Routine

QUESTION: Rather than have the Timer2 ISR start the next analog-to-digital conversion wouldn't it make more sense to have the ADC ISR start a conversion?
ANSWER: In this example, the Timer2 period is such that several thousand A-D conversions could occur between timer interrupts. Since only the last ADC result is placed in PR2, all other ADC values captured in a period would not be used. Having the Timer ISR restart the ADC reduces the number of interrupts.