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 support@ccsinfo.com

problem with int0 and adc routine

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



Joined: 16 Jan 2008
Posts: 61

View user's profile Send private message

problem with int0 and adc routine
PostPosted: Mon Jan 12, 2009 5:23 pm     Reply with quote

Hi guys,

I am using pic18f25k20.

I have following adc routine.

Code:
setup_adc_ports(sAN1);    //|VSS_VDD); // setup port RA1/AN1 as an analog
   
////setup_adc(ADC_CLOCK_INTERNAL);  //|ADC_TAD_MUL_0);
set_adc_channel(1);             // setup channel 8 for battery reading
adc_value = read_adc();
setup_adc_ports(NO_ANALOGS|VSS_VDD); // set back the ports in digital mode
setup_adc(ADC_OFF);


now whenever i execute this routine my external interrupt 0 become disabled. i check and tested a code and i found out "setup_adc(ADC_OFF)" causing interrupt 0 not to work.

if i use "setup_adc(ADC_CLOCK_INTERNAL)" then interrupt works.

my external interrupt routine is:
disable_interrupts(INT_EXT); //! don't reenable in ISR
clear_interrupt(INT_EXT);

//! timer 0 setup for debouncing time
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
clear_interrupt(INT_RTCC); //! enable debouncing timer0 interrupt
enable_interrupts(INT_RTCC);
set_timer0(TIMERVALUE);



i am enabling interrupt in timer routine.

regards:
nehal
_________________
nehal
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 12, 2009 5:51 pm     Reply with quote

You need to setup the ADC ports before you read the ADC.
The ADC needs to be enabled before you read it.

See this post which shows how to setup the ADC. It shows the
correct order for the setup statements.
http://www.ccsinfo.com/forum/viewtopic.php?t=32168&start=1
nehallove



Joined: 16 Jan 2008
Posts: 61

View user's profile Send private message

PostPosted: Tue Jan 13, 2009 2:03 pm     Reply with quote

it turns out if i use ADC_CLOCK_DIV_8 for setting up adc it works but if use ADC_CLOCK_INTERNAL then it is same problem. does anybody has any idea?

thanks you for a prompt reply PCM Programmer.

regards:
nehal
_________________
nehal
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jan 13, 2009 2:15 pm     Reply with quote

Read the A/D section of the PIC data sheet. It says this about the
internal A/D clock:
Quote:

When the device frequency is greater than 1 MHz, the FRC clock source
is only recommended if the conversion will be performed during Sleep.

Since you are almost certainly running the PIC at a frequency greater
than 1 MHz, the INTERNAL ADC clock is not recommended.
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