cancel
Showing results for 
Search instead for 
Did you mean: 

Measure sleep time using DWT SLEEPCNT problems

tm3341
Associate II
Posted on May 12, 2015 at 07:56

Hello everyone,

I need to measure sleep time of my Cortex-M4 processor (STM32F4xx).

I looked at DWT where I also use normal tick counter and I enabled SLEEPCNT counter.

However, I noticed that it is 8-bit register with event generation support.

Now, there is my question.

How can I know how many events was triggered with this timer if MCU sleeps for example 1 second?

Currently, I'm using like this:

before = DWT->CYCCNT; 
/* Read current instruction time */
__WFI(); 
/* Go sleep, wait interrupt */
after = DWT->CYCCNT - before; 
/* Get different */

The first problem I see here is that this method also measures the time when I was in interrupt and do stuff in method which wake up processor.

It would be very nice, if someone can point me to direction how to handle events from SLEEPCNT when I'm in sleep mode.

SLEEPCNT timer is working, I can get different values when I read it but it probably overlaps from 8-bits like 1000 times before MCU is awake again and I read register.

Thanks in advance.

PS: I want to create a very primitive ''CPU monitor'' to measure CPU load when it is active or when it sleeps.

Maybe you, clive1 have a solution? :D #sleep #measure #count #dwt
1 REPLY 1
tm3341
Associate II
Posted on May 23, 2015 at 10:38

Ok, using SLEEPCNT from DWT was not good idea, so I used another way.

With disabling interrupts before going to sleep with WFI() it can be done pretty nice.

More here:

http://stm32f4-discovery.com/2015/05/cpu-load-monitor-for-stm32f4xx/