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

Strategies for low power battery operation.....

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



Joined: 09 Aug 2004
Posts: 97

View user's profile Send private message

Strategies for low power battery operation.....
PostPosted: Wed Sep 08, 2004 3:09 pm     Reply with quote

Hi,

I've designed a remote wireless temperature sensor based on the PIC12F675 micro. The last step of the project is to make the circuit battery powered for truly remote operation. I plan to power my circuit with two CR2032 lithium coin cell batteries, so low power operation is a must. The circuit only needs to transmit temperature data every 5 minutes or so (this is not critical), so I'd like to "Sleep" between temperature readings to reduce the battery consumption. To get such a long sleep period, it seems that I need to count a number of short "naps" totalling the complete sleep time. To do this I'd load an EEPROM memory location with a count value and then go to sleep. Each time the WDT timed out I'd wake up, decrement the count and check to see if I have reached the terminal count. If so, I'd transmit my data, and if not, I'd go back to sleep. I think this would work, but it doesn't seem too elegant. Is there a better way? BTW, I'm using the 4 MHz internal oscillator. I'm also transmitting my data at 1200 baud, so anything I do has to keep this in mind!

Thanks,

John
_________________
John Morley
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Sep 08, 2004 4:43 pm     Reply with quote

Why not use RAM instead of eeprom?
LomasS
Guest







PostPosted: Thu Sep 09, 2004 2:55 pm     Reply with quote

John,
I had a similar requirement except that I needed to transmit a data burst using an off the shelf low power 433MHz transmitter every 20 mins.
I achieved this as you described, using the WDT with maximum prescaler waking every 2.304 secs. this increments a (RAM) counter which is tested for the number of 2.304s wakeups in 20 mins, if not reached goes back to sleep.
This seems to work OK for me, for accelerated testing I reduced the Tx time to 10 sec intervals which gave me a battery (2032) life of 45 days at which point the battery dropped to 2.37V and the Tx module stopped working, although the 12F675 carried on. Scaling this to the real Tx interval of 20 mins should allow me a >2 year battery life.
Although the life will depend entirely on the application.

I made some measurements on my circuit and got a current drain of 2.3uA in sleep, 540uA awake (and my circuit drew 10.4mA transmitting)
If you think about the relative time spent in sleep vs waking and immediatly sleeping again, the amount of time drawing 540uA is not so bad.

I trust this helps.
Steve.
John Morley



Joined: 09 Aug 2004
Posts: 97

View user's profile Send private message

PostPosted: Tue Sep 14, 2004 9:19 am     Reply with quote

Hi All,

This seems like an easy concept, but I'm having trouble getting a simple test program going to test the long duration sleep method I described. Here is my code:

Code:
#include <12F675.h>
#fuses INTRC_IO,WDT,NOBROWNOUT,NOPROTECT,NOPUT,MCLR

#use delay(clock=4000000)

#define Data_Output PIN_A4

#use rs232(baud=9600, xmit=Data_Output, invert)       // for the serial LCD module...

void main()
{

int SleepCount=0;

      switch (restart_cause())
      {
   case NORMAL_POWER_UP:
            printf("Normal power up!\r");
            break;

        case WDT_FROM_SLEEP:
            printf("Restarted processor because of watchdog timeout!\r");
      SleepCount++;
           break;   
   }
   
   printf("SleepCount: %u", SleepCount);   
   setup_wdt(WDT_2304MS);
   Sleep();
}


I'm using compiler version 3.162. When the first program runs I would expect to see the "Normal power up" message, followed by the "Restarted processor" message at 2.304 second intervals. The strange thing is that the program seems to operate differently each time it is run. I almost never get the "Normal power up" message. Mostly I see "SleepCount: 0" and then nothing else, and occasionally "SleepCount: 0", followed by Restarted processor", followed by SleepCount: 1" and then nothing else.

It seems like the processor is going to sleep and restarting at least some of the time, but it is never sustained, and it is never consistent. Any ideas what might be going on? Have I missed something perhaps?


