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

Saving power for battery device [PIC16F722A]

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



Joined: 24 Mar 2022
Posts: 10

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

Saving power for battery device [PIC16F722A]
PostPosted: Thu Mar 24, 2022 4:23 am     Reply with quote

Hey there It's my first post so I will try my best to put in all the info in the post.
I have only started working with pics 4-5 months ago and yet learning.

I am currently working on a project using PIC16F722A with an external eeprom, sensor, LED, and a button. The program goes on in a loop checking for any change on inputs (button or sensor) and it's all working as intended but the device will be using a battery and need it to last for as long as possible.
[ccs c version 5.102]
So I was searching for how to use less power specially while going on in the loop (I have tried using watchdog & sleep but did nothing as it wake ups up frequently to check the pins). I also wanted to add some kind of a time counter. (I made one using delay for 500ms or 1sec and incrementing the counter)(and replaced the delay with the sleep function when I was trying watchdog).

I am still new to this so I am trying to explain as much as possible Smile

Also, when I put in "setup_wdt(WDT_ON)" I get an error saying "WDT_ON" is "unidentified identifier".

& that's a bit of my code:
Code:

#include <16F722A.h>
#device ADC=16

#FUSES WDT                      //Watch Dog Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV19                   //Brownout reset at 1.9V
#FUSES NOVCAP                   //VCAP pin disabled
#FUSES NOMCLR

#use delay(internal=4000000,restart_wdt)
#include <2404.C>


void hygienee(){
   if(hygiene_ == 0){            //12hours //a variable/flag for a switch
      h_counter++;
      sleep();                        //counting using WDT & sleep
      //delay_ms(500);          //simple delay counting
      if(h_counter == 86400){
         open_valve();
      }
   }
   if(hygiene_ == 1){            //24hours
      h_counter++;
      sleep();
      //delay_ms(500);
      if(h_counter == 172800){
         open_valve();
      }
   }
}

void main(){
   setup_wdt(WDT_1152MS);      //~1.125 s reset
   
   init_ext_eeprom();            // command to initiate the external eeprom
   delay_ms(3000);
   Initialization();
   
   bat_check();                  //battery check
   fresh_setup();
   transferattributes();         //copy data from eeprom to its variables
   powerupflush();
   
   while(true){
     
      PIR_detect();
      test();
      Setup_Buttoncheck();
      Lowbat_alert();
      hygienee();
   }
}


Hope I was able to fill in all the information needed!
temtronic



Joined: 01 Jul 2010
Posts: 9098
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Mar 24, 2022 7:07 am     Reply with quote

hmm, open up the device header (#include <16F722A.h> ) file.
About 3 'page downs' you'll see the predefined 'definitions' for the WDT 'options'. I do see WDT_ON in my file.\

Had a quick look at the datasheet. that PIC can wake up from sleep, using interrupts on PortB. I'd put the 'sensor' and 'button' on those pins. When coded properly the PIC will stay asleep UNTIL the button is pressed. No need to sleep, wake up, test button status, go back to sleep.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Mar 24, 2022 7:32 am     Reply with quote

The reason WDT_ON does not work, is that this chip does not support
software control of the watchdog. On this chip the watchdog is
enabled/disabled in the fuses only. Once it is on, it is on. No ability for
software control.

The first critical thing you do not show is which pins you are using, and
what you are 'doing' with the pins you do not use. It is critical that pins
are not left 'floating'. Every pin must be driven. So any pin that does not
have a connection externally, should be explicitly driven high or low
by your code.

The watchdog is of little use for a timer. It is very inaccurate. On your chip
the watchdog has nearly 3:1 range of timings it gives 10 to 27mSec.
Awful. The way to do a timer is to use an external clock chip. When you
wake read the time from this. The watchdog is not a way to get anything
remotely accurate. The 1.152 second nominal time can be anything
from 0.64 seconds to 1.728 seconds.

Now the other thing that will drink power is your LED. Even a low power
one will draw more than the PIC when on.

Then note in the data sheet. "All VCAP functions are disabled (not
recommended)". If you want to run without Vcap, you should be using
the LF chip, not the F chip. The regulator wastes you 50uA, even when
switched off. It actually draws less when enabled (just 30uA). So long
as you can guarantee that the supply is not going to go above 3.6v,
use the LF chip and don't worry about Vcap. Otherwise enable Vcap
and add the capacitor for this. This will save you power. Particularly
since with the LDO disabled the 50uA consumption is there even when
the chip is asleep. With the regulator enabled this drops to 5uA.

You can save power when 'on', by dropping the clock rate. Running at
250KHz, means the PLL is not enabled, and drops the power to well under
half what is used at 4MHz.
temtronic



