<?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>i.MX RT Crossover MCUsのトピックRe: Incorrect counter value measuring time between interrupts</title>
    <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Incorrect-counter-value-measuring-time-between-interrupts/m-p/1399189#M17986</link>
    <description>&lt;P&gt;Hello&lt;BR /&gt;Hope you are well.&lt;BR /&gt;This issue might be cause by the code inside the IRQ Handler. I suggest you leave the code that clears/sets flags.&lt;BR /&gt;To calculate the time you can use a callback function so the result can be processed outside the handler.&lt;/P&gt;
&lt;P&gt;If you have more questions do not hesitate to ask me.&lt;BR /&gt;Best regards,&lt;BR /&gt;Omar&lt;/P&gt;</description>
    <pubDate>Fri, 14 Jan 2022 02:20:52 GMT</pubDate>
    <dc:creator>Omar_Anguiano</dc:creator>
    <dc:date>2022-01-14T02:20:52Z</dc:date>
    <item>
      <title>Incorrect counter value measuring time between interrupts</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Incorrect-counter-value-measuring-time-between-interrupts/m-p/1396169#M17914</link>
      <description>&lt;P&gt;I am using&amp;nbsp;evkmimxrt1064_gpt_timer example project. The settings for counter are as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;GPT_SetClockDivider(EXAMPLE_GPT, 6); //PER clock, so 75MHz/6 = 12.5MHz
GPT_SetOutputCompareValue(EXAMPLE_GPT, kGPT_OutputCompare_Channel1, 125); //125 counts, so 100kHz signal&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the interrupt routine I toggle a GPIO pin and try to measure time between interrupts using the files in attachment. I got these files here on NXP forum.&lt;/P&gt;&lt;P&gt;In the interrupt routine I have the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;void EXAMPLE_GPT_IRQHandler(void)
 {
	result = us_count() - start_time;
	start_time = us_count();
    /* Clear interrupt flag.*/
    GPT_ClearStatusFlags(EXAMPLE_GPT, kGPT_OutputCompare1Flag);
	GPIO_PortToggle(EXAMPLE_LED_GPIO, 1u &amp;lt;&amp;lt; EXAMPLE_LED_GPIO_PIN);

    gptIsrFlag = true;

#if defined __CORTEX_M &amp;amp;&amp;amp; (__CORTEX_M == 4U || __CORTEX_M == 7U)
    __DSB();
#endif
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The issue is that the result fluctuates from 5 to 30 microseconds when I put a breakpoint at GPIO_PortToggle. However, looking at the actual hardware signal, I can clearly see the port being toggled at 10 microseconds:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="CarrotMan_0-1641562253394.png" style="width: 754px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/167021i7959D9F25B6131DC/image-dimensions/754x422?v=v2" width="754" height="422" role="button" title="CarrotMan_0-1641562253394.png" alt="CarrotMan_0-1641562253394.png" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;CarrotMan_0-1641562253394.png&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;My question is what causes the incorrect values to appear in result variable in software?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;P.S. I realized that checking this with edge trigger is not exhaustive, so I checked it with pulse trigger mode, and it always was within the range of 9.6 to 10.5 microseconds.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;CarrotMan&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jan 2022 14:03:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Incorrect-counter-value-measuring-time-between-interrupts/m-p/1396169#M17914</guid>
      <dc:creator>CarrotMan</dc:creator>
      <dc:date>2022-01-07T14:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: Incorrect counter value measuring time between interrupts</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Incorrect-counter-value-measuring-time-between-interrupts/m-p/1399189#M17986</link>
      <description>&lt;P&gt;Hello&lt;BR /&gt;Hope you are well.&lt;BR /&gt;This issue might be cause by the code inside the IRQ Handler. I suggest you leave the code that clears/sets flags.&lt;BR /&gt;To calculate the time you can use a callback function so the result can be processed outside the handler.&lt;/P&gt;
&lt;P&gt;If you have more questions do not hesitate to ask me.&lt;BR /&gt;Best regards,&lt;BR /&gt;Omar&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 02:20:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Incorrect-counter-value-measuring-time-between-interrupts/m-p/1399189#M17986</guid>
      <dc:creator>Omar_Anguiano</dc:creator>
      <dc:date>2022-01-14T02:20:52Z</dc:date>
    </item>
  </channel>
</rss>

