View previous topic :: View next topic |
Author |
Message |
edi
Joined: 22 Dec 2003 Posts: 82
|
PIC16F1508 sleep current |
Posted: Sun May 12, 2013 6:47 am |
|
|
During sleep the PIC16F1508 consume ~17uA.
The wake up supposed to be only by pressing the TACT on RA3.
Can I reduce the sleep current?
(ver 4.128)
Code: |
#include <16F1508.h>
#device adc=16
#FUSES PUT //Stabilizing time at P.U
#FUSES WDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES WDT_SW //No Watch Dog Timer, enabled in Software
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(int=4000000)
short ON=0;
short OFF=1;
short ONSEG = 0;
short OFFSEG = 1;
short PRESS=0;
int16 Ton=800; // 7seg segments on time (function of refresh rate vs. on time)
int8 CMP_REF=2; //Comparator POS reference
int8 sensetivity=6; // number of ADC reads
int16 Sensor_level=600; // ADC level threshold ut of 12bit resolution
int8 count=0;
short sleep_mode;
int16 Poff_timeout=0;
#byte porta=0x0c
#byte trisa=0x8c
#byte portb=0x0d
#byte trisb=0x8d
#byte portc=0x0e
#byte trisc=0x8e
#bit DIGITR = portc.0
#bit DIGITL = portc.1
#bit SEG_A = porta.5
#bit SEG_B = porta.4
#bit SEG_C = portc.5
#bit SEG_D = portc.4
#bit SEG_E = portc.3
#bit SEG_F = portb.7
#bit SEG_G = portb.5
#bit TACT = porta.3
void init()
{
porta = 0b00111111; // | | | AAA | BBB | TCT | IRQ | PGC | SEN |
trisa = 0b00001001; // | | | OUT | OUT | IN | OUT | OUT | IN |
portb = 0b11111111; // | FFF | | GGG | | | | | |
trisb = 0b00000000; // | OUT | OUT | OUT | OUT | OUT | OUT | OUT | OUT |
portc = 0b11111111; // | SDO | SS~ | CCC | DDD | EEE | DOT | LFT | RGT |
trisc = 0b00000000; // | OUT | OUT | OUT | OUT | OUT | OUT | OUT | OUT |
PORT_A_PULLUPS(0b00001000); //
}
#INT_COMP
void isr()
{
...
}
#INT_RA
void RA3_isr()
{
...
}
void main()
{
unsigned int8 old_count=0, hold_time,i;
SETUP_WDT(WDT_OFF);
disable_interrupts(GLOBAL); // all interrupts OFF
disable_interrupts(INT_RA); // RA interrupt OFF
SETUP_DAC(DAC_OFF);
setup_comparator(NC_NC_NC_NC);
setup_oscillator(OSC_4MHZ);
init();
sleep_mode=true;
CLEAR_INTERRUPT(INT_RA3);
ENABLE_INTERRUPTS(INT_RA3_H2L);
SETUP_TIMER_1(T1_INTERNAL | T1_DIV_BY_8);
while(1)
{
if (PRESS)
{
...
}
if (sleep_mode)
{
setup_comparator(NC_NC_NC_NC);
setup_vref(VREF_OFF);
disable_interrupts(GLOBAL);
for (i=0; i<5; i++)
{
display_bye();
}
count=0;
CLEAR_INTERRUPT(INT_RA3);
ENABLE_INTERRUPTS(INT_RA3_H2L);
setup_dac(DAC_OFF);
// setup_comparator(NC_NC_NC_NC); // With this line the current during sleep become much higher to ~30uA !!!
setup_comparator(CP1_A1_DAC | CP1_INT_H2L | CP1_HYST);
sleep();
sleep_mode = false;
...
|
|
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1342
|
|
Posted: Sun May 12, 2013 7:39 am |
|
|
I might have missed it, but where are you setting it to low power sleep mode (see VREGPM in the datasheet) as opposed to normal sleep?
Normal sleep mode is 10-12uA typical (but can be more) while low power sleep mode is 0.2-0.3uA typical (still could be a little more).
I haven't used this chip, so the sleep() command might do this by default for that chip, but I don't know for sure either way...something to check.
I'm not familiar with this specific chip, but it looks like (at a glance) that you are leaving the comparator on during sleep ( setup_comparator(CP1_A1_DAC | CP1_INT_H2L | CP1_HYST); ), which also takes some current.
EDIT: Also something to consider, when I work on extremely low powered systems, I tend to start out much simpler than you are doing. I set up a program that is just a simple main where everything is turned off in the way I want it asleep and then finish with a simple while loop:
Code: |
void main(){
//code to set outputs for unused pins
//code to turn off everything here
while(TRUE){
sleep();
}
}
|
I don't bother with interrupts or having a sequence count down to sleep. I just setup everything to be off and check the current to make sure I have everything correct. You might try simplifying your setup more like that, at least until you have the current number you are looking for.
Last edited by jeremiah on Sun May 12, 2013 7:44 am; edited 1 time in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9215 Location: Greensville,Ontario
|
|
Posted: Sun May 12, 2013 7:43 am |
|
|
sure you can !
But...
you'll have to read the datasheet to see which internal peripherals you must turn off or disable to reduce the current.
also look at the power levels when you reduce Vdd.
also check power vs. Fclk. the slower you clock the less power.
download the Microchip appnote about reducing power.it's about an 8 pin PIC,ext ADC,serial to pc 'project'. A great starting point to 'do the math'.
Have to ask why? I find it a LOT easier to just use a bigger capacity battery.
hth
jay |
|
|
edi
Joined: 22 Dec 2003 Posts: 82
|
|
Posted: Sun May 12, 2013 8:15 am |
|
|
thanks, will try your suggestions. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun May 12, 2013 11:20 am |
|
|
There is an errata on the VREGPM bit:
Quote: |
Under the following conditions:
• ambient temperatures below 0 degrees C
• while in Sleep mode
• VREGCON configured for Low-Power Sleep
mode (VREGPM = 1 )
On very rare occasions, the LDO voltage will drop below
the minimum VDD, causing unexpected device Resets.
Work around -
For applications that operate at ambient
temperatures below 0 degrees C, use the LDO voltage
regulator in Normal-Power mode (VREGPM = 0 ).
|
16F1508 errata sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/80536D.pdf |
|
|
|