Joined: 01 Jul 2010
Posts: 9098
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Mar 24, 2022 8:55 am     Reply with quote

hmm.curious am I

I assumed it could be controlled after seeing WDT_ON and WDT_OFF in the device header.

Downloaded the datasheet, again, as Windows put it 'somewhere'....

.. saw this
Quote:
The WDTE bit is located in the Configuration Word
Register 1. When set, the WDT runs continuously.
somewhere near section 3.4.2

The diagram kinda says WDT should be controllable.

Don't take much to confuse me these days though....
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Mar 24, 2022 11:42 pm     Reply with quote

Key bit in your post "located in the Configuration Word".

Fuse only.
Omarfarouk



Joined: 24 Mar 2022
Posts: 10

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

PostPosted: Mon Mar 28, 2022 3:53 am     Reply with quote

Ttelmah wrote:

The first critical thing you do not show is which pins you are using, and
what you are 'doing' with the pins you do not use. It is critical that pins
are not left 'floating'. Every pin must be driven. So any pin that does not
have a connection externally, should be explicitly driven high or low
by your code.


most of the pins are in use for other functions through the code and the pins not in use are all 0 volts as I measured them but I did not pull them down in my code.

Code:

#define temp PIN_A0
#define chargecheck PIN_A1
#define LED PIN_A2
#define openvalve PIN_A3
#define closevalve PIN_A4
#define button PIN_A7
#define tester PIN_B0
#define charge PIN_B1
#define mode PIN_B2
#define PIR PIN_B3
#define hygiene PIN_B4
#define five PIN_B5
#define ten PIN_B6
#define twenty PIN_B7


Ttelmah wrote:

Then note in the data sheet. "All VCAP functions are disabled (not
recommended)". If you want to run without Vcap, you should be using
the LF chip, not the F chip. The regulator wastes you 50uA, even when
switched off. It actually draws less when enabled (just 30uA). So long
as you can guarantee that the supply is not going to go above 3.6v,
use the LF chip and don't worry about Vcap. Otherwise enable Vcap
and add the capacitor for this. This will save you power. Particularly
since with the LDO disabled the 50uA consumption is there even when
the chip is asleep. With the regulator enabled this drops to 5uA.


About power the board will be powered by 4 batteries which is 6V input. So I will definitely be above the 3.6V. I want the board to stay for 1 year or so. And I think the key fix is to find a way to save on power while waiting for any inputs(sensor or button).

temtronic wrote:

using interrupts on PortB. I'd put the 'sensor' and 'button' on those pins. When coded properly the PIC will stay asleep UNTIL the button is pressed.

That might actually help but I will not be able to measure the time passed tho. I think...[/quote]
Omarfarouk



Joined: 24 Mar 2022
Posts: 10

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

PostPosted: Mon Mar 28, 2022 3:57 am     Reply with quote

temtronic wrote:
hmm.curious am I

I assumed it could be controlled after seeing WDT_ON and WDT_OFF in the device header.

Downloaded the datasheet, again, as Windows put it 'somewhere'....

.. saw this
Quote:
The WDTE bit is located in the Configuration Word
Register 1. When set, the WDT runs continuously.
somewhere near section 3.4.2

The diagram kinda says WDT should be controllable.

Don't take much to confuse me these days though....


yea but it only turns on and never goes off. thb I can't even test if it will work or not. CCS does not accept these commands for this chip at all.
temtronic



Joined: 01 Jul 2010
Posts: 9098
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 28, 2022 5:51 am     Reply with quote

As Mr T pointed out, it's a 'configuration FUSE' , so it'll ALWAYS be on(or off).
I looked at the diagram,assumed ( thought ), GREAT 'controlled' by a bit in a register...later found out it's NOT an accessable bit.....

Actually controllable WDT is a 'new' thing to me, then again I remember when single chip UARTs came out. Smile
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Mon Mar 28, 2022 6:59 am     Reply with quote

On the pins, 'being at 0v', if you test with a meter, does not mean they
will stay at 0v. If a pin floats (they all do), it can get into the transition
region of the chip's inputs. This then means a lot of extra power is drawn.
Just in your code, set all the unused pins low (output_low(PINxx);).
temtronic



Joined: 01 Jul 2010
Posts: 9098
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 28, 2022 7:04 am     Reply with quote

hmm... battery powered for a year...
Some things you need to consider

actual temperature the product is in
power really used
ideal pullups on pins
read Microchip's AN806
size allocated for 'battery'
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Mon Mar 28, 2022 7:26 am     Reply with quote

Key thing he can do is switch to the LF chip. The overhead for the regulator
on the F chip _even when turned off_, is wasting power. Seriously this will
probably about double the battery life!...
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