Appropriate low-power mode for timing applications

Post here all questions related to STM32 core if you can't find a relevant section!
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Appropriate low-power mode for timing applications

Post by ag123 »

Well, one way though, for timing critical apps, a hardware timer gives the best precision and predictability. That may be useful for timing sensitive apps such as interfacing a sensor over comms etc. But it would cost some power. And I'm not too sure how that works in deep sleep etc, my guess is the hardware timer should still be running as it is a separate hardware from the CPU.
mebab
Posts: 115
Joined: Mon Aug 24, 2020 12:42 pm
Answers: 4

Re: Appropriate low-power mode for timing applications

Post by mebab »

Thanks fpiSTM. The part of the code under discussion is in the following:

Code: Select all

      uint32_t ss = millis() - T_Beginx; // SS is the total operating time of different tasks from the beginning of the main loop
      uint32_t ww=0;
      
      if (T_Loop>ss) ww = T_Loop-ss;  // We check if there is an extra time left for energy saving; T_Loop =10000 ms
     
      if ww>0     // In case there is time left, the processor will sleep to save energy
      {
          sleep(ww);    // To sleep STM32 as much as ww
          //LowPower.deepSleep(ww);  // To deep sleep STM32 as much as ww
      }
There are two problems:
1. Waking up of LowPower.deepSleep(ww) instead of sleep(ww) takes more than ww millisecond.
2. Assuming that ww is longer than 10 ms, the interrupt (every 10 ms) can not be carried out during deep sleep mode as you mentioned.

Because of above mentioned reasons I had to deactivate LowPower.deepSleep(ww).
Last edited by mebab on Thu Sep 23, 2021 11:48 am, edited 3 times in total.
mebab
Posts: 115
Joined: Mon Aug 24, 2020 12:42 pm
Answers: 4

Re: Appropriate low-power mode for timing applications

Post by mebab »

ag123 wrote: Thu Sep 23, 2021 10:22 am Well, one way though, for timing critical apps, a hardware timer gives the best precision and predictability. That may be useful for timing sensitive apps such as interfacing a sensor over comms etc. But it would cost some power. And I'm not too sure how that works in deep sleep etc, my guess is the hardware timer should still be running as it is a separate hardware from the CPU.
The external RTC can help to have the correct real-time and it consumes up to 1 mA which is ok. But, problem is that I need the CPU to work while I read the sensors in every interrupt-based 10 ms. Then, my problem is how to force STM32 to deep sleep mode for short times like 10 ms repeatedly. Because, as I replied fpiSTM, the CPU doesn't wake up at exact times after being in deep sleep mode! Maybe this is not the case with long times like few seconds or so. The simple word is deep sleep is not working fine for short times.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Appropriate low-power mode for timing applications

Post by ag123 »

You can experiment with hardware timers to see if those timer interrupts works in deep sleep modes. I've not tried such yet.
If those works, then it is a solution, as it can drive the interrupts at the frequency you need.
You may like to search app notes from ST to see if there are things about that.
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Appropriate low-power mode for timing applications

Post by fpiSTM »

millis() relies on the systick. in low power mode systick interrupt is disabled so millis is no more increased.
About the RTC time, ensure to use the LSE as input for theRTC to have a better precision.
Then you ask for ms, this implies the subsecond usage which is fairly dependant of the RTC synchronous prescaler value. depending of the this value the subsecond match is more or less precise.

For example, with 255 as prescaler value the best possible is Alarm activated every 1/128 s -- > 7,8 ms (for RTC2 type, the one of STM32L476)
mebab
Posts: 115
Joined: Mon Aug 24, 2020 12:42 pm
Answers: 4

Re: Appropriate low-power mode for timing applications

Post by mebab »

Thank you all for the valuable comments! I will consider using the external RTC later when my hardware is ready for the test which may take some time.
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Appropriate low-power mode for timing applications

Post by fpiSTM »

And do not forget it exists some latencies due to sleep mode entrance and exit...
mebab
Posts: 115
Joined: Mon Aug 24, 2020 12:42 pm
Answers: 4

Re: Appropriate low-power mode for timing applications

Post by mebab »

Yes. I know this. In fact, I have some extra reserve time at the end of the loop to take care of this.

Thanks for your kind help fpiSTM!
Post Reply

Return to “General discussion”