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

Wake from sleep on pin change?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
blak3r



Joined: 11 Jan 2004
Posts: 45

View user's profile Send private message Visit poster's website

Wake from sleep on pin change?
PostPosted: Wed Sep 01, 2004 9:19 pm     Reply with quote

I want to design a circuit that the PIC can go to sleep and have extremely low power consumption. My existing circuit used a SCR to turn on when a button was pressed and turn it off when the current went below 5mA. However, the SCR drops the voltage from 3.0V to 2.2V and i'd like to drive an LCD which requires 3.0V.

I'd like the circuit to be able to run for a few years on a single coin battery (assuming it was in sleep mode the entire time).

I am using the internal clock to run the PIC so even in SLEEP mode there is considerable power consumption. I'm trying to design my circuit with the bare minimum number of components to have the lowest cost.

I want to wake up the device in response to a button being pressed. So, i'd be nice there was some type of pic which could shut itself down until an interrupt occured on a particular pin.

Any suggestions on a microcontroller that can do this?
_________________
"Everything should be made as simple as possible, but not one bit simpler" -- Albert Einstein

http://www.blakerobertson.com
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Wed Sep 01, 2004 10:43 pm     Reply with quote

Quoting from the PIC16F87x datasheet:

Quote:

12.13.1 WAKE-UP FROM SLEEP

The device can wake-up from SLEEP through one of
the following events:

1. External RESET input on MCLR pin.
2. Watchdog Timer Wake-up (if WDT was enabled).
3. Interrupt from INT pin, RB port change or peripheral interrupt.


So you can use the INT pin, or RB change interrupt for your purpose.
valemike
Guest







Re: Wake from sleep on pin change?
PostPosted: Thu Sep 02, 2004 6:02 am     Reply with quote

Hi,
I just finished an app that uses the pic16F627A (or pic16LF627a) that sleeps all the time until a pushbutton is pressed. if the button is pressed it will sound an alarm for 2 minutes, then go back to sleep. It runs off a 9V battery.

I connect a switch to RB0 as an external interrupt with which to wake the device up from sleep.
It's a fairly easy circuit to build. i can send you a .pdf of it, or i may even just post it here as an inline image if you like.



blak3r wrote:
I want to design a circuit that the PIC can go to sleep and have extremely low power consumption. My existing circuit used a SCR to turn on when a button was pressed and turn it off when the current went below 5mA. However, the SCR drops the voltage from 3.0V to 2.2V and i'd like to drive an LCD which requires 3.0V.

I'd like the circuit to be able to run for a few years on a single coin battery (assuming it was in sleep mode the entire time).

I am using the internal clock to run the PIC so even in SLEEP mode there is considerable power consumption. I'm trying to design my circuit with the bare minimum number of components to have the lowest cost.

I want to wake up the device in response to a button being pressed. So, i'd be nice there was some type of pic which could shut itself down until an interrupt occured on a particular pin.

Any suggestions on a microcontroller that can do this?
blak3r



Joined: 11 Jan 2004
Posts: 45

View user's profile Send private message Visit poster's website

PostPosted: Thu Sep 02, 2004 8:24 am     Reply with quote

This is good news for my design. I figured there must of been some PICs which allowed wake on interrupt. But, for some reason i overlooked it as an option when i looked into this a while back.

If anyone knows of a PIC with 18-20 I/O pins and has the wake on interrupt functionality please let me know. I'm constrained on board space so i wanted to avoid getting one of the PIC16F87x chips.

Thanks again
_________________
"Everything should be made as simple as possible, but not one bit simpler" -- Albert Einstein

http://www.blakerobertson.com
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Sep 02, 2004 8:50 am     Reply with quote

Quote:
If anyone knows of a PIC with 18-20 I/O pins and has the wake on interrupt functionality please let me know. I'm constrained on board space so i wanted to avoid getting one of the PIC16F87x chips.

