Performance Timers for Cortex-M0 MKL17Z Processors?

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

Performance Timers for Cortex-M0 MKL17Z Processors?

1,164 Views
nnewell
Contributor II

Using MKL17Z256xxx4 processor based product would like to know what's the best timer facility for accurately measuring duration. In most systems there's a free running timer accurate to a microsecond or better that one can create a performance measurement set of functions and measure in code how long things are taking without using a debugger or a scope. Perhaps someone has already made such a timer facility (aka similar to ZEN Timer from the Zen of Optimization). Thanks.

0 Kudos
5 Replies

704 Views
mjbcswitzerland
Specialist V

Nick

The SYSTICK runs at the core frequency and has highest resolution, but is usually used for a TICK interrupt.

A free PIT is good too since it runs at the bus frequency and has 32 bits (SYSTICK 24 bits) so can measure longer periods with high accuracy.

In the uTasker project a free PIT tends to be used to monitor CPU load sharing between tasks. There are two macros used to couple it to the HW as follows:

#define INITIALISE_MONITOR_TIMER()        POWER_UP(6, SIM_SCGC6_PIT); PIT_MCR = 0; LOAD_PIT(1, 0xffffffff); PIT_TCTRL1 = PIT_TCTRL_TEN
#define EXECUTION_DURATION()              (0xffffffff - PIT_CVAL1); LOAD_PIT(1, 0xffffffff); PIT_TCTRL1 = PIT_TCTRL_TEN // read the elapsed count value and reset the counter back to 0xffffffff

Regards

Mark

0 Kudos

704 Views
nnewell
Contributor II

Sounds like what I want is the PIT timer, its currently in use but I should be able to modify things, just need to be careful. Thanks.

0 Kudos

704 Views
mjbcswitzerland
Specialist V

Nick

The PIT has two channels which can be used independently. If you use only one there is still one free (I used PIT channel 1 in the macros since one usually starts using channel 0, so the second may be free).
At 24MHz bus clock (max. for KL17) the PIT gives about 42ns resolution and can measure periods up to 178.9s (if its overflow interrupt were used it could be extended almost infinitely)

Regards

Mark

0 Kudos

704 Views
BlackNight
NXP Employee
NXP Employee

As Mark indicates, I'm using the Systick on M0 devices for this, and for me the 24bits are good enough which means at high clock speeds I can measure things up to about 800 ms (depending on clock speed). Of course there is some small overhead to read the timer value/etc.

I'm usually using the Systick to measure things with FreeRTOS too, or using a PIT for longer measurements.

On a side note: you would be better off with the M3/M4 core, as it comes with a instruction cycle counter (see Cycle Counting on ARM Cortex-M with DWT | MCU on Eclipse ) which I'm using there.

Regards,

Erich

0 Kudos

704 Views
nnewell
Contributor II

Unfortunately I don't have the luxury of choosing the processor, so I'll try Mark's suggestions and post my results. Most of what I'm measuring will be less than a second long so Systick should be sufficient but prehaps its possible to detect the wrap condition and extend it. I do have other projects that use higher end ARMs and they generally have something suitable for measuring time accurately, but its good to know the M3 has something.

Thanks,

Nick

0 Kudos