ilpaso 0 Posted January 27, 2014 Share Posted January 27, 2014 Hi, I'm newbie in low power mode. I've seen a lot of examples but I'm not able to see a low current in LMP4 mode. The lowest current I can see is about 90uA. Is there a minimal working sketch in order to run LPM4 mode and wake up the microcontroller with an external interrupt and switch on a led? My hardware is launchpad V1.5 with Msp430G2553. Both red an green leds are off. I've removed all the jumpers (Vcc and uart, NOT rst and test) and my power supply is a battery at 3.5V. Thank you for your help and sorry for this newbie question. Quote Link to post Share on other sites
grahamf72 169 Posted January 27, 2014 Share Posted January 27, 2014 A basic sketch could look something like the following: void setup() { pinMode(P1_3,INPUT_PULLUP); //Enable inputs on P1_3 (onboard button) pinMode(P1_0,OUTPUT); //Enable output on P1_0 (onboard red LED) attachInterrupt(P1_3,Interrupt, FALLING); //attach our interrupt routine to P1_3 } void loop() { LPM4; //whenever the loop runs, switch back into LPM4 //we could put code here that would run after every Interrupt - see warning in text. } void Interrupt(void) //Our interrupt routine { digitalWrite(P1_0,!digitalRead(P1_0)); //toggle the red LED }; The above code will toggle the onboard red LED everytime the button is pressed. The code goes through the normal setup routine, which is pretty self explanatory. When it goes into the loop the first thing it gets is the command to switch to Low Power Mode 4. The processor now goes into a deep sleep until an interrupt occurs. When you press the button, the processor wakes up and executes the code in the Interrupt() function - in this case just toggling the red led. After the interrupt finishes, the processor should go back into sleep, however Energia has a timer that handles things like millis() that also wakes up with the return from the interrupt. This timer calls an interrupt, which leaves the processor running when it finishes. The processor will continue to run from the next command after LPM4 in loop(). In the above example, there is no more code, so loop() will start again, it gets to the LPM4 instruction and goes to sleep. If you will be using low power modes, I recommend going into the Energia "cores" folder, finding the file WInterrupts.c, and adding the command "LPM4_EXIT;" to the end of each of the interrupt handlers in that file. This will guarantee that the processor will always be left in the "awake" state after an interrupt runs, and doesn't make it dependent on Energia's timer. Without this change, if for some reason Energia's timer was stopped when you go into LPM4, there is no way to leave the processor awake after an interrupt. To minimize current consumption, you should also configure any unused pins as INPUT_PULLDOWN. From the tests I have done, configuring all pins to INPUT_PULLDOWN will reduce current to below 0.1uA (on my meter it flickers between 0 and 0.1). Configuring unused pins to INPUT_PULLUP or OUTPUT will result in the meter showing a consistent 0.1uA, while leaving the pins at their default (equivalent to INPUT) resulted in random current consumption in the 200-500uA range. Paulmac, ilpaso, p2baron and 3 others 6 Quote Link to post Share on other sites
ilpaso 0 Posted January 27, 2014 Author Share Posted January 27, 2014 thank you grahamf72! The code is clear! Maybe in my examples something was wrong. I'll try your code this evening and I'll reply with the result. Quote Link to post Share on other sites
ilpaso 0 Posted January 29, 2014 Author Share Posted January 29, 2014 Hi grahamf72 with your example and the following code for setup method the current is between 3.5uA / 4.0uA. That is fantastic! I don't understand if something is wrong or the problem is my low cost meter. My Vcc is 3.3V. What is your test Vcc value in order to read a 0.1uA in LPM4? Xout and Xin pins are floating on launchpad. Is this correct for very low power layout? void setup() { pinMode(P1_1,INPUT_PULLDOWN); pinMode(P1_2,INPUT_PULLDOWN); pinMode(P1_3,INPUT_PULLDOWN); pinMode(P1_4,INPUT_PULLDOWN); pinMode(P1_5,INPUT_PULLDOWN); pinMode(P1_6,INPUT_PULLDOWN); pinMode(P1_7,INPUT_PULLDOWN); pinMode(P2_0,INPUT_PULLDOWN); pinMode(P2_1,INPUT_PULLDOWN); pinMode(P2_2,INPUT_PULLDOWN); pinMode(P2_3,INPUT_PULLDOWN); pinMode(P2_4,INPUT_PULLDOWN); pinMode(P2_5,INPUT_PULLDOWN); pinMode(P1_0,OUTPUT); //Enable output on P1_0 (onboard red LED) attachInterrupt(P1_3,Interrupt, FALLING); //attach our interrupt routine to P1_3 } Quote Link to post Share on other sites
grahamf72 169 Posted January 29, 2014 Share Posted January 29, 2014 By default, Energia configures Xin & Xout as general IO, so if you aren't reconfiguring them to use the crystal you should change them to INPUT_PULLDOWN also. I start my setup with a simple for loop - for(uint8_t i;i<20;i++) pinMode(i, INPUT_PULLDOWN); Then I reconfigure any pins that I want to use. As for voltage, I was using the standard launchpad with 3.6v. It is possible my meter was inaccurate too, but you can be confident that power consumption will be at the lowest if all unused pins are configured as above. I also made my measurements with all jumpers removed from the launchpad. Sent from my iPad using Tapatalk Quote Link to post Share on other sites
ilpaso 0 Posted January 30, 2014 Author Share Posted January 30, 2014 My setup is in poor man style!I'll try to set Xin and Xout as INPUT_PULLDOWN. Thank you Quote Link to post Share on other sites
Lerssi 0 Posted March 8, 2014 Share Posted March 8, 2014 A basic sketch could look something like the following: void setup() { pinMode(P1_3,INPUT_PULLUP); //Enable inputs on P1_3 (onboard button) pinMode(P1_0,OUTPUT); //Enable output on P1_0 (onboard red LED) attachInterrupt(P1_3,Interrupt, FALLING); //attach our interrupt routine to P1_3 } void loop() { LPM4; //whenever the loop runs, switch back into LPM4 //we could put code here that would run after every Interrupt - see warning in text. } void Interrupt(void) //Our interrupt routine { digitalWrite(P1_0,!digitalRead(P1_0)); //toggle the red LED }; The above code will toggle the onboard red LED everytime the button is pressed. Hi, first of all, thanks for the nice explanation and sorry about for probably very stupid question: but how can I use the LPM function in Energia? I mean it seems that my Energia doesn't recognize LPM4 as any function/command. I have the latest version of Energia installed. I have tried to read other posts related to subject but I really haven't figured out should I copy some file to somewhere or edit something to be able to use function LPM4 for example? I would like to be able to do exactly similar thing which is in the example code above. Thanks already for the clarification L Quote Link to post Share on other sites
grahamf72 169 Posted March 8, 2014 Share Posted March 8, 2014 @@Lerssi which Launchpad are you using? The Low Power macros (LPM4, LPM3 etc) are defined in the header files for the MSP430 processors. If you start with the basic Energia sketch and put "LPM4;" in the loop section, the sketch will compile without errors for any of the MSP430 Launchpads, without needing to put any header files etc beyond what Energia automically compiles. But - if you are using a Stellaris or Tiva launchpad, it won't compile. Stellaris & Tiva use a different method of controlling low power, and to be honest I haven't looked at it close enough to know even the basics of how low power works on these processors. Lerssi 1 Quote Link to post Share on other sites
Lerssi 0 Posted March 9, 2014 Share Posted March 9, 2014 grahamf72, thanks for your reply. It turned out that the reason was very simple as you suspected: I have earlier played with Stellaris and now I was just verifying the new code without the actual MSP430 Launchpad which will be used for my project... So it's compiling now just fine, thank you Quote Link to post Share on other sites
rord100 1 Posted August 31, 2016 Share Posted August 31, 2016 A basic sketch could look something like the following: void setup() { pinMode(P1_3,INPUT_PULLUP); //Enable inputs on P1_3 (onboard button) pinMode(P1_0,OUTPUT); //Enable output on P1_0 (onboard red LED) attachInterrupt(P1_3,Interrupt, FALLING); //attach our interrupt routine to P1_3 } void loop() { LPM4; //whenever the loop runs, switch back into LPM4 //we could put code here that would run after every Interrupt - see warning in text. } void Interrupt(void) //Our interrupt routine { digitalWrite(P1_0,!digitalRead(P1_0)); //toggle the red LED }; The above code will toggle the onboard red LED everytime the button is pressed. The code goes through the normal setup routine, which is pretty self explanatory. When it goes into the loop the first thing it gets is the command to switch to Low Power Mode 4. The processor now goes into a deep sleep until an interrupt occurs. When you press the button, the processor wakes up and executes the code in the Interrupt() function - in this case just toggling the red led. After the interrupt finishes, the processor should go back into sleep, however Energia has a timer that handles things like millis() that also wakes up with the return from the interrupt. This timer calls an interrupt, which leaves the processor running when it finishes. The processor will continue to run from the next command after LPM4 in loop(). In the above example, there is no more code, so loop() will start again, it gets to the LPM4 instruction and goes to sleep. If you will be using low power modes, I recommend going into the Energia "cores" folder, finding the file WInterrupts.c, and adding the command "LPM4_EXIT;" to the end of each of the interrupt handlers in that file. This will guarantee that the processor will always be left in the "awake" state after an interrupt runs, and doesn't make it dependent on Energia's timer. Without this change, if for some reason Energia's timer was stopped when you go into LPM4, there is no way to leave the processor awake after an interrupt. To minimize current consumption, you should also configure any unused pins as INPUT_PULLDOWN. From the tests I have done, configuring all pins to INPUT_PULLDOWN will reduce current to below 0.1uA (on my meter it flickers between 0 and 0.1). Configuring unused pins to INPUT_PULLUP or OUTPUT will result in the meter showing a consistent 0.1uA, while leaving the pins at their default (equivalent to INPUT) resulted in random current consumption in the 200-500uA range. @@grahamf72 Hi, I followed this conversation with great interest. I have a similar setup, namely, MSP-EXP430G2 Launchpad with MSP430g2553 controller assembled on an external self made PCB with RX, TX, TEST, RST, VCC connected to the Luanchpad through a FLUKE 187 (high quality meter ) microAmper meter and GND. I tried the recommended sketch to test the LPM4 mode, including the "for(uint8_t i;i<20;i++) pinMode(i, INPUT_PULLDOWN)" routine followed by pinMode(P1_3,INPUT_PULLUP); and pinMode(P1_0,OUTPUT); It seem to work but when in LPM4, I measure 75 microampers instead of the desired ~ 0.1 microamp. Can you please advise how can I reach the desired ~ 0.1 microamp. Thank you @rord100 Quote Link to post Share on other sites
Rei Vilo 695 Posted August 31, 2016 Share Posted August 31, 2016 Pleas have a look at Ultra-Low Power with MSP430 which discusses low power options with Energia and how to measure consumption with EnergyTrace. Quote Link to post Share on other sites
rord100 1 Posted September 3, 2016 Share Posted September 3, 2016 Hi @Mention, Thank you for your advise. It is a very enlightening article which I read with great interest. I studied the practices mentioned at the "Ultra-Low Power with MSP430" link and successfully used the codes they suggested. Although I used their codes, I did not use their measuring method but instead I used analog method, namely, connected a micro Amper meter in series with the VCC line. I used different high quality ?A meters, they all show similar results. The code is working, the current goes from 5mA when in awake mode to 75 ?A when in LPM4 mode. I failed to understand what did I do wrong not being able to reach 1?A like they did. The TI MSP430G2553 datasheet indicates to use 2.2VDC of supply voltage where they mentioned 0.1?A current consumption. I was tempted to go down this road when I realized that in the link you mentioned they reached this current consumption using Vcc~3.6VDC. Presently I am a bit confused..... and will appreciate a good hint, thank you Quote Link to post Share on other sites
Rei Vilo 695 Posted September 3, 2016 Share Posted September 3, 2016 For even lower consumption, GPIOs need to be configured so they don't use power. I don't remember right now the details (INPUT, OUTPUT HIGH, OUTPUT LOW), sorry. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.