I think the 'wake on interrupt' functionality is a standard PIC feature. Check the microchip website, especially the page with an overview of all nanoWatt devices. Some of these devices even contain provisions for switching to lower clock frequencies when no processing power is required and so save even more power.

The PIC16F627A is a nice one with 16 I/O lines. Other chips with more I/O lines (22 or 25) are available but are about double the price.
ernest



Joined: 11 Feb 2004
Posts: 51

View user's profile Send private message

How to Sleep when RB3=0 and Wake-up when RB3=1
PostPosted: Sun Oct 03, 2004 9:51 pm     Reply with quote

Hello,

I am trying to make my PIC16LF877A to SLEEP when the main power supply got cut-off and let it run on a backup battery. So, I'll need to switch off the power to the LCD, MAX232 IC and other components when running on backup supply in order to conserve power. How can I do that without affecting the way it works?
I need to freeze all processes but retain the current data and resume them after the main power returns.

Next, I need to wake up my PICmicro once the main power returns. How can I do that? I intend to connect the PIN RB3 to the 5V main power to sense for its availability.


Please advise...

Thank You.
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Mon Oct 04, 2004 1:01 am     Reply with quote

If you intend to power off external peripherals you will need to ensure that all inputs to the peripherals are at 0V otherwise they will attempt to source power from the inputs via the input protection diodes. IN the case of the MAX you may want to look at some of Maxims MAX232 variants design specifically to support this capability. With respect to the LED display - you will also need the PIC to retain a copy of the contents of the display so you can replace the contents on power up.
ernest



Joined: 11 Feb 2004
Posts: 51

View user's profile Send private message

PostPosted: Mon Oct 04, 2004 1:50 am     Reply with quote

Posted: Mon Oct 04, 2004 12:01 am Post subject:

If you intend to power off external peripherals you will need to ensure that all inputs to the peripherals are at 0V otherwise they will attempt to source power from the inputs via the input protection diodes. IN the case of the MAX you may want to look at some of Maxims MAX232 variants design specifically to support this capability. With respect to the LED display - you will also need the PIC to retain a copy of the contents of the display so you can replace the contents on power up.



As for the hardware part, it has been taken care of ie. the power to other peripherals such as LCD will be LOST once the main power to the MCU is cut-off as they share the same +5V supply. But in term of coding, how do I get my PIC16LF877A to SLEEP when the main power is cut-off. I intent to use PORTB to bring the MCU out from sleep but I only have PORT RB3 left. The rest of the PORTB I/O are being used LCD display. Basically, I plan to use RB3 to detect/sense the main +5V supply but HOW CAN I DO THAT?
- When RB3==0 (ie when main power is cut-off), the MCU must goto SLEEP
- When RB3==1 (ie when main power returns/comes back), the MCU must WAKE UP from sleep and resume from the previous operation

# How can I achieve the above ??? Confused

Thanks...
Ttelmah
Guest







Re: Wake from sleep on pin change?
PostPosted: Mon Oct 04, 2004 2:09 am     Reply with quote

blak3r wrote:
I want to design a circuit that the PIC can go to sleep and have extremely low power consumption. My existing circuit used a SCR to turn on when a button was pressed and turn it off when the current went below 5mA. However, the SCR drops the voltage from 3.0V to 2.2V and i'd like to drive an LCD which requires 3.0V.

I'd like the circuit to be able to run for a few years on a single coin battery (assuming it was in sleep mode the entire time).

I am using the internal clock to run the PIC so even in SLEEP mode there is considerable power consumption. I'm trying to design my circuit with the bare minimum number of components to have the lowest cost.

I want to wake up the device in response to a button being pressed. So, i'd be nice there was some type of pic which could shut itself down until an interrupt occured on a particular pin.

Any suggestions on a microcontroller that can do this?