Thanks,

John
_________________
John Morley
Ttelmah
Guest







PostPosted: Tue Sep 14, 2004 9:40 am     Reply with quote

John Morley wrote:
Hi All,

This seems like an easy concept, but I'm having trouble getting a simple test program going to test the long duration sleep method I described. Here is my code:

Code:
#include <12F675.h>
#fuses INTRC_IO,WDT,NOBROWNOUT,NOPROTECT,NOPUT,MCLR

#use delay(clock=4000000)

#define Data_Output PIN_A4

#use rs232(baud=9600, xmit=Data_Output, invert)       // for the serial LCD module...

void main()
{

int SleepCount=0;

      switch (restart_cause())
      {
   case NORMAL_POWER_UP:
            printf("Normal power up!\r");
            break;

        case WDT_FROM_SLEEP:
            printf("Restarted processor because of watchdog timeout!\r");
      SleepCount++;
           break;   
   }
   
   printf("SleepCount: %u", SleepCount);   
   setup_wdt(WDT_2304MS);
   Sleep();
}


I'm using compiler version 3.162. When the first program runs I would expect to see the "Normal power up" message, followed by the "Restarted processor" message at 2.304 second intervals. The strange thing is that the program seems to operate differently each time it is run. I almost never get the "Normal power up" message. Mostly I see "SleepCount: 0" and then nothing else, and occasionally "SleepCount: 0", followed by Restarted processor", followed by SleepCount: 1" and then nothing else.

It seems like the processor is going to sleep and restarting at least some of the time, but it is never sustained, and it is never consistent. Any ideas what might be going on? Have I missed something perhaps?


Thanks,

John

Key thing. Setting 'sleep_count=0', is done at the start of main, so it'll never advance...
Instead, just declare 'sleep_count', without initialising it. Then in the branch for 'normal_power_up', set it to zero.

Best Wishes
John Morley



Joined: 09 Aug 2004
Posts: 97

View user's profile Send private message

PostPosted: Tue Sep 14, 2004 12:20 pm     Reply with quote

Ttelmah,

Yes, of course, I can't believe I missed such an obvious error! Unfortunately, the fact remains that the code does not work as intended. Frequently it seems to go through at least one or two "sleep cycles", and then freezes Crying or Very sad . This should be very simple but its causing me to really pull my hair out!

Thanks,
_________________
John Morley
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 14, 2004 12:37 pm     Reply with quote

Quote:

Frequently it seems to go through at least one or two "sleep cycles", and
then freezes . This should be very simple but its causing me to really
pull my hair out!


The primary resource for solving problems would be the 12F675 data
sheet. This is the section to read:
9.7.1 WAKE-UP FROM SLEEP
http://ww1.microchip.com/downloads/en/DeviceDoc/41190c.pdf

Reading what that section says, and then one other tidbit of information
that you get from this board (that CCS puts a hidden sleep ins. at
the end of main), will answer your question.
John Morley



Joined: 09 Aug 2004
Posts: 97

View user's profile Send private message

PostPosted: Tue Sep 14, 2004 3:36 pm     Reply with quote

PCM,

OK, I got it to work as expected by adding some code so that the end of Main is never reached.

Thanks for the gentle "encouragement" to RTFM Very Happy ! Actually, I had read that section, but the importance of what happens immediately after SLEEP, and the SLEEP after Main that CCS adds didn't fire the right synapses in my brain! Oh well, I guess my concentration has been broken lately by the frustration caused by the "blue screen of death" that my ICD-U40 seems to be randomly triggering while developing code for the 12F675.......

Thanks,
_________________
John Morley
Guest








PostPosted: Fri Oct 29, 2004 11:07 am     Reply with quote

What is the code you added it, I reach the point as you described here, which the sleepcount does not add up?

Thank you
Guest








PostPosted: Fri Oct 29, 2004 11:13 am     Reply with quote

I added a while loop, now is working. thank you!
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