CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

adc interrupt

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
fariq23



Joined: 29 Nov 2010
Posts: 8

View user's profile Send private message

adc interrupt
PostPosted: Tue Nov 30, 2010 12:46 am     Reply with quote

can someone tell how the adc interrupt work..
it is same as timer interrupt??
mahmudur.rahman



Joined: 08 Nov 2010
Posts: 3

View user's profile Send private message

Re: adc interrupt
PostPosted: Tue Nov 30, 2010 2:34 am     Reply with quote

fariq23 wrote:
can someone tell how the adc interrupt work..
it is same as timer interrupt??


My suggestion is study you MCU data sheet. I think you will have a picture how it works. I did the same.

You need to enable global interrupt and ADC interrupt and configure the A/D interrupt...
    • Clear ADIF bit
    • Set ADIE bit
    • Set PEIE bit
    • Set GIE bit


Embarassed I hope this is helpful enough... Rolling Eyes
Ttelmah



Joined: 11 Mar 2010
Posts: 19543

View user's profile Send private message

PostPosted: Tue Nov 30, 2010 3:26 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group