Global milliseconds timer.

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

Global milliseconds timer.

1,811 Views
john71
Senior Contributor I

Right now I have a global counter that increments in interrupt every millisecond.

void TI1_OnInterrupt(LDD_TUserData *UserDataPtr)
{
   globalSysTimer++;
}

And on this variable based timeouts, delays, and periodic loops in the program.
It's easy and convenient but I don't like the paradigm to interrupt the program flow every millisecond.
So I want to use a timer - like FlexTimer Module (FTM) and read its counter for a timestamp. But the FTM is 16-bit - it gives me 65536 ms before overflow. not enough.
What another options do I have in Kinetis K line?

6 Replies

1,235 Views
john71
Senior Contributor I

Thanks

0 Kudos

1,235 Views
john71
Senior Contributor I

How do I config PIT to tick every millisecond? I didn't find any prescaler registers.

The same question for SysTick  - how do I configure the period of the tick?

0 Kudos

1,235 Views
mjbcswitzerland
Specialist V

Hi

These timers don't have any pre-scalers and so they count at the clock rate directly (SYSTICK at core clock speed and PIT at bus clock speed).

Regards

Mark

1,235 Views
mjbcswitzerland
Specialist V

Hi Evgeny

You have PITs, which are 32 bit counters.
You also have the SYSTICK (a 24 bit counter, which is usually used to generate a system TICK - like your 1ms one).
The PIT and FlexTimers are peripheral timers that are specific to the Kinetis parts and the SYSTICK is in all Cortex parts (and thus compatible).

In the case of the Kinetis K parts, with Cortex-M4 (but not parts with Cortex-M0+) there is also the data watch and trace unit (in the core) that can be used for time stamps. It is a 32 bit cycle counter and the code is (basically) compatible across all such cores. This is the preferred solution fro high resolution time stamps as long as you only work on Cortex parts that have this [compatible and doesn't need peripheral timers]; it can be configured in the Kinets K by using

    DEMCR |= DHCSR_TRCENA;                       // enable trace for DWT features
    DWT_CYCCNT = 0;                              // reset the cycle count value
    DWT_CTRL |= DWT_CTRL_CYCCNTENA;              // enable the cycle counter

Afterwards you can simply read "DWT_CYCCNT" to get the cycles that have elapsed (this is much higher resolution than ms of course and also overflows).

You can also extend your FlexTimer method by using a single interrupt at overflow to increment a variable, thus extending your ms time stamp to any width you like.

Regards

Mark


uTasker developer and supporter (+5'000 hours experience on +60 Kinetis derivatives in +80 product developments)
Kinetis: http://www.utasker.com/kinetis.html

1,235 Views
john71
Senior Contributor I

How do I config PIT to tick every millisecond? I didn't find any prescaler registers.

0 Kudos

1,235 Views
john71
Senior Contributor I

Thank you very much

0 Kudos