Jump to content
L293D

Is there a way in Energia to access the LPM's?

Recommended Posts

How are you measuring the current? You should remove jumper J9 and then place an amp meter on those pins.

 

Low power can be tricky. You have to make sure that all the I/O's are in the right state. For most of them that are not connected to anything they should be OUTPUT/HIGH (e.g. pinMode(<pin>, OUTPUT), digitalWrite(<pin>, HIGHT). For the RED/GREEN LED, you will have to set them to OUTPUT/LOW to prevent them from turning on and consuming power. pinMode(RED_LED, OUTPUT), digitalWrite(RED_LED, LOW); pinMode(GREEN_LED, OUTPUT), digitalWrite(GREEN_LED, LOW). 

Share this post


Link to post
Share on other sites

Enabling easy access to LMP's has been on my list for a long time but just hadn't had the time..

I have done some sketching to get a rough idea of what it would take. The below Sketch should help you to get on your way.

 

void setup() {
  /* Watchdog runs in interval.
   * Disable it so we don't wake up at 6 am when our alarm is set for 10 am.
   * After this call delay(...) will not work */
  disableWatchDog();
  attachInterrupt(P1_3, awake, FALLING);
}

void loop() {
  __bis_status_register(LPM4_bits + GIE);
  /* Code after this will never be reached */
}

void awake(){
  /* You are in the ISR.
   * Do something useful while you are awake!
   * But don't call any functions that rely on interrupt */
}
Note that after awake() is called, system will go back to LPM4. Clearing the LPM4 bits here will not work since the SR register is on the stack and will be popped off resetting the LPM bits. Only place you can do this right now is inside WInterrupt.c in the port interrupt ISR. You will have to call __bic_status_register_on_exit(LPM4_bits);

 

Using the above you should see current consumption go down to the nA's icon_e_smile.gif

 

Robert

 

 

Can someone help me get this example compiling? All I did was open Energia and copy and paste the above code.  What library am I missing?  Can someone show the complete code including the includes needed?  I should probably mention that my target board is the MSP432 - Launchpad.

 

 

Thanks.

Share this post


Link to post
Share on other sites

Hi @@JasonP and welcome.  The code you referenced will not compile because it is for the MSP430 and you are using a MS432.  The MSP432 is different in that it uses Energia MT and can multi-task.  When it is idle it automatically enters a low power mode so you don't need to do anything it in Energia.  See for example this discussion:  http://forum.43oh.com/topic/8896-msp432-energia-code-composer-studio/

Share this post


Link to post
Share on other sites

@@Fmilburn, Thanks for the reply.  

 

Let me explain a little what I would like to accomplish with the MSP432.  I need a program that will put the MSP432 into a sleep mode that consumes 5uA or less for power budget.  The controller needs to be woken by external interrupts, increment variables, do some SPI work and go back to low power mode.  Since I do not need timers for this I suppose I can go to LPM4 or even LPM4.5?

 

I guess I'm confused an a few things...

 

What is considered idle?  Is this as simple as calling delay()?

During an idle period what low power mode am I in?

Can I meet my power requirements using Energia MT?

 

Thanks, and sorry for the noob questions.

Share this post


Link to post
Share on other sites

With the MSP432 Launchpad you can use CCS6 and Energy Trace to measure LPM supply currents. You can import your Energia sketches into CCS and do full debug as well.  I haven't had a lot of success getting much below 100uA on the 432 with my testing, both with Energia MT using long delays in the program, and with a TI LPM3 (maybe LPM3.5, can't remember for sure) demo program under CCS.  Under Energia I shut down the serial port prior to the delay (which helped) and the CCS demo program supposedly put all the ports in a low power configuration prior to calling LPM3.x  I am sure that I am missing something and am planning to dig deeper when I get some free time. 

Share this post


Link to post
Share on other sites
#include "driverlib.h"
#include "msp.h"

/* Standard Includes */
#include <stdint.h>
#include <stdbool.h>

volatile int state = HIGH;
volatile int flag = HIGH;
int count = 0;


void setup(){
  Serial.begin(9600);
  delay(1000);
  Serial.println("Starting setup");
  delay(1000);
  
  //Set all I/0s as out put except for reset and power pins. 
  setPins_LowPower();
  
  // Set pin mode for interrupt
  pinMode(73, INPUT_PULLUP);
  pinMode(GREEN_LED,OUTPUT);
  attachInterrupt(73, blink, FALLING); // Interrupt is fired whenever button is pressed
  
  Serial.println("Done with setup");
  delay(1000);
  

}

void loop(){
  
  if(state) {
    digitalWrite(GREEN_LED, state); //LED starts ON
  }
  else{
    digitalWrite(GREEN_LED, state);
    //delay(1000);
    if(flag){
     flag = LOW;
     
     Serial.begin(9600);    
     Serial.println(count);   
     Serial.end();           // Without ending Serial I was not able to enter LPM3
     lowpower();
    }
  }
}

void blink()
{
  //count++;
  state = !state;
  flag = HIGH;
}

void setPins_LowPower(){
    for (int i = 2; i < 11; i++)
  {
    pinMode(i, OUTPUT);
    digitalWrite(i, LOW);
  }
  
  for (int i = 11; i < 16; i++)
  {
    pinMode(i, OUTPUT);
    digitalWrite(i, LOW);
  }
  
  for (int i = 17; i < 20; i++)
  {
    pinMode(i, OUTPUT);
    digitalWrite(i, LOW);
  }
  
  for (int i = 23; i < 79; i++)
  {
    pinMode(i, OUTPUT);
    digitalWrite(i, LOW);
  }
}

