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

12LF1822 POWER TEST

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



Joined: 21 Feb 2013
Posts: 8

View user's profile Send private message

12LF1822 POWER TEST
PostPosted: Fri Feb 22, 2013 8:35 am     Reply with quote

I am trying to put my 12LF1822 to sleep in a manner which uses the least amount of power.
I am using the 8pin package.
My compiler version is 4.140

I made this sample program to put it to sleep so I could measure current draw.
Code:

#include <12LF1822.h>

#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES WDT_SW                   //No Watch Dog Timer, enabled in Software
#FUSES PUT                      //Power up Timer
#FUSES PLL_SW                   //4X HW PLL disabled, enabled in Software
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O

#use delay(clock=31000)

#define LED_LIGHT_PIPE     PIN_A4

void main()
{
   setup_oscillator(OSC_31KHZ  |OSC_INTRC | OSC_PLL_OFF);
   port_a_pullups(0x00);//no pullups?
   setup_wdt(WDT_OFF);
   
   output_low(LED_LIGHT_PIPE);//turn LED OFF
   sleep();//For this purpose just go to sleep forever
   
   //you should never get here, but just for sanity:
   output_high(LED_LIGHT_PIPE);//turn LED on
   for(;;)   {      delay_ms(1000);   }
}


The power source is about 3.50 volts from a lithium battery. It is regulated to 2.75 volts for the pic.
The measured current is about 84microAmps. I believe it should be closer to 20micros.

Is there anything more I should be doing with the code to cut power?
temtronic



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

View user's profile Send private message

PostPosted: Fri Feb 22, 2013 8:59 am     Reply with quote

While I do not use that PIC a 'general' comment.

You'll need to read the datasheet and disable any and all internal peripherals you are not using.SPI,ADC,PLL all consume power and PICs typically default the ADC 'on'..
Check the 'fuses' options too,some default values may consume more power.
Buried in the datasheets are the details..and I KNOW reading 400-500 pages can be ,well, boring..but in there is the stuff you need to know if you want ultra low power.

I gave up on the quest for super low power decades ago.Adding a second battery was a lot cheaper ,more reliable solution in getting products off the R&D bench and into the field.

hth
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19359

View user's profile Send private message

PostPosted: Fri Feb 22, 2013 9:06 am     Reply with quote

Also, the other 'classic' with sleep is that _all_ the pins must not be left floating.
Pins must either be driven by external circuits, that pull them 'to' a rail (even just resistors), or must be driven by the internal drivers, to a state that draws the least power. The latter draws a fraction more power than driving the pins externally (but it is pA).
Currently, all the pins except A4, if they are not connected externally, are floating. If they float into the gate transition region, power consumption will shoot up.....

Best Wishes
Plater



Joined: 21 Feb 2013
Posts: 8

View user's profile Send private message

PostPosted: Fri Feb 22, 2013 9:12 am     Reply with quote

Ahh yes, I had heard not to float pins but wasnt sure which way to pull them.

In another thread someone stated that peripherals default to off, and that sometimes using the setup commands (like setup_SPI(ss_disabled)) will actually turn them on when you don't want to.

I try to read the spec sheets but there seems to be nothing in common between pics so everytime I switch, i have to figure out what everything is called all over again. Ugh. I will try that out.
Ttelmah



Joined: 11 Mar 2010
Posts: 19359

View user's profile Send private message

PostPosted: Fri Feb 22, 2013 9:24 am     Reply with quote

A lot of clocked peripherals do stop, but remain turned on internally.
However the key problem in the line you post, is that setup_SPI(ss_disabled), _will_ turn on the SPI, since it is an incorrect command.....
The command to turn off the SPI, is setup_spi(FALSE); ss_disabled, says 'turn off slave select', but turn _on_ everything else. It is a faulty command from the 'wizard', and should never be used.

Best Wishes
Plater



Joined: 21 Feb 2013
Posts: 8

View user's profile Send private message

PostPosted: Fri Feb 22, 2013 2:27 pm     Reply with quote

