<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Calculating program execution time in miliseconds or microseconds in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-program-execution-time-in-miliseconds-or/m-p/1231508#M59639</link>
    <description>&lt;P&gt;Hello &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/38376"&gt;@bobpaddock&lt;/a&gt;&amp;nbsp; and &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/1431"&gt;@mjbcswitzerland&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for your help. I solved the problem with timer interrupt which is called every second.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I assigned a variable and increased, when the timer interrupt is called.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have a nice day&lt;/P&gt;</description>
    <pubDate>Tue, 16 Feb 2021 11:02:44 GMT</pubDate>
    <dc:creator>itr1718</dc:creator>
    <dc:date>2021-02-16T11:02:44Z</dc:date>
    <item>
      <title>Calculating program execution time in miliseconds or microseconds</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-program-execution-time-in-miliseconds-or/m-p/1227919#M59553</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to calculate program running time in miliseconds or microseconds.&lt;/P&gt;&lt;P&gt;I used PIT and RTC, but it works not correctly.&lt;/P&gt;&lt;P&gt;"RTC_GetDatetime" calculate in seconds and I thought that this function "PIT_GetCurrentTimerCount" returns a counted execution time.&lt;/P&gt;&lt;P&gt;Moreover, functions from time.h don't work on KL27 Microcontroller.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do I have some mistakes or misunderstanding or are there some methods for the execution time?&lt;/P&gt;&lt;P&gt;How can the time calculated?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PIT Setting:&lt;/P&gt;&lt;P&gt;pit_config_t pitConfig;&lt;/P&gt;&lt;P&gt;PIT_GetDefaultConfig(&amp;amp;pitConfig);&lt;BR /&gt;PIT_Init(PIT, &amp;amp;pitConfig);&lt;BR /&gt;PIT_SetTimerPeriod(PIT, kPIT_Chnl_0, USEC_TO_COUNT(1000000U, PIT_SOURCE_CLOCK));&lt;BR /&gt;PIT_EnableInterrupts(PIT, kPIT_Chnl_0, kPIT_TimerInterruptEnable);&lt;BR /&gt;EnableIRQ(PIT_IRQ_ID);&lt;BR /&gt;PIT_StartTimer(PIT, kPIT_Chnl_0);&lt;BR /&gt;PIT_IRQHandler();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PIT_IRQHandler:&lt;/P&gt;&lt;P&gt;void PIT_IRQHandler(void)&lt;BR /&gt;{&lt;BR /&gt;/* Clear interrupt flag.*/&lt;BR /&gt;PIT_ClearStatusFlags(PIT, kPIT_Chnl_0, kPIT_TimerFlag);&lt;BR /&gt;pitIsrFlag = true;&lt;BR /&gt;__DSB();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Start time:&lt;/P&gt;&lt;P&gt;int64_t start = PIT_GetCurrentTimerCount(PIT, kPIT_Chnl_0);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Calculating running time:&lt;/P&gt;&lt;P&gt;int64_t get_timestamp_us(int64_t start)&lt;BR /&gt;{&lt;BR /&gt;int64_t now = PIT_GetCurrentTimerCount(PIT, kPIT_Chnl_0);&lt;/P&gt;&lt;P&gt;return (now-start) * 1000000;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;itr&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 11:30:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-program-execution-time-in-miliseconds-or/m-p/1227919#M59553</guid>
      <dc:creator>itr1718</dc:creator>
      <dc:date>2021-02-08T11:30:15Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating program execution time in miliseconds or microseconds</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-program-execution-time-in-miliseconds-or/m-p/1228014#M59559</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;The Cortex-M4 contains a cycle counter that is designed to do this very accurately and simply. Therefore it is best to use that instead:&lt;/P&gt;&lt;P&gt;Initialisation:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;DEMCR |= DHCSR_TRCENA; // enable trace for DWT features&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;DWT_CYCCNT = 0; // reset the cycle count value&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;DWT_CTRL |= DWT_CTRL_CYCCNTENA; // enable the cycle counter&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;To measure the time a code section takes&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;unsigned long ulTimeStamp = DWT_CYCCNT; // time stamp before starting&lt;/STRONG&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;.. code to be measured&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;STRONG&gt;ulTimeStamp = (DWT_CYCCNT - ulTimeStamp);&amp;nbsp;&amp;nbsp; // counts during the code execution&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;To convert the value to us&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;ulTimeStamp /= (SYSTEM_CLOCK / 1000000);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Regards&lt;/P&gt;&lt;P&gt;Mark&lt;BR /&gt;&lt;EM&gt;[uTasker project developer for Kinetis and i.MX RT]&lt;/EM&gt;&lt;BR /&gt;&lt;FONT color="#999999"&gt;Contact me by personal message or on the uTasker web site to discuss professional training, solutions to problems or rapid product development requirements&lt;BR /&gt;&lt;BR /&gt;For professionals searching for faster, problem-free Kinetis and i.MX RT 10xx developments the uTasker project holds the key&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 13:58:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-program-execution-time-in-miliseconds-or/m-p/1228014#M59559</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2021-02-08T13:58:48Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating program execution time in miliseconds or microseconds</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-program-execution-time-in-miliseconds-or/m-p/1228015#M59560</link>
      <description>&lt;P&gt;As to Op mentions the KL27, I presume that is what he is using.&lt;BR /&gt;Sadly the KL27 m0+ core doesn't have this.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 14:02:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-program-execution-time-in-miliseconds-or/m-p/1228015#M59560</guid>
      <dc:creator>bobpaddock</dc:creator>
      <dc:date>2021-02-08T14:02:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating program execution time in miliseconds or microseconds</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-program-execution-time-in-miliseconds-or/m-p/1228024#M59561</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;pitIsrFlag = true;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;__DSB();"&lt;BR /&gt;&lt;BR /&gt;Those concern me.&lt;BR /&gt;Flags like this frequently create race conditions.&lt;BR /&gt;Better to increment&amp;nbsp;a var in the IRQ then outside compare with a previous value to see if it changed.&lt;BR /&gt;&lt;BR /&gt;In any case such vars need to be declared 'volatile' .&lt;BR /&gt;&lt;BR /&gt;The DSB instruction&amp;nbsp;itself will cause an unknown number of cycles to be added to each IRQ.&lt;BR /&gt;I expect it was added to see 'will this make this work?'.&amp;nbsp; There are places such instructions are needed, this is not one of them.&lt;BR /&gt;&lt;BR /&gt;What exactly does "time.h doesn't work" mean here?&lt;BR /&gt;What is the clock() function doing or not doing?&lt;BR /&gt;That may depend&amp;nbsp;on the toolchain being used.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 14:14:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-program-execution-time-in-miliseconds-or/m-p/1228024#M59561</guid>
      <dc:creator>bobpaddock</dc:creator>
      <dc:date>2021-02-08T14:14:58Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating program execution time in miliseconds or microseconds</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-program-execution-time-in-miliseconds-or/m-p/1228063#M59563</link>
      <description>&lt;P&gt;Hello &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/38376"&gt;@bobpaddock&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;That is an good idea which a var increases in the IRQ.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will try that.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Furthermore, "time.h doesn't work" means that the functions from time.h which are clock(), time(), gettimeofday(), localtime() etc. They return always -1 after I added -lnosys.&lt;/P&gt;&lt;P&gt;This library, nosys, needs for USB driver.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;itr&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 15:23:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-program-execution-time-in-miliseconds-or/m-p/1228063#M59563</guid>
      <dc:creator>itr1718</dc:creator>
      <dc:date>2021-02-08T15:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating program execution time in miliseconds or microseconds</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-program-execution-time-in-miliseconds-or/m-p/1228087#M59565</link>
      <description>&lt;P&gt;Hello &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/1431"&gt;@mjbcswitzerland&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;as I know, KL27 has Cortex-m0+ and Cortex-m0+ and m4 are different.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you know maybe about Cortex-m0?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;itr&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 15:45:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-program-execution-time-in-miliseconds-or/m-p/1228087#M59565</guid>
      <dc:creator>itr1718</dc:creator>
      <dc:date>2021-02-08T15:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating program execution time in miliseconds or microseconds</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-program-execution-time-in-miliseconds-or/m-p/1228115#M59567</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;My mistake, I oversaw the fact that you are using a KL27.&lt;/P&gt;&lt;P&gt;For the Cortex-M0+ parts one can use PIT0 as follows:&lt;/P&gt;&lt;P&gt;Initialisation:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;POWER_UP_ATOMIC(6, PIT0);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;PIT_MCR = 0;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;LOAD_PIT(0, 0xffffffff);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;PIT_TCTRL0 = PIT_TCTRL_TEN;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;To measure the time a code section takes&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;unsigned long ulTimeStamp =(0xffffffff - PIT_CVAL0); // time stamp before starting&lt;/STRONG&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;.. code to be measured&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;STRONG&gt;ulTimeStamp = ((0xffffffff - PIT_CVAL0) - ulTimeStamp);&amp;nbsp;&amp;nbsp; // counts during the code execution&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;To convert the value to us&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;ulTimeStamp /= (BUS_CLOCK / 1000000);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;There is no need to work with interrupts for such measurements.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Regards&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;P&gt;&lt;EM&gt;P.S Methods taken from uTasker project code.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 16:25:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-program-execution-time-in-miliseconds-or/m-p/1228115#M59567</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2021-02-08T16:25:25Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating program execution time in miliseconds or microseconds</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-program-execution-time-in-miliseconds-or/m-p/1231508#M59639</link>
      <description>&lt;P&gt;Hello &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/38376"&gt;@bobpaddock&lt;/a&gt;&amp;nbsp; and &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/1431"&gt;@mjbcswitzerland&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for your help. I solved the problem with timer interrupt which is called every second.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I assigned a variable and increased, when the timer interrupt is called.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have a nice day&lt;/P&gt;</description>
      <pubDate>Tue, 16 Feb 2021 11:02:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-program-execution-time-in-miliseconds-or/m-p/1231508#M59639</guid>
      <dc:creator>itr1718</dc:creator>
      <dc:date>2021-02-16T11:02:44Z</dc:date>
    </item>
  </channel>
</rss>

