imxrt 1050 - Millisecond ticks

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

imxrt 1050 - Millisecond ticks

Jump to solution
3,052 Views
dynamix
Contributor II

Hey folks,

I need to measure how many milliseconds a block of code takes to run in order to measure its performance; I am wondering if there is an easy way to do so.

Thanks in advance.

Labels (1)
0 Kudos
1 Solution
3,045 Views
gh78731
Contributor III

The way I do this is to set up a "general purpose timer" (gpt1 or gpt2) to count up  continuously in microseconds forever..

Then you bracket the code you want to measure, with an initial call to fetch the gpt1 value, then after the code has run, fetch the gpt1 value again and subtract the initial value. The result is the number of microseconds it took the code to run. Using unsigned 32 bit uint's this is good for up to a little over 4000 seconds.

View solution in original post

4 Replies
2,960 Views
dynamix
Contributor II

Thank you guys, it completely solved my problem.

0 Kudos
2,969 Views
nickwallis
Senior Contributor I

Thanks Mark.

For info, those using mcuXpresso IDE can use the structures defined in core_cm7.h for this.

CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; // enable trace for DWT features
DWT->LAR = 0xc5acce55; // unlock access to DWT registers
DWT->CYCCNT = 0; // reset the cycle count value
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; // enable the cycle counter

-Nick

3,034 Views
mjbcswitzerland
Specialist V

Hi

Typically the cycle counter in the Cortex-M7 is used for measuring execution time.

DEMCR |= DHCSR_TRCENA; // enable trace for DWT features
DWT_LAR = DWT_LAR_UNLOCK; // unlock access to DWT registers
DWT_CYCCNT = 0; // reset the cycle count value
DWT_CTRL |= DWT_CTRL_CYCCNTENA; // enable the cycle counter
... code to be measured
DWT_CYCCNT now contain the number of cycles required (and thus the time with high resolution from one cycle to about 7s on a 600MHz i.MX RT part).

Regards

Mark
[uTasker project developer for Kinetis and i.MX RT]
Contact me by personal message or on the uTasker web site to discuss professional training, solutions to problems or rapid product development requirements

For professionals searching for faster, problem-free Kinetis and i.MX RT 10xx developments the uTasker project holds the key: https://www.utasker.com/iMX/RT1050.html

3,046 Views
gh78731
Contributor III

The way I do this is to set up a "general purpose timer" (gpt1 or gpt2) to count up  continuously in microseconds forever..

Then you bracket the code you want to measure, with an initial call to fetch the gpt1 value, then after the code has run, fetch the gpt1 value again and subtract the initial value. The result is the number of microseconds it took the code to run. Using unsigned 32 bit uint's this is good for up to a little over 4000 seconds.