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

sleep() function problem with 18f2520

 
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

sleep() function problem with 18f2520
PostPosted: Wed Jan 30, 2008 2:52 pm     Reply with quote

Hi guys,

I am working on the project in which i have to wake up the unit from sleep mode after detecting the comparator output of the 18f2520's port pin.

Problems which i face are ...
1. comparator interrupt works pretty good without putting sleep function in. but whenever i put sleep function comparator interrupt fires even if there isn't possible condition to fire it up. and unit comes out of sleep.

2. if i remove sleep function then it works great. so is it debugger which messing it up or something else.

Code:
setup_comparator(A0_A3_NC_NC_OUT_ON_A4); // a0 & a3 comparator
setup_vref(FALSE); // input and a4 is output


enable_interrupts(INT_COMP); // Initialize the Comparator interrupt
enable_interrupts(GLOBAL); // Enable the requested interrupts

sleep();
while(1){
output_low(PIN_C2);
delay_ms(100);
output_high(PIN_C2);
}

#INT_COMP
void isr()
{
disable_interrupts(INT_COMP);
clear_interrupt(INT_COMP);
delay_ms(1000); // *** TEST CODE, wait to see if it works
output_high(PIN_C2); // *** TEST CODE, turn on LED
return;
}

regards:
_________________
nehal
Ttelmah
Guest







PostPosted: Wed Jan 30, 2008 3:31 pm     Reply with quote

_Clear_ the comparator interrupt before enabling it.
Remember it will already be set, if _any_ comparator event has already occured.
Unless you really 'need' to have the interrupt handler, get rid of it, and remove the 'global' interrupt enable. The interrupt will _wake_ the chip when it fires, even if the global enable is off, and execute the next instruction. So:
Code:

while (true) {
   clear_interrupt(INT_COMP);
   enable_interrupts(INT_COMP); // Initialize the Comparator interrupt
   sleep();
   delay_cycles(1); //The instruction after the sleep is 'prefetched'
   //This ensures it is a NOP
   output_low(PIN_C2);
   delay_ms(1000);
   output_high(PIN_C2);
}

With your comparator setups, this should sleep, and respond immediately (only a couple of instruction times delay), when the interrupt triggers, while the 'interrupt handler' approach, will add about 30 instruction times delay to this.

Best Wishes
Guest








PostPosted: Thu Jan 31, 2008 11:48 am     Reply with quote

hey thanks for the help.

i already did same way you showed me, but it didn't work. it doesn't go to sleep at all. it remains in constant loop. It responses to comparator interrupt but if i remove comparator interrupt then it doesn't have any problem going to sleep. Is any relationship between comparator interrupt and sleep mode???

nehal
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