View previous topic :: View next topic |
Author |
Message |
hcalex
Joined: 18 May 2011 Posts: 5
|
Power consumption in SLEEP mode |
Posted: Wed May 18, 2011 1:40 pm |
|
|
Hey,
my first post here .
I use the CCS compiler 4.109 and a PIC 18F1320. My problem is that the current (160µA) is too high in sleep mode and I can't find the reason :(.
At the moment my circuit looks as follows: +4.5V at VDD, GND at Vss and a 10k resistor between VDD and MCLR.
My configuration looks like this:
Code: | #include <18F1320.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOPUT //No Power Up Timer
#FUSES PROTECT //Code protected from reading
#FUSES NOPUT //No Power Up Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES MCLR //Master Clear pin enabled
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#use delay(clock=4000000)
#use I2C(master, sda=PIN_B1, scl=PIN_A3, slow=100000) |
And here is my code:
Code: |
void setupPIC()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_wdt(WDT_OFF);
setup_timer_0(T0_INTERNAL|T0_DIV_64|T0_8_BIT);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_ccp1(CCP_OFF);
ext_int_edge( 0, H_TO_L);
clear_interrupt(INT_EXT);
enable_interrupts(INT_EXT);
}
void goSleep()
{
disable_interrupts(GLOBAL);
SET_TRIS_B(0b00000000);
SET_TRIS_A(0b00000000);
output_a(0);
output_b(0);
sleep(SLEEP_FULL);
}
void main()
{
setupPIC();
initPinConfiguration();
goSleep();
while(TRUE);
}
|
I have no other peripherals connected to the pins of the pic or any other things which would consume power. But my PIC consumes 160µA which is definitely to much (data sheet says 1µA).
Did I miss something to configure or is my code incorrect?
Please help me! Thanks a lot! |
|
|
mharris27
Joined: 22 Apr 2005 Posts: 15
|
|
Posted: Wed May 18, 2011 1:49 pm |
|
|
Just throwing it out there because it happened to me....you do have your programmer disconnected right? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 18, 2011 2:00 pm |
|
|
Quote: | #use I2C(master, sda=PIN_B1, scl=PIN_A3, slow=100000)
SET_TRIS_B(0b00000000);
SET_TRIS_A(0b00000000);
output_a(0);
output_b(0);
|
You probably have pull-up resistors on your i2c, and you've set SDA and
SCL to a low level. This will draw current. Try setting those two pins to
floating, since they have pull-ups on them. |
|
|
hcalex
Joined: 18 May 2011 Posts: 5
|
|
Posted: Wed May 18, 2011 2:18 pm |
|
|
No, to find the reason for the leakage i removed the pull-ups from my circuit. Now, I also removed the #use I2C line in my code.
But now it is very strange... I measure a power consumption over 1.2mA which drops to 145µA after 3 seconds. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Wed May 18, 2011 2:58 pm |
|
|
Your pullup on MCLR will draw 45ua..(4.5/10,000)... |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Wed May 18, 2011 11:20 pm |
|
|
Quote: | Your pullup on MCLR will draw 45ua..(4.5/10,000)... |
Why? The pin is input only and thus unaffected by the tri and output states.
I don't see the reason for the reported current consumption at first view. However, I don't know what happens in initPinConfiguration() and it should be clarified that none of IO pins (exept for MCLR) is connected to a pull-up resistor or other circuit, that can be sourcing current.
P.S.: If permanently powered I2C slaves are connected to the circuit, SDA and SCL should rather stay at 1 in sleep mode. The same may apply to other signals with idle state high. Generally, design of circuits utilizing "nanopower" sleep requires a detailed analysis of each IO pin signal.
Another comment. I global interrupts stay apparently disabled, otherwise it would matter that the external interrupt isn't preceeded by a pin initialization. Also, there's no IRQ handler. |
|
|
hcalex
Joined: 18 May 2011 Posts: 5
|
|
Posted: Wed May 18, 2011 11:43 pm |
|
|
Quote: | Another comment. I global interrupts stay apparently disabled, otherwise it would matter that the external interrupt isn't preceeded by a pin initialization. Also, there's no IRQ handler. |
Yes, I disabled everything to find to origin of the power consumption. In the normal code, I have of course an IRQ handler and don't disable global interrupts. It's only to eliminate possible errors. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu May 19, 2011 1:23 am |
|
|
I generally feel uncomfortably with code posted in snippets. If you aren't able to identify the problem, you should post the exact code used in your test.
The ultimate test tools are in my opion:
- measuring where the current flows
- checking all SFR states with MPLAB and a hardware debugger |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Thu May 19, 2011 2:30 am |
|
|
I'd be wondering if the chip actually is going to sleep.
There are two 'levels' to interrupt enables. The 'global' flag, which disables _service_ for all interrupts, and the individual enables. If an interrupt is enabled, while the global flag is 'off', it is still checked for sleep. So, if the INT_EXT flag gets set at any point, the code will either not go to sleep, or wake up.
Then, FvM, is 'dead right'. You should make a small _working_ program. which is the code you actually test. It is surprising how often, it is some single line 'missed' from a snippet, which makes a huge difference to what is happening. For any of ups to test and see what happens, the code needs to be compilable and complete.
Then, are you actually measuring the consumption on the 4.5v line, or is this being fed from a regulator?. It is common to forget that regulators themselves draw power, and also sometimes can become less stable when loads drop.
Best Wishes |
|
|
hcalex
Joined: 18 May 2011 Posts: 5
|
|
Posted: Thu May 19, 2011 2:37 am |
|
|
At the moment the above posted code IS my test code. I compile exactly this code and program my target with that. I measure the current between the battery and the PIC. The only pins of the PIC which are connected are VSS, VDD, and MCLR. I measure +4.5V on VSS and MCLR and 0V on all other pins. Even the ICD is not connected to my circuit. I program my PIC externally.
Today I changed the multimeter, but I got the same result (~140µA). If someone can post an example for a sleep code where you really know that the PIC is going into sleep without any other current consumptions please tell me. Then I will try and can eliminate errors caused by the C code. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu May 19, 2011 4:43 am |
|
|
Quote: | So, if the INT_EXT flag gets set at any point, the code will either not go to sleep, or wake up. |
I must admit, that I wasn't aware of this well documented behaviour. Apparently, my applications, that use sleep mode, are avoiding this condition, otherwise I would have noticed before.
In your application, code execution advances to the endless while (TRUE); loop if an active interrupt is triggered. But the power consumption will be higher than 125 uA in this case, I guess. |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Thu May 19, 2011 12:23 pm |
|
|
hi,
Turn off the UART and disable internal pullups, check your .h file for peripherals you might have missed...low voltage detect, any internal vrefs....
g. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
hcalex
Joined: 18 May 2011 Posts: 5
|
|
Posted: Tue May 24, 2011 2:30 pm |
|
|
I found the solution, I needed to add the following configuration parameter:
#FUSES NOFCMEN //Fail-safe clock monitor disabled |
|
|
|