|
|
View previous topic :: View next topic |
Author |
Message |
gabirelms
Joined: 28 Jun 2014 Posts: 38
|
Timer1 during sleep high consumption |
Posted: Sat Jun 28, 2014 3:04 pm |
|
|
Hi all, I'm working in a simple idea: any time I press a button, MCU has to wake up and write current timer in the memory.
Device will be in sleep mode 99% of the time, maybe only press the button 4 or 5 times in a day.
I'm using PIC16LF1459 with a button cell, and my problem is power consumption during sleep.
I don't need real time, just a counter, when I start up the device it starts counting from zero, I don't need an accurate counter.
I checked sleep mode, power consumption is only 0.1uA or less, and it can interrupt when I press the button.
The problem is to calculate time during sleep. I'm using timer1 during sleep with an external 32khz crystal.
But the device wake-up on an overflow and this consumes a lot of power, I checked power during sleep in this case, one second 0.1uA, one second 700uA, changing continuously. Is this normal ?
Please I need help with these questions:
1. Can I use timer1 during sleep, without using interrupt on overflow ? I only want my device to wake up when I press the button.
2. If device must wake-up on an overflow to keep timer1 counting, what power consumption is good ? I think 700uA is very high.
3. I'm thinking about another option: Not to use sleep mode. Then I will try to disable all peripherals, and leave timer1 running. Can I use LFINTOSC in this case ? Or is it better to use LP mode with external crystal ?What power consumption can I expect in this case ?
Data sheet, page 1: Timer1 Oscillator: 600 nA @ 32 kHz, typical. Is it possible to disable everything, and leave only Timer1 running with less than 1uA ?. This is much better than sleep mode for me.
Any help would be appreciated
Thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Jun 28, 2014 4:08 pm |
|
|
Quote: | I checked power during sleep in this case, one second 0.1uA, one second
700uA, changing continuously. |
It shouldn't run 700ua for one second. Post your test program. Make it short but complete (compilable, with #fuses, etc.). |
|
|
gabirelms
Joined: 28 Jun 2014 Posts: 38
|
|
Posted: Sat Jun 28, 2014 4:44 pm |
|
|
Ok, I will post my code on monday (not at home now)
I'm reading power consumption using a multimeter, it is hard to read because it changes. But before I enable timer1 power consumption was always 0.1uA.
Is it normal that power changes due to timer1 interrupt ? What should I expect ?
I will be very happy if I can get a continuous 5uA during sleep |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19482
|
|
Posted: Sun Jun 29, 2014 1:00 am |
|
|
Even 0.1uA is rather high....
Critical thing with 'sleep' is to make _sure_ you set everything to reduce power. Things that are often missed are that (for example), a pin left floating as an 'input', will draw more power, than the same pin set as an output!. A floating pin, if it floats into the 'transition region' (where the internal gate is switching levels), results in a spike of power every time it switches. The output FET set to drive, provided there is no load, draws almost nothing.
However you do say 'or less', so things probably are OK.
The 700uA though is silly. It suggests something is happening like a pin being driven in your 'I'm awake' code. Key is that your sequence should be to just handle incrementing the timer overflow register, if this is the cause of waking, and then go straight back to sleep. It possibly sounds as if the code is going straight into the 'do something' part of your code, assuming the button was the reason for waking, and only after a lot of time, 'realising' this wasn't the case. If handled correctly, the extra power will be under a couple of uA, for just a handful of uSec every couple of seconds.
You want the overflow, or the timer can't give you a 'time' beyond a couple of seconds, or a 'count' beyond 65535.
Best Wishes |
|
|
gabirelms
Joined: 28 Jun 2014 Posts: 38
|
|
Posted: Sun Jun 29, 2014 4:53 am |
|
|
Thanks for your reply.
Sometimes I get 0.1uA, and sometimes 0.0uA, my multimeter cannot read less than 0.1uA.
What you said give me a lot of hope, that means power should be 0.1uA during 2 seconds, and 2uA during 1u second.
I'm very new to microchip, and I'm not sure of my results.
During wake-up, if PIC16 HFINTOSC run at 4Mhz, that means power should be only 100uA ? Datasheet page 1: Operating Current: 25 uA/MHz @ 1.8V, typical.
I got around 2mA, but Im using 3.6v battery.
By the way, I have 2 load caps with the external crystal, but I see some designs using only crystal, without caps.
How can that be done ? If I use a crystal with only 4pF load cap, can it work without caps ?
For example this one:
www.abracon.com/Resonators/ABS06-107-32.768kHz-T.pdf
Edit: Thoses design are with TI mcu or Atmel mcu, maybe those mcu have built-in load capacitors. Anybody tried with PIC ? |
|
|
gabirelms
Joined: 28 Jun 2014 Posts: 38
|
|
Posted: Mon Jun 30, 2014 2:32 am |
|
|
Compiler 5.015
Code: |
MCU used : PIC16LF1459
Clock : 2MHz while sleep
Compile used : CCS
// Fuse settings fCCS compiler
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#fuses MCLR
#fuses PUT
#fuses NOWDT
Void timer1_interrupt()
{
second++;
time_sleep++;
if(second>59)
{
second=0;
minute++;
}
if(minute>59)
{
minute=0;
hour++;
}
if(hour>23)
{
hour=0;
day++;
}
}
Sleep command settings used
// Timer1 settings
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
// t1con reg settings
TMR1CS0=0;
T1CKPS1=0;
T1CKPS0=0;
T1OSCEN=1; //1
T1SYNC=1;
TMR1ON=1;
// End timer1 settings
USBEN=0; // USB disable
SDO_TRIS=0; // SPI SDO
SCK_TRIS=0; // SPI_SCK
//SDI_TRIS=0;
SPI_DO = 0;
SPI_SCK = 0;
output_bit(PIN_B4,0); // clear pins unused
output_bit(PIN_B6,0);
output_c(0x00);
output_bit(CS,1);
IOCBN=0x00;
IOCB7=1; // wake up interrupt
INTCONRABIE=1;
INTCONRABIF=0;
SLEEP(); |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19482
|
|
Posted: Mon Jun 30, 2014 3:07 am |
|
|
First, start to use CCS!....
For example, the timer setup, is one line, using the 'setup_timer_1' command in CCS.
Then 'rethink' slightly.
Basically, get rid of the global interrupt enable. Then work like:
Code: |
output_low(PIN_B4); // clear pins unused
output_low(PIN_B6);
output_c(0x00);
output_high(CS);
disable_interrupt(GLOBAL);
enable_interrupt(INT_TIMER1);
enable_interrupt(INT_RB7);
//Now chip will wake on a change of RB7, or on the timer
do
{
sleep();
delay_cycles(1); //the instruction after a sleep should always be
//a 'NOP'. This instruction is 'prefetched' when you sleep, and can
//give unexpected results.
if (INTERRUPT_ACTIVE(INT_RB))
{
//Handle your RB7 changed interrupt here
// - remember must read the port and should clear the changed
//latch as well as clearing the interrupt.
}
if (interrupt_active(INT_TIMER1))
{
timer1_interrupt(); //call the handler for the timer
clear_interrupt(INT_TIMER1);
//and go back to sleep ASAP
}
} while (TRUE); //unless you want to exit the loop
|
The point is that you don't want to waste time actually calling an interrupt handler. Two interrupts are enabled, and can therefore wake the chip. All you do, is test which one (or both) have triggered, handle their jobs, and as soon as you have done this, go back to sleep. |
|
|
gabirelms
Joined: 28 Jun 2014 Posts: 38
|
|
Posted: Mon Jun 30, 2014 3:54 am |
|
|
Worked! thanks so much.
With SPI flash connected, without timer I got 6.6uA.
Now, with SPI flash, and timer working during sleep, I got 7.9uA.
Do you think it is a good result ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19482
|
|
Posted: Mon Jun 30, 2014 4:42 am |
|
|
The flash is obviously the big 'drinker' here. Question perhaps whether there is a lower power version/equivalent, or whether you can fully disable this (FET to turn off it's supply!...)?. However the 1.3uA sounds a much more sensible figure from the PIC.
6.6uA, from something like a 240mAHr coin cell, would potentially give over 4 years operation....
Best Wishes |
|
|
gabirelms
Joined: 28 Jun 2014 Posts: 38
|
|
Posted: Mon Jun 30, 2014 5:40 am |
|
|
Ttelmah, I really appreciate your great support, thanks again :-)
By the way, do you know anything about this:
Quote: | I have 2 load caps with the external crystal, but I see some designs using only crystal, without caps.
How can that be done ? If I use a crystal with only 4pF load cap, can it work without caps ?
For example this one:
www.abracon.com/Resonators/ABS06-107-32.768kHz-T.pdf
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19482
|
|
Posted: Mon Jun 30, 2014 7:40 am |
|
|
There are chips specifically designed to do this. For instance the DS1307 RTC. It has slightly higher than normal pin capacitances on the oscillator pins, and specifies a crystal load capacitance (12.5pF).
Now, you have to think carefully, since the capacitance seen by the crystal, is not the pin capacitance. It is the capacitance _between_ the pins that is seen as the crystal load. With just the pins, and PCB, these two capacitances paralleled together, in series with each other. This is why (for instance), you will typically see something like 30pF capacitors being used on crystals with 20pF specified capacitance. It sees the 30pF, paralleled by the track capacitance (perhaps 5pF), and the pin capacitance (another 4 to 5pF), all paralleled together (40pF), in series with the same capacitances on the other pin, giving 20pF across the crystal.
Most crystals will happily oscillate without the correct capacitance, just be slightly more 'in error', than they are specified to be. With a crystal designed for a low capacitance like 4pF, provided your pad layout is reasonably careful (so only gives perhaps 4 to 5pF of capacitance), you will be very close indeed to the correct value. The unit is designed for exactly this reason. |
|
|
gabirelms
Joined: 28 Jun 2014 Posts: 38
|
|
Posted: Mon Jun 30, 2014 7:52 am |
|
|
I'm already placing my order in digi-key. Thanks |
|
|
|
|
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
|