MQX time between ticks

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

MQX time between ticks

Jump to solution
2,760 Views
guillaumetiffin
Contributor III

Hello,

I have questions about ticks in MQX.

I didn't find the time between two ticks in MQX.

I have a k60 @100 MHz

I would like to know the time between two ticks.

I would like to know exactly the time elapsed between two ticks.

I want to use the functions _time_delay_ticks and _time_diff_nanoseconds.

If I call the function "_time_delay_ticks(10)", what is the real delay?

If I want to measure times under the 5ms period, can I use the function _time_diff_nanoseconds()? Is it return the exact number of nanosecond elapsed or only a multiple of 5ms ?

How can I have a resolution around 10 nanoseconds ?

Regards,

Guillaume

0 Kudos
1 Solution
1,231 Views
DavidS
NXP Employee
NXP Employee

Hi Guillaume,

It's convoluted so hopefully I can clear it up correctly.

If K60 is configured for 100MHz core frequency the SysTick timer is clocked at that rate.  The resolution is 10ns.

The MQX RTOS TICK is setup to be 200 ticks/sec (a TICK every 5ms...i.e. the heart beat).  So the SysTick timer gets configured to count down to zero and generate TICK interrupt every 5ms. 

MQX function calls can read that high speed SysTick timer and return very accurate results.

The various _time_delay() MQX calls strictly are working off the TICK counter (the 5 ms heart beat). 

A _time_delay_ticks(10) will block the current task 10xTICK or 10x5ms=50ms.

A _time_delay(50) does the equivalent delay of 50ms.

So a _time_delay(1) really will round up to 1 TICK or 5ms.

Regards,

David

View solution in original post

0 Kudos
4 Replies
1,231 Views
DavidS
NXP Employee
NXP Employee

Hi Guillaume,

A couple of posts that I think answer your question.

Bug report: _time_delay() not the good delay.

elapsed time in nanoseconds

Cut-n-Paste from second post:

Every Kinetis device uses the SysTick timer as its master clock source.  Different Kinetis devices can be clocked at different frequencies.  K70 @120 or 150MHz, K60 @100, etc…  So the range is 50-150MHz depending on the device.

In MQX the SysTick timer is clocked at the core frequency.

Ex: Using the K70-120MHz as my example 120MHz has an 8.333 nanosecond/SysTick.

MQX calculates the SysTick timer count down value to generate an interrupt every 5ms.

Ex: 5ms/8.333nanoseconds = 600024 SysTicks.

When you are calling the timeget_nanoseconds() function in the PSP time.c file, it is grabbing the SysTick counter value and scaling it to return a value in nanoseconds since the last MQX Tick occurred.

This value is based off of hardware so it is real.  But the resolution is based on the SysTick counting rate which ic equal to the process core frequency.  Faster processor core frequency means better resolution.

The accuracy of the timeget_microseconds() function call is better than thetimeget_nanoseconds() function call since there are 120 SysTick clocks per microsecond.

With respect to SW1.  I was just placing a breakpoint in the btn_kernel_isr() routine as a place to stop and then use IDE to inspect the variable window.  Nothing more.

With respect to your code to get the TICKS from start of MQX I modified it to the following:

#if 1                       //DES 1=test, 0=default code

            {

                MQX_TICK_STRUCT tickstruct;

                uint32 ticknum[2];

                timeget_elapsed_ticks(&tickstruct);

                ticknum[0] = tickstruct.TICKS[0];  //DES lower 32-bits

                ticknum[1] = tickstruct.TICKS[1];  //DES upper 32-bits

                printf("\n ticknum64 = %u%u\n", ticknum[1], ticknum[0]);         //DES 64-bit TICKS value.

            }

#endif

Regards,

David

0 Kudos
1,231 Views
guillaumetiffin
Contributor III

Hi David,

If I well understand the post, if my K60 is clocked at 100 MHz, I have a tick each 10 nanoseconds.

So if I use the function _time_delay_ticks(10), I will have a delay of 100 nanoseconds. Is it right or not?

And if I use the function _time_diff_nanoseconds(), I will have an accuracy of 10 nanoseconds. Is it right or not?

Because in some posts I understood that everithing is clocked with the minimum timer wich is 5 ms by default. So the minimum accuracy is 5 ms.

In your post I understand that the accuracy is 10 nanoseconds. This is better for me if I want to measure elapsed time.

Do you know in which case the things are clocked by the 5 ms timer?

Regards,

Guillaume

0 Kudos
1,232 Views
DavidS
NXP Employee
NXP Employee

Hi Guillaume,

It's convoluted so hopefully I can clear it up correctly.

If K60 is configured for 100MHz core frequency the SysTick timer is clocked at that rate.  The resolution is 10ns.

The MQX RTOS TICK is setup to be 200 ticks/sec (a TICK every 5ms...i.e. the heart beat).  So the SysTick timer gets configured to count down to zero and generate TICK interrupt every 5ms. 

MQX function calls can read that high speed SysTick timer and return very accurate results.

The various _time_delay() MQX calls strictly are working off the TICK counter (the 5 ms heart beat). 

A _time_delay_ticks(10) will block the current task 10xTICK or 10x5ms=50ms.

A _time_delay(50) does the equivalent delay of 50ms.

So a _time_delay(1) really will round up to 1 TICK or 5ms.

Regards,

David

0 Kudos
1,231 Views
guillaumetiffin
Contributor III

Hello David,

Thank you for your answer.

It was not really obvious in the documentation.

Regards,

Guillaume Tiffineau

0 Kudos