As others have said, allmost any PIC. The only 'exceptions', are some of the small 8pin devices, that don't support the pin change interrupt, and a couple of models, which do a 'restart' from sleep, rather than a normal wake-up.
However one line of your post 'worries' me. You say that 'I am using the internal clock to run the PIC, so even in SLEEP mode there is considerable power consumption'. The oscillator _stops_ when the chip sleeps. The power consumption is tiny. I have a 16F628 here, which works roughly in this way. It sleeps, and wakes when a key is pressed, or once per minute on a signal from an external counter. This has been running for over two years, on a single 2032 cell.
It is quite a common failing, for people to think they are putting the chip to sleep, and for it not to really be sleeping, since quite a few 'conditions' have to be met before sleep will trigger. It may be worth double checking that you are genuinely getting the chip to sleep. Keeping the power consumption low when sleeping, also requires some careful 'thought' about other devices, and the pin connections made.
A caveat, is that 'wake-up', will take a significant time (the oscillator has to start and stabilise, before the chip wakens), so this limits the speed that can be used.

Best Wishes
ernest



Joined: 11 Feb 2004
Posts: 51

View user's profile Send private message

PostPosted: Mon Oct 04, 2004 2:29 am     Reply with quote

Thanks Ttelmah for replying...Hope I've not caused any confusion or misunderstanding, I have actually posted a new question or enquiry to this forum on a similar topic. So as opposed to the enquiry by blak3r, my enquiry is as follow:


As for the hardware part, it has been taken care of ie. the power to other peripherals such as LCD will be LOST once the main power to the MCU is cut-off as they share the same +5V supply. But in term of coding, how do I get my PIC16LF877A to SLEEP when the main power is cut-off. I intent to use PORTB to bring the MCU out from sleep but I only have PORT RB3 left. The rest of the PORTB I/O are being used LCD display. Basically, I plan to use RB3 to detect/sense the main +5V supply but HOW CAN I DO THAT?
- When RB3==0 (ie when main power is cut-off), the MCU must goto SLEEP
- When RB3==1 (ie when main power returns/comes back), the MCU must WAKE UP from sleep and resume from the previous operation

# How can I achieve the above ???
I have tried with the function below but it could not work. It actually worked well when I try out the function alone without my main codes.



#include <16F877A.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

// global flag to send processor into sleep mode
short sleep_mode;

// external interrupt when button pushed and released
#INT_EXT
void ext_isr()
{
static short button_pressed=FALSE;

if(!button_pressed) // if button action and was not pressed
{
button_pressed=TRUE; // the button is now down
sleep_mode=TRUE; // activate sleep
printf("The processor is now sleeping.\r\n");
ext_int_edge(L_TO_H); // change so interrupts on release
}

else // if button action and was pressed
{
button_pressed=FALSE; // the button is now up
sleep_mode=FALSE; // reset sleep flag
ext_int_edge(H_TO_L); // change so interrupts on press
}

if(!input(PIN_B3)) // keep button action sychronized wth button flag
button_pressed=TRUE;
delay_ms(100); // debounce button
} //end of ext_isr


///////////////////////////////////////////////////////////////////////
// main program that increments counter every second unless sleeping //
///////////////////////////////////////////////////////////////////////

void main()
{
long counter;

sleep_mode=FALSE; // init sleep flag

ext_int_edge(H_TO_L); // init interrupt triggering for button press
enable_interrupts(INT_EXT);// turn on interrupts
enable_interrupts(GLOBAL);

printf("\n\n");

counter=0; // reset the counter

while(TRUE)
{
if(sleep_mode) // if sleep flag set
sleep(); // make processor sleep if SLEEP_MODE is TRUE !!!
printf("The count value is: %5ld \r\n",counter); // if SLEEP_MODE is FALSE
counter++; // display count value and increment
delay_ms(1000); // every second
}
}


Thanks...
Ttelmah
Guest







PostPosted: Mon Oct 04, 2004 4:25 am     Reply with quote

