View previous topic :: View next topic |
Author |
Message |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
Sleep current too high. |
Posted: Wed Jan 23, 2013 4:31 pm |
|
|
I'm trying to run a PIC18F1320 for months/years from a single 3V coin cell.
With no activity, I want it to go to sleep, but don't seem to be able to reduce the current to low enough levels.
I've stripped a sample board to the minimum to investigate.
Schematic looks like this:-
Code: |
10k ------
+3V -----WWWW------|MCLR |
| |
0V -----WWWW--<|--|A2 |
220R LED | |
| |
+3V ---------------|VDD |
| | |
--- | |
---100n | |
| | |
+0V ---------------|VSS |
| |
------
All other pins pulled to VSS via individual 10k.
|
Complete test code is:-
Code: | #include <18F1320.h>
#fuses INTRC_IO,NOWDT
#use delay(clock=1000000) // Start at 1MHz
int i;
// main flashes LED to prove its working then goes to sleep
void main()
{
setup_adc_ports(NO_ANALOGS);
for (i = 0; i < 10 ; i++)
{
output_toggle (PIN_A2);
delay_ms(200);
}
// Now go to sleep
set_tris_a(0xff);
set_tris_b(0xff);
setup_oscillator(OSC_31KHZ); // Slow down to min
sleep(); // send to sleep
while(1) {;} // loop here for ever
}
| Having read the data sheet, I was hoping to reduce current in sleep mode to low nA, but it's persisting at ~20uA level.
I've tried forcing pins to be O/P both high and low with similar effect.
What am I missing?
Mike |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Wed Jan 23, 2013 4:51 pm |
|
|
Any other internal peripherals ? Some default to being 'on'..thus drawing power.
like...
comparators
ADC
timers
I2C
UARTs
2nd osc/clocks
portB pullups
I know...you've probably checked....but...
hth
jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jan 23, 2013 4:59 pm |
|
|
Compile and look at your fuses at the end of the .LST file. It shows
Brownout is enabled by default.
Code: | Configuration Fuses:
Word 1: C800 INTRC_IO FCMEN IESO
Word 2: 1E0E PUT BROWNOUT NOWDT WDT32768
Word 3: 8000 MCLR
Word 4: 0081 STVREN NOLVP NODEBUG
Word 5: C003 NOPROTECT NOCPB NOCPD
Word 6: E003 NOWRT NOWRTC NOWRTB NOWRTD
Word 7: 4003 NOEBTR NOEBTRB |
Data sheet shows typical 19 ua current usage at 3v. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Wed Jan 23, 2013 5:34 pm |
|
|
temtronic:-
Thanks for the hint. I will have to double check. There's a long list and they're not all obvious to a simple guy like me.
PCM programmer:-
Hadn't considered brown out at all. Looks like a good candidate, the current you're quoting is close to my measured value.
It's nearly mid-night here in the UK, will have to wait till tomorrow.
Thank you again.
Mike |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Thu Jan 24, 2013 3:03 am |
|
|
I would leave the LED pin set as output, and drive this pin low. An LED as a load, won't ensure the pin can't float into the transition region, and consumption will go up if this happens.
Glad to see you have all the other pins driven, but seems unnecessary complex, why not get rid of the resistors, and just drive the pins with the PIC?. The PIC outputs, 'static' holding a pin at a logic level draw basically nothing (femto amps).
Key is to ensure that all pins _are_ driven when the chip is asleep.
Best Wishes |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Thu Jan 24, 2013 4:35 pm |
|
|
Hi Ttelmah:-
On my board I actually have most pins driving LEDs, and a couple connected to switches, all active low.
To investigate the current consumption problem I simply assembled a bare board with one LED only, to prove the board was running.
I pulled all the I/Os to 0V because it was easy to dab on 10k SMDs from each pin to a 0V track which conveniently runs underneath the DIL PIC.
I had already tried making the pins all O/P, the current in sleep mode was roughly the same for both input or output modes.
What I posted was exactly the latest version of my testing. (I was simply being honest and trying out all possibilities.)
I will take your advice and go for driving all I/Os.
Hi PCM programmer.
I changed the #fuses to include nobrownout.
The current in sleep mode has now dropped to ~3.5uA.
A long way off the nA level the data sheet lead me to expect.
I suppose I could live with it.
I can now anticipate battery life being comparable to shelf life.
Still leaves a nagging doubt there's something I've overlooked.
Will report on further progress if and when.
Mike |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Thu Jan 24, 2013 6:16 pm |
|
|
Mike.. use a bigger battery !
While it might be a nice 'exercise' to reduce power to almost zero..most of us can't afford the time($$$$) to figure out the 'details'.
I still think some silly 'default' value for a peripheral or 'deafult 'fuse' setting is the culprit.
Boils down to how much effort you'll use for what gain. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Fri Jan 25, 2013 1:44 am |
|
|
Going low, can be necessary in some cases. The factor of error here is so large, that it is important to work out what is wrong, since it could reflect something that will cause problems later.
Other things to consider:
I'd be explicit on all the fuses. NOFCMEN, NOIESO. Though the other oscillators should be 'off' when asleep, it is worth making sure there is nothing trying to happen here.
I'd make sure that the timer1 oscillator is off in the code.
setup_timer_1(T1_DISABLED);
If this was trying to run, it'd explain the problem.
Normally I'd say to make sure it is not the voltage regulator drawing the extra power, but you are running directly from the battery so it doesn't apply. However make sure there is not a resistive load somewhere - can you remove the PIC and measure the current without it?. Something silly like a capacitor that has gone high leakage, or a hair whisker on the board. Triple check on your pulled up pins, that they are sitting at the supply rail. If one is even 0.1v down, it implies something is drawing current here.
Best Wishes |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Jan 25, 2013 3:53 am |
|
|
My first hit in Google "site:ccsinfo.com/forum power consumption"
http://www.ccsinfo.com/forum/viewtopic.php?t=45460
Here the same PIC18F1320 was discussed and disabling the Fail-Safe Clock Monitor solved his problem with high current in sleep mode. Code: | #FUSES NOFCMEN //Fail-safe clock monitor disabled |
Edit: I now see Ttelmah suggested this one already.
Last edited by ckielstra on Fri Jan 25, 2013 8:20 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Fri Jan 25, 2013 4:27 am |
|
|
We tend to be quite good at having similar thoughts!.
The two things I found were FSCM, and the timer1 oscillator.
Best Wishes |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Fri Jan 25, 2013 10:21 am |
|
|
I can remove the PIC, (it's socketed). Without the PIC in place current is <1nA.
With the PIC in place current is now down to ~4nA.
At this level I'm struggling to measure it.
The biggest culprits were NOBROWNOUT and NOFCMEN.
I can see from the data sheet that Timer1 defaults to running.
I've not been able to detect any improvement by either stopping Timer1 or adding NOIESO to #fuses. I'm not saying that there's no gain to be had; changing the oscillator to 32kHz now no longer produces a noticable benefit either.
I'm going to have to do a board scrub to remove flux residues if I want to go any further.
Thank you everyone. You've been so helpful
Mike |
|
|
drh
Joined: 12 Jul 2004 Posts: 192 Location: Hemet, California USA
|
|
Posted: Fri Jan 25, 2013 10:28 am |
|
|
Timer 0 in ON at reset/power up. Have you turned it OFF? _________________ David |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Fri Jan 25, 2013 10:35 am |
|
|
Thanks David,
I had mis-read the data sheet and missed that one.
Will do.
Mike |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Fri Jan 25, 2013 11:04 am |
|
|
With the clock stopped, Timer0 stops as well.
The point about Timer1, is it has it's own oscillator, which will keep running. This _should_ default to off, but 'just in case', this was why I suggested turning it off. The fact the power doesn't change, says that it was correctly not starting the oscillator.
Best Wishes |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Wed Feb 06, 2013 5:33 pm |
|
|
Hopefully, the last word from me on this thread.
On my project I have mostly outputs which drive LEDs by pulling down.
There was still excessive current in sleep mode with the outputs driven high.
The culprit was A4 which is open drain on many PICs.
A burden resistor across the LED reduced sleep current from 10's uA to low nA level.
Mike |
|
|
|