Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Tue Nov 30, 2010 3:26 am |
|
|
The ADC interrupt, signals that an ADC conversion is complete. Nothing else.
Now, in normal use, it is pointless. The ADC takes typically about 25uSec (on some of the later PIC's down to perhaps half this), to go from being triggered to completing a conversion. Getting into and out of an interrupt handler takes this long, so for a simple conversion, there is really no point in using the interrupt.
There are two exceptions. The first, is when you want a conversion 'at' an exact time. One of the options for the CCP, is to have it trigger the ADC to start converting. If you set this up, and then add a handler for the ADC interrupt, the sequence becomes:
CCP triggers - starts the ADC
ADC converts
ADC interrupt fires
You can then have an ADC interrupt handler, that just reads the result (read_adc(ADC_READ_ONLY)), and you get an ADC result for a conversion that happened _at_ a precisely defined moment in time.
The second exception, is when you want the best accuracy from the ADC. Depending on the noise sources in your system, stopping the processor from running for the conversion, may help. This is the one situation where you use the internal ADC clock. The sequence here is:
setup_adc(ADC_CLOCK_INTERNAL) -
- must use this clock, since CPU clock will stop.
disable the GLOBAL interrupt flag.
disable all other interrupt sources.
clear the ADC interrupt.
enable the ADC interrupt -
- you are now setup so that only the ADC wakes the chip from sleep.
read_adc(ADC_START_ONLY); //trigger an ADC conversion
sleep(); //The chip will now sleep _till_ the conversion completes
delay_cycles(1); //NOP instruction
read_adc(ADC_READ_ONLY);
Here, you use the interrupt, _not_ to trigger an interrupt handler, but to wake the chip from sleep.
The ADC will _not_ interrupt on it's own. The conversion has to be started by something else (you or the CCP), and the interrupt fires when the conversion has finished.
Best Wishes |
|