There are quite a few 'caveats', without looking at the code.
Get a low voltage power supply monitor/switch chip. Maxim do a number of these. Have this trigger the normal 'interrupt' input to put the processor to sleep. Now you then have to look at your external connections. For instance, the RS232 output line, will at idle, by default be driving high. If the RS232 driver is then switched off, and the processor is put to sleep, this line will be drawing very significant current, trying to drive the isgnal high... You need to think of every line on the chip, and work out how it will be driving, and how to minimise the power when the other circuitry is switched off. Personally, I'd probably 'snapshot' the state of the lines, then drive them all low, and restore there state when power is re-applied.
Remember also that the changes really need to be triggered before the power disappears completely, since otherwise there is a risk of seeing incorrect signals as the external voltage decays. This is why a proper 'monitor' IC, which can normally be set to trigger the shutdown when the power falls blow a specific threshold, but also to delay the 'OK' wakeup for a few mSec, when the signal comes back (to allow the other circuitry to genuinely be 'on' before trying to drive it), is a good idea.
General comment, 'poll' the input you are using for the interrupt, and verify that the signal is 'high', before programming a 'high to low' interrupt, and check similarly when setting things the other way.
In common with some code posted on another thread, this code, has the potential to become 'locked' in the sleep loop. Remember that it will take time for the chip to wake up. hence it is possible that a signal could be received (which should clear the 'sleep mode' flag), but for the signal to not actually be present when tested in the interrupt handler. Consider adding a hardware latch to the button signals to avoid this. Also in 'sleep', the next instruction is 'pre-fetched', hence it is usually safer to add a 'nop' instruction (delay_cycles(1)), after the sleep instruction itself.

Best Wishes
ernest



Joined: 11 Feb 2004
Posts: 51

View user's profile Send private message

PostPosted: Mon Oct 04, 2004 11:32 am     Reply with quote

Thanks for the suggestions...

Looks like I need to study the whole circuits & the peripherals to check on the effects of switching them ON and OFF especially the MCU. I presume it's gonna take quite some time solve it.

So, is there any other shortcuts to this...as a temporary solution.
Rolling Eyes

It seems that the peripherals like the MAX232 IC consume huge amount of my backup power...

Cheers..
Will Reeve



Joined: 30 Oct 2003
Posts: 209
Location: Norfolk, England

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

PostPosted: Mon Oct 04, 2004 2:01 pm     Reply with quote

I think I remember reading that some PIC18 devices can detect their own VDD and interrupt on programmed levels, so you can get an interrupt when Vdd hits 3 volts for instance. If you use a largish capacitor on Vdd there will be enough time for this interrupt to run a sleep command?

Just a idea,

Will
Steve H.
Guest







PostPosted: Mon Oct 04, 2004 10:10 pm     Reply with quote

"Everything should be made as simple as possible, but not one bit simpler" -- Albert Einstein

Is that one 'bit' or 'byte' simpler?

;-)

Sorry I couldn't resist....

Steve H.
ernest



Joined: 11 Feb 2004
Posts: 51

View user's profile Send private message

PostPosted: Tue Oct 05, 2004 12:24 am     Reply with quote

Hi...

OK..temporarily, I'll let my PIC16LF877A run continuosly without sleeping as the currect that draws is not too high as long as I turn off all the other peripherals including the LCD. I tried to turn OFF the LCD but everytime after I turn off the power to the LCD and resupply it back later, the data that is being displayed would be JUNK!. From the Hyperterminal, I can see that the PIC is working fine and PIC can display the data correctly thru Hyperterminal as well. I have tried both ways ie. driving the LCD using external power supply and supplying the power to LCD using one of the PIC I/O pin.

So, what is wrong with the LCD?

The LCD works well when I turn ON the power together with PIC but after that, it doesn't work when I turn OFF the LCD power without turning off the PIC. I have tried setting all the I/Os to the LCD to Hi-Z as well as pull-up after the LCD is powered OFF.

What can I do to solve this problem? Confused

Thanks...
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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