void lowpower(){

  MAP_WDT_A_holdTimer(); // Turn off watchdog timer?
  //MAP_RTC_C_holdClock(); // Turn off RTC
  MAP_PSS_disableHighSide(); // 
  MAP_PSS_disableLowSide();  // 
  MAP_PCM_gotoLPM3();
  
}

So I threw a Hail Mary with with bits and pieces I have found from this forum and TI's forum.  The above code although a bit scabby, toggles the MSP-432 in and out of LPM3 mode.  While the device is in low power mode the the LED is off.  While out of low power mode the LED is on.  Not sure how to handle debouncing of the button but it seems to work well enough to get the idea of power consumption.

 

**************************************************

@3.3V

 

LPM3 / LED OFF ~ 2.5uA !! low power

ACTIVE / LED ON ~12mA

ACTIVE/ LED OFF ~6mA

 

***************************************************

I was happy to see "count" is maintained after entering and exiting LPM3.  There are still some quirks to get passed such as delay() doesn't work after calling my lowpower() function and coming back, but that's not too surprising since I disabled WDT?  Also without Serial.end() the device never reaches a low power state.  It gets stuck somewhere in between at about 4.5mA.  I will keep playing with this to see if I can completely come back from LPM3 with full functionality.

 

Anyways things are looking OK thus far but I realized today that I need a way to wake the device on some specified time interval also.  I was thinking an RTC interrupt but I am looking for some advice on this.  I am finding snippets of code here and there but nothing really concrete yet.  

 

I would be grateful if anyone can verify those sleep currents with the above code and give and or advise on timer interrupt in LPM3.

 

Thanks guys.

Share this post


Link to post
Share on other sites

Hello everyone,

 

I just wanted to post an update on my MSP432 project.  Today after a few hours of messing around trying to get RTC interrupts working properly I gave up.  I did have a calendar based event trigger an interrupt but afterwards I was in no mans land.  All code execution stopped and I wasn't quite sure were I was ending up.  I suppose thats where the power of CCS comes in?  

 

Anyways, I have seen the comment posted several times "when the processor is in an idle, it automagically enters a low power state".  A few days ago this was the first thing I tried, but it didn't seem to change the power consumption much.  I assumed it was entering LPM0 or LPM1 because during the delay state I was still up around 4.5mA.  After failing miserably with the RTC interrupt I figured I would re-explore this. 

 

Huge thanks to @@dubnet for posting this

 

With the MSP432 Launchpad you can use CCS6 and Energy Trace to measure LPM supply currents. You can import your Energia sketches into CCS and do full debug as well.  I haven't had a lot of success getting much below 100uA on the 432 with my testing, both with Energia MT using long delays in the program, and with a TI LPM3 (maybe LPM3.5, can't remember for sure) demo program under CCS.  Under Energia I shut down the serial port prior to the delay (which helped) and the CCS demo program supposedly put all the ports in a low power configuration prior to calling LPM3.x  I am sure that I am missing something and am planning to dig deeper when I get some free time. 

 

The key words in there are long delays.  After I added delay(10000); in each of my loops I saw the current all the way down to 2.5uA!!!!  The trick to get this low of current is to make sure to end Serial if it is used.... Serial.end(); Otherwise I could never get below 1.5mA.  Thank you @@energia for this awesome MT platform!  I can now use interrupt based code with delays() in my loops and achieve my power budget goals. 

 

I really only wished I had paid more attention to what was right in front of me or someone had spelled it out clearer.  

 

LONG DELAYS = LOW POWER!

 

IF YOU HAVE A MULTIPLE SKETCHES, ALL LOOPS MUST DELAY TO ENTER THIS LOW POWER STATE.  A FREE SPINNING LOOP IS NOT IDLE. 

 

 

Cheers!

Share this post


Link to post
Share on other sites

IF YOU HAVE A MULTIPLE SKETCHES, ALL LOOPS MUST DELAY TO ENTER THIS LOW POWER STATE.  A FREE SPINNING LOOP IS NOT IDLE.

@@JasonP Thanks for the above statement. The light bulb just went on. I did delays in my primary task but didn't even think about the secondary task. Now the question is how to sync the delays so that when one task wakes up the other is available. Or perhaps if there is a way in Energia to exit the delay in a secondary task with a command from the primary task.

 

Thanks again for the insight.

Share this post


Link to post
Share on other sites

@@dubnet,

 

I guess depending on what you are trying to do, you could use an interrupt.  You could set a pin as output inside you first sketch and setup up an interrupt in your other sketch.  When an event happens in your first loop, write the pin high which will trigger the interrupt in the other sketch.  Of course this also requires a hardware connection. 

Share this post


Link to post
Share on other sites

@@JasonP Turns out it wasn't a task related issue after all. I had disconnected the jumpers to the XDS110 portion of the board so that power being measured by Energy Trace (via a MSP-FET) was only the target MCU. However, I overlooked the internal/external JTAG switch. Once it was set to the external connector, power consumption dropped from 100uA to less than 4uA. A classic facepalm moment...

Share this post


Link to post
Share on other sites

@@JasonP Turns out it wasn't a task related issue after all. I had disconnected the jumpers to the XDS110 portion of the board so that power being measured by Energy Trace (via a MSP-FET) was only the target MCU. However, I overlooked the internal/external JTAG switch. Once it was set to the external connector, power consumption dropped from 100uA to less than 4uA. A classic facepalm moment...

 

That's good to hear.  Iv'e also done that a couple times :)

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...