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

sleep and wake up

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



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

sleep and wake up
PostPosted: Mon Sep 08, 2008 1:10 pm     Reply with quote

hello, i just want to make sure i get it right.
1) sleep
I just disable interrupts which i dont want to be used for waking the PIC up.
I call sleep();
2) wake up
Interrupts enabled only will wake the PIC up.

Is there anything else i should be aware of?
I am using 18LF2420 particularly.

cheers
Meereck
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: sleep and wake up
PostPosted: Mon Sep 08, 2008 2:29 pm     Reply with quote

meereck wrote:
hello, i just want to make sure i get it right.
1) sleep
I just disable interrupts which i dont want to be used for waking the PIC up.
I call sleep();
2) wake up
Interrupts enabled only will wake the PIC up.
...

Yes, only the specific interrupts whose flags you have enabled will wake up the PIC. This will happen even if the Global Interrupt Enable is turned off. In that case, execution after wakeup will continue just after the Sleep instruction. Then you could poll to find out which interrupt flag without actually having an interrupt.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 08, 2008 2:38 pm     Reply with quote

You need to tell us what you want to do upon wake-up from sleep.

1. What interrupt do you want to use ?

2. Do you want to wake up and immediately continue operation of the program at the next line of code after the sleep() function ?

3. Or, do you want to wake-up and first execute an isr for that interrupt
before resuming execution at the next line after sleep() ?
Ttelmah
Guest







PostPosted: Tue Sep 09, 2008 3:16 am     Reply with quote

One more comment.
If not using an interrupt handler, you need to clear the interrupts used, before you next go to sleep.

Best Wishes
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Wed Sep 10, 2008 3:59 am     Reply with quote

hey guys,
thanks for the replies.
Here is what I basically need:
Sleep the PIC when there is no external action for particular time (I can call sleep() in a timer int routine or in the main loop --- I dont care). I have some external peripherals which would also be good to put in sleep mode by turning low a PIN of the PIC.
There arises one question : can be a pin held low when the PIC is in sleep?

Waking up the PIC should be carried out by action on any PORTB pins. So I was thinking about INT_RB. Therefore, if I get it right, before calling sleep(), I should disable all timer interrupts, and the only interrupt enabled should be INT_RB. Is that correct?
I dont care if the PIC executes the isr routine at first.

Thanks a lot!
Meereck
Ttelmah
Guest







PostPosted: Wed Sep 10, 2008 4:21 am     Reply with quote

Yes. Logic outputs are 'static', and can remain operated while the chip is asleep.

For low power, you should be careful to ensure that none of the PIC inputs is 'floating'. Especially consider whether turning off the other chips, might leave pins like this.

How many pins of port B, are available for INT_RB, depends on the PIC. On most, only the high four pins support this. Only some of the latter chips have this available on all the pins. Check the data sheet.

The sequence for 'wake up', without using an interrupt handler, would basically be:
Code:

disable_interrupts(global); //Turn off calling interrupt handlers
disable_interrupts(INT_TIMER0); //do this for all timers in use

//Operate your 'turn off' pin here

dummy=input_b(); //You must read the port, to ensure the latch matches
clear_interrupts(INT_RB);

enable_interrupts(INT_RB);
sleep();
delay_cycles(1); //This puts a 'nop' after the sleep instruction

disable_interrupts(INT_RB);

//Now enable all timer interrupts you want to use
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL); //re-enable calling interrupt handlers
//You may also want to clear the timer interrupts before re-enabling
//the global flag. They should have stopped running when the sleep was
//called, so it depends whether you want to 'catch' any timer overflows
//in the bits before/after the sleep.

Now, the chip will wake, if any of the inputs changes after the read of the port. So will not actually sleep if this occurs in the next couple of instructions. Otherwise, it'll wake, whenever an input changes. Remember that once 'asleep', wake-up, will take quite a few uSec, as the oscillator has to restart, and stabilise before the code starts running again. Also note that the instruction _after_ the sleep, is 'pre-fetched' by the chip, before it goes to sleep,so should really be a 'dummy' instruction, or some odd behaviours may appear (tests for example, will reflect the status before sleeping, rather than after, if put here). Hence the 'nop' in the code.

Best Wishes
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Wed Sep 10, 2008 6:19 am     Reply with quote

Thanx for the hints and the example src.
I am using 18LF2420. Entire PORTB with internal pull-ups can be used for the interrupt.
How can I assure none of inputs is floating? By external weak pull-ups? For example, I will be using an external chip with a RS232 interface connected to the PIC's HW UART.

have a nice day
Ttelmah
Guest







PostPosted: Wed Sep 10, 2008 10:06 am     Reply with quote

If the external RS232 driver is still powered, then 'no problem'. If you are turning this off, then I'd add external weak _pull downs_ (rather than pull-ups). Otherwise the protection diodes in the inputs/outputs of the other chips, could result in these being powered.

Best Wishes
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Wed Sep 10, 2008 3:48 pm     Reply with quote

great, that is exactly what I was looking for.
Cheers
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