Jump to content
mgonsalv

Excessive current useage when analogReference is not DEFAULT

Recommended Posts

I've run into an issue with execssive current usage on the Launchpad. My goal is to run a sensor on a battery for at least a year. The initial test was promosing because the launchpad (with J3 jumpers removed of course) was drawing barely a uA in LP3 sleep mode using the sleepSeconds() function in Energia. I was thrilled.

 

Then I figured that I should keep tabs on the battery level. To do this, I had to set analogReference to INTERNAL2V5 and use analogRead(11) to get the value. It works great. Below is a barebones snippet. The problem is that the current usage jumps to 180uA even in LP3 sleep mode. I understand that there will be some current usage to get the reference voltage, but it never turns off. Even if I set analogReference back to DEFAULT after the analogRead and call sleepSeconds.

 

Can anyone explain this? I'm hoping I'm doing something wrong.

void setup()
{
  // Use the 2.5V internal reference
  analogReference(INTERNAL2V5);
  //analogReference(DEFAULT);
}

void loop()
{
  // Get battery voltage
  //analogReference(INTERNAL2V5);
  int v = analogRead(11);
  //analogReference(DEFAULT);

  sleepSeconds(10);
}

Share this post


Link to post
Share on other sites

This is a known problem. The voltage reference is enabled when analogReference() is used, but the ADC code in Energia does not clear REFON so it's on all the time, and I'm not sure why it's also using power in DEFAULT mode but perhaps that has REFON too. In any case, I believe the next release of Energia fixes it... based on what I see from the source code.

Share this post


Link to post
Share on other sites

Thanks for the response spirilis. Just one clarification. If you stick with DEFAULT, there is no issue. The current drain starts when you select INTERNAL2V5 or 1V5, but doesn't stop when you attempt to go back to DEFAULT. I'm looking forward to the fix in Enegia.

 

@@bobnova, hey I'm doing the same thing. When I noticed that the battery was draining faster than it could charge in diffused lighting, it got my attention. :-)

Share this post


Link to post
Share on other sites

I decided to compare current usage if I did the same in CCS. My proggy is sleeping all the time in LPM4 drawing 0.1 uA. Then guess what? I hit the interrupt to wake it up, get the internal voltage, go back to LPM4 sleep, and it continues to draw 184 uA. Argh! Same problem!

 

Does my code have the same bug as Energia 12? Below is the main.c

 

#include "msp430g2553.h"

volatile float voltage;

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;
  P1OUT &= 0x00;
  P1DIR &= 0x00;
  P1DIR |= BIT0;
  P1REN |= BIT3;
  P1OUT |= BIT3;
  P1IE |= BIT3;
  P1IES |= BIT3;
  P1IFG &= ~BIT3;
  _BIS_SR(LPM4_bits + GIE);  // Go to sleep
  while(1) // Forever
  {}
}

#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
    unsigned int value=0;
    P1OUT ^= BIT0; // Turn on LED

    ADC10CTL0 = SREF_1 + REFON + REF2_5V + ADC10ON+ADC10SHT_3;    // Using internal reference of 2.5V
    ADC10CTL1 = INCH_11 + ADC10DIV_3;                            // Internal Voltage
    __delay_cycles(1000);                                        // Wait for ADC Ref to settle
    ADC10CTL0 |= ENC + ADC10SC;                                    // Sampling and conversion start
    while (ADC10CTL1 & BUSY);                                    // Wait for conversion to finish
    value = ADC10MEM;                                            // Fetch ADC value
    ADC10CTL0 &= ~(ENC + ADC10ON);                                // Does this turn off ADC?????
    voltage = (value * 2 * 2.5) / 1023;                            // Convert to volts

    P1OUT ^= BIT0;  // Turn off LED
    P1IFG &= ~BIT3; // Clear interrupt flag
    _BIS_SR(LPM4_bits + GIE);  // Go to sleep - Do I really need this?
}
 

Share this post


Link to post
Share on other sites

In your main loop, put your call to BIS_SR... inside your while(1) loop, and take the call to BIS_SR out of your interrupt. I think it is ending up in your while loop, and not going back to LPM. Also, it probably wouldn't hurt to explicitly clear REFON bit. I know the family guide says the reference is automatically turned off, but it can't hurt.

 

 

Sent from my iPad using Tapatalk

Share this post


Link to post
Share on other sites

Here's another users who ran into this problem. The following code will continue to suck ~160 uA even when in LPM3.

void loop()
{
  analogReference(INTERNAL2V5);
  int v = analogRead(11);
  
  sleepSeconds(10);
}

It is solved for me when I add two lines after analogRead() to shutdown the ADC:

void loop()

{
  analogReference(INTERNAL2V5); 
  int v = analogRead(11);
 
  // end conversion and turn off ADC
  ADC10CTL0 &= ~ENC; 
  ADC10CTL0 &= ~(ADC10IFG | ADC10ON | REFON);
 
  sleepSeconds(10);
}

Thanks to this article. I only found this thread afterwards.

 

This Energia behavior bug(?) is still in version 0101E0016.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...