cancel
Showing results for 
Search instead for 
Did you mean: 

Time spent in WFI / Sleep

root
Associate II
Posted on March 05, 2014 at 22:41

Hello,

I'd like to measure precisely the time spent in WFI / Sleep mode.

Is there a non-too-intrusive way of doing that in software ?

Thomas.
3 REPLIES 3
root
Associate II
Posted on March 05, 2014 at 23:21

Probably some clues:

- DWT contains a cycle counter on 32 bits (possibility to trigger an event on overflow), this can be used to measure ... well ... cycles very accurately. - One of the problems is I don't want to include time spent in interrupts on the sleep time, but using WFI, the interrupt starts immediatly. The SEVONPEND feature seems interesting, because it triggers an event (that can wake the core if WFE is used instead of WFI) when an interrupt in pended but not enabled in the NVIC. This would allow software to stop counting sleep cycles, and start counting run cycles before it enables the NVIC and the interrupt triggers. BUT if all interrupts are disabled through, for examplean CPSID instruction, is the mecanism still working? Then the idle task would be like (pseudo code):

while(true) 
{ 
stop couting run cycles (through DWT CYCCNT) 
disable all interrupts (CPSID) 
start counting sleep cycles (CYCCNT) 
WFE 
stop counting sleep cycles 
start counting run cycles 
enable interrupts (CPSIE) 
}

And gather that data (run cycles, sleep cycles) to calculate CPU usage on average say over one second. I'll do some testing tomorrow, but do someone already tried this? Thomas
chen
Associate II
Posted on March 06, 2014 at 10:06

Hi

''I'd like to measure precisely the time spent in WFI / Sleep mode.''

Define what you mean by ''precisely'' - ms, us etc?

If you set up the RTC, the RTC is capable of showing ms and will run in sleep mode.

root
Associate II
Posted on March 06, 2014 at 11:08

Hello,

I did implement the algorithm above and it is working very good.

I can get time spent in sleep (WFI) mode and run mode accurately (a few instructions cycles jitter).

My homebrew RTOS takes 0.17% of CPU time when idling 😉

Thomas.