cancel
Showing results for 
Search instead for 
Did you mean: 

How to handle overflows in a register like DWT_CYCCNT

LMI2
Lead
Posted on September 06, 2016 at 20:40

There are examples counting clock pulses with the DWT_CYCCNT, but it will overflow in time.

Counting pulses is easy if there is no overflow, but with overflow I am sure there nice way of doing it.

I could do something like this.

if old value>new value

Max count of DWT_CYCCNT-old value+ new value.

But how to get the max in DWT_CYCCNT and what happens if the DWT_CYCCNT overflows twice or more.

5 REPLIES 5
Posted on September 06, 2016 at 21:09

Ask yourself what it is you want to measure, over what time intervals.

If you want to benchmark things under 24 seconds (@180MHz) then such durations and timeouts do not have worry about wrapping.

If you want some long time base, use a slower counter, or a SysTick based counter counting off milli-seconds and seconds, for years.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
christoph2399
Associate II
Posted on September 06, 2016 at 21:31

never came up with the idea that i need to count cycles @ a 32bit controller. last time i debugged efficiency was on an 8bit.

for program flow 1ms timestamp is more than enough.

Posted on September 06, 2016 at 21:46

> never came up with the idea that i need to count cycles @ a 32bit controller. last time i debugged efficiency was on an 8bit.

>

> for program flow 1ms timestamp is more than enough.

I envy your easy job.

Oh, wait, no, I love real challenges.

JW

Posted on September 06, 2016 at 21:46

> never came up with the idea that i need to count cycles @ a 32bit controller. last time i debugged efficiency was on an 8bit.

>

> for program flow 1ms timestamp is more than enough.

I envy your easy job.

Oh, wait, no, I love real challenges.

JW

LMI2
Lead
Posted on September 06, 2016 at 22:07

A wonder, the forum did not crash.

I was planning to let counter to run continuously for some time and check the results via serial bus.