Electronic – Does an external interrupt interrupt ADC or does ADC stall interrupt

adcinterruptspic

I'm working on an RTC application with a 1Hz clock attached to the external interrupt pin on a PIC16f887. I also have continuous ADC operations happening along with the 1Hz clock.

My question is whether the ADC or the interrupt would get priority if both occur at the same time? What if the interrupt occurs during an ADC operation? Is the operation halted to allow the interrupt to be executed? This would obviously invalidate the reading.
Or does the interrupt wait for the ADC to finish?

Best Answer

No, the interrupt occurring has no effect on the A/D. The A/D runs from the instruction clock or its own clock, depending on how you set it up. Both these keep going during a interrupt unless you deliberatly execute a SLEEP instruction to stop the processor clock.

At most, the 1 Hz interrupt could delay the interrupt routine processing the A/D conversion done, if you are doing this by using interrupts at all. There is no requirement that A/D results be handled by using interrupts. Even if so, the A/D will perform its conversion and write the result into ADRESH:ADRESL regardless of whether the processor is taking a interrupt or not. In fact, the processor itself is not really "in" a interrupt. That's only a software abstration. When the right conditions are met for a interrupt, the processor executes a call to location 4 and turns off the GIE bit in INTCON. That's all. The rest is up to firmware.

Once the A/D has finished a conversion, the result will be available in ADRESH:ADRESL. It is up to the firmware what to do with that. The value will stay there until a new conversion is completed. If the firmware doesn't start a new conversion until reading the result of the previous, then nothing can be lost. If a new conversion is started automatically, then it is possible for the previous data to be lost if the firmware didn't get around to reading ADRESH:ADRESL in time. Look at the acquisition and conversion time of the A/D and the instruction rate, and you will see there are generally plenty of instruction cycles to grab a conversion result, even if a new conversion is started automatically by the special event trigger of a CCP module. Just make sure the clock tick interrupt code is not so long that it takes longer than it takes the A/D to make a new result. This should be easy. Any lengthy processing is best handled by setting a flag and letting the foreground code get around to it when it gets around to it. The interrupt code should handle only the immediate servicing of the device.