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

somebody post a definitive answer to ULPWU.Please

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



Joined: 15 Jun 2011
Posts: 16

View user's profile Send private message

somebody post a definitive answer to ULPWU.Please
PostPosted: Mon Oct 10, 2011 7:46 pm     Reply with quote

I have tried numerous solutions to ULPWU interrupts. They all seem to work at times. But often they do not work when other interrupts are active after the call. Can someone please give example that will work all the time. The sleep_ulpwu() from compiler does not seem to work. I am using v1024 chip is pic 16f886.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 10, 2011 8:37 pm     Reply with quote

Quote:

I am using v1024

That is not your version. These are versions:
http://www.ccsinfo.com/devices.php?page=versioninfo
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Tue Oct 11, 2011 1:38 am     Reply with quote

Any interrupt that is itself enabled - so:
enable_interrupts(INT_RB);
_will_ wake the system from sleep if the interrupt flag gets set, _or_ will prevent the system sleeping, if the interrupt flag is set before you call the sleep instruction.

Basically, before sleeping, you need to turn off _all_ interrupts except the ones that you want to wake the chip. Also, unless you want the wake up interrupt(s) to call a handler, disable_interrupts(GLOBAL);
You also need to clear the interrupts you are going to use, if they may have become set while the chip was awake. All this before sleeping.

Now, after waking, if you don't want handlers to be called for the interrupt(s) that woke you, you need to clear the interrupts, and/or disable them.
Remember that to _clear_ an interrupt (in the case of one triggered by a hardware event), you may also need to clear the hardware event itself - so in the case of INT_RB above, you would need to read PORTB, before clearing the interrupt.

Remember also, that in some cases, failure to handle an interrupt, can leave the hardware in a locked condition. So (for instance), if you left the master clock running, and disabled INT_RDA, while you slept, then woke up, cleared the interrupt, and re-enabled it, you have a very good chance, that the UART will now be in a locked condition. Problem here is that if two characters have arrived, and not been handled, the UART will have overflowed. So here you would have to either use:
Code:

while (kbhit()) dummy=getc();

Then clear and enable the interrupt, or manually turn off CREN, read the buffer and re-enable the UART.

All of these are described in the data sheet, but the number of permutations is almost infinite (dozens of potential interrupt sources, which can be enabled/disabled in any combination, and may be used just to wake, and/or to call handlers). So there is no global 'example that will work all the time'. It'll depend totally on what combinations of interrupts you are using, and what you are actually doing with them....

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