I am beginning LPM with RA2L1 processors and want to better understand enter and exit mechanism.
In my project, I need to enter LPM - Software Standby under some conditions. Once in LPM, the processor should wake up after an interval (t), take ADC reading and make some comparison, lets say A>B. If true, it should return to Normal mode, else go back to LPM.
The LPM entry will be called in a function myFunc() which itself will be called in an ISR, (ISR1). A timer will be started before entering LPM and it's interrupt ISR2 will be used to wake up the processor. The code logic is given below
ISR1()
{
myFunc()
}
// Configure peripherals for LPM
// Start timer
// Enter LPM
// Program starts here on wake up and after ISR2 is executed
// Read ADC
// if(A>B == False) myFunc() //Re-enter LPM
ISR2()
How can I implement this? As per my understanding, the processor stops at //Enter LPM line. When a timer interrupt occurs, ISR2() will be called and executed and once ISR2 is executed, program will return to next line after //Enter LPM.
Ques 1.) Is this correct?
Ques 2.) What happens if ISR2 priority is less than that of ISR1? Will the processor still wake up?
Ques 3.) If (A>B) is not true, is the code logic above the correct way to do it or is there a better mechanism proposed by Renesas?
Kindly help with your feedback so that I can expedite my development.
Hi NMANI,
Thanks for reaching out Renesas Community.
About your question:
1, Enter lpm in interrupt is not suggested, if you want to enter the lpm after an interrupt is triggered, you can use a flag to do this:
ISR()
//your func()
//enter_lpm_flag = true
main()
while(1) {
if (enter_lpm_flag == true){
enter_lpm();
2, To avoid this, not to enter lpm in interrupt.
3, If you need to compare the ADC value with a fixed value, you can use the ADC window compare mode, but if you need to compare two ADC channel value, your method is right.
We have an official sample project for RA2L1 lpm, it introduce the difference of three lpm mode and their wake up source, you can take it for reference:ra-fsp-examples/example_projects/ek_ra2l1/lpm/lpm_ek_ra2l1_ep at 294f649f1aca599b783cbbf115f7da5d88ff113d · renesas/ra-fsp-examples (github.com)
BR,
NP_Renesas