Ttelmah wrote:
A lot of clocked peripherals do stop, but remain turned on internally.
However the key problem in the line you post, is that setup_SPI(ss_disabled), _will_ turn on the SPI, since it is an incorrect command.....
The command to turn off the SPI, is setup_spi(FALSE); ss_disabled, says 'turn off slave select', but turn _on_ everything else. It is a faulty command from the 'wizard', and should never be used.

Best Wishes

The reason why I question it is because FALSE is defined as 0 and SPI_DISABLED is also defined as 0. So I figured there had to be more to it.

Turning off all the devices(I suspect just the A2D was on) saved me another 20microamps. Putting me down to 60micros in sleep.
I will have to talk to the hardware guy when he gets back.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Feb 22, 2013 4:16 pm     Reply with quote

Plater wrote:
The reason why I question it is because FALSE is defined as 0 and SPI_DISABLED is also defined as 0. So I figured there had to be more to it.
You referred to SS_DISABLED, this one isn't zero and should only be used in the slave. Using SS_DISABLED on it's own actually enables SPI. This wrong configuration can be found in many code samples on this forum as the early CCS v4 Code Wizards did it wrong.

For the low power issue, search this forum. The topic has been discussed several times before with many useful tips.
A few threads that I found in two minutes Googling and will be helpful to you:
here they found out that disabling the fail-safe clock (enabled by default) safes a few dozens of uA.
Code:
   
#FUSES NOFCMEN //Fail-safe clock monitor disabled

Already mentioned above is that floating inputs can create current consumption caused by oscillation. A nice variation on this theme that I never heard of before is this recent thread where a LED connected to the Open Collector input A4 caused extra current flow. Driving the output high (to switch the LED off) actually created a floating input because the push FET is missing. Easily solved with a 100k resistor over the LED.
Plater



Joined: 21 Feb 2013
Posts: 8

View user's profile Send private message

PostPosted: Mon Feb 25, 2013 9:00 am     Reply with quote

Ah ha! Ok I see the difference between SPI_DISABLED and SPI_SS_DISABLED disabled now. That was my typo.

I only searched for my specific PIC chip when looking for power savings, wasnt sure how much translated between pics.

Unfortuantely I found no difference in power consumption with and without the NOCFM line.

Your comment on the LED pin went over my head. But my led pin goes to a 100k resister then into the LED then to ground. I don't know if that follow the pattern you described or not.

My revised code so far
Code:

#include <12LF1822.h>

#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES PUT                      //Power up Timer
#FUSES PLL_SW                   //4X HW PLL disabled, enabled in Software
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled

#use delay(clock=31000)

#define P_DATA_IN          PIN_A0
#define P_CLOCK_IN         PIN_A1
#define BAT_VOLTAGE        PIN_A2
#define MCLR               PIN_A3
#define LED_LIGHT_PIPE     PIN_A4
#define EPA_CONNECTED      PIN_A5

void main()
{
   setup_oscillator(OSC_31KHZ  |OSC_INTRC | OSC_PLL_OFF);
   port_a_pullups(0x00);//no pullups?
   //setup_wdt(WDT_OFF);//turned off with a fuse
   
   //setup_timer_0(T0_DISABLED);there is no disable?
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,1,1);
   SETUP_CCP1(CCP_OFF);
   setup_comparator(NC_NC);
   setup_vref(VREF_OFF);
   SETUP_DAC(DAC_OFF);
   
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   
   setup_spi(FALSE);//
   
   output_low(P_DATA_IN);//
   output_low(P_CLOCK_IN);
   input(BAT_VOLTAGE);
   output_low(MCLR);
   output_low(LED_LIGHT_PIPE);//turn LED OFF
   //EPA_CONNECTED is driven elsewhere by a physical jumper
    //output_high(BAT_SENSE_ENABLE);//This pin will be an A2D pin later

   sleep();//For this purpose just go to sleep forever
   
   //you should never get here, but just for sanity:
   output_high(LED_LIGHT_PIPE);//turn LED on
   for(;;)   {      delay_ms(1000);   }
}
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