<?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: RT1176-EVAL: Clock drift when using Periodic Interrupt Timer (PIT) in i.MX RT Crossover MCUs</title>
    <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/RT1176-EVAL-Clock-drift-when-using-Periodic-Interrupt-Timer-PIT/m-p/1359079#M16794</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;Hope you are well.&amp;nbsp; I will gladly help you with this.&lt;/P&gt;
&lt;P&gt;I don´t think that the interrupt is causing this drift but I suggest you reserve the IRQ_Handler only for setting or clearing flags. You can create a callback that uses the function update_clock() each time the interruption is executed.&lt;/P&gt;
&lt;P&gt;The precision of the timer is determined by the root clock, using the GPT will not make a considerable difference since they can be fed by the same clock.&lt;BR /&gt;The 24Mhz that feds the PLL3 has a good precision of +-20ppm so it is a good result.&lt;BR /&gt;I also suggest you use the latest version of the SDK(2.10.1)&lt;/P&gt;
&lt;P&gt;You can also check the RTC functionality of the SNVS module, there is one example at the SDK of your board.&lt;BR /&gt;&lt;BR /&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>Thu, 21 Oct 2021 01:58:16 GMT</pubDate>
    <dc:creator>Omar_Anguiano</dc:creator>
    <dc:date>2021-10-21T01:58:16Z</dc:date>
    <item>
      <title>RT1176-EVAL: Clock drift when using Periodic Interrupt Timer (PIT)</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/RT1176-EVAL-Clock-drift-when-using-Periodic-Interrupt-Timer-PIT/m-p/1356452#M16731</link>
      <description>&lt;P&gt;I've been trying to build a real-time-clock using the PIT. But comparing the resulting msec-clock with my systems epoch time, I've been seeing a clock drift on the board. That shift is not constant, it's around 1 to 2 msec per minute. I'm asking myself: is this expected behaviour? Can I somehow improve the accuracy of this clock? Am I initialising it incorrectly? I've been using the PIT example in the&amp;nbsp;SDK as a baseline. As SDK I'm using&amp;nbsp;MCUXpresso Software Development Kit (SDK) in Version 2.9.1.&lt;/P&gt;&lt;P&gt;The following is my code handling this msec-clock.&amp;nbsp;Note that the actual implementation is variable (e.g. a different period than 1msec could be set or other PIT channels could be used), to allow the usage of other PIT-timers as well. But for now I only use it for the msec-timer, and have set the variables to its constant values.&lt;/P&gt;&lt;P&gt;Initialisation of the PIT:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;{
    PIT_Type * pit_base = PIT1;
    pit_config_t pitConfig;
    uint8_t pit_channel = 0;
    uint32_t usec = 1000;

    PIT_GetDefaultConfig(&amp;amp;pitConfig);
    PIT_Init(pit_base, &amp;amp;pitConfig);


    PIT_SetTimerPeriod(pit_base, pit_channel, USEC_TO_COUNT(usec, CLOCK_GetRootClockFreq(kCLOCK_Root_Bus))); //PIT always uses "Peripheral Bus Clock". Has no selectable clock source
    PIT_EnableInterrupts(pit_base, pit_channel, kPIT_TimerInterruptEnable);
    EnableIRQ(PIT1_IRQn);
    PIT_StartTimer(pit_base, pit_channel);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Handling PIT-IRQ:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;void PIT1_IRQHandler(void)
{
    //which channel of PIT1? Clear irq flag, call callback-fct
    if(PIT_GetStatusFlags(PIT1, kPIT_Chnl_0) &amp;amp; kPIT_TimerFlag)
    {
        PIT_ClearStatusFlags(PIT1, kPIT_Chnl_0, kPIT_TimerFlag);
        update_clock(); ///&amp;lt; function increases a int64_t counter by 1
    }
    {...}

    /* Added for, and affects, all PIT handlers. For CPU clock which is much larger than the IP bus clock,
     * CPU can run out of the interrupt handler before the interrupt flag being cleared, resulting in the
     * CPU's entering the handler again and again. Adding DSB can prevent the issue from happening.
     */
    __DSB();
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Initialisation of the `kCLOCK_Root_Bus`:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;void BOARD_BootClockRUN(void)
{
    clock_root_config_t rootCfg = {0};

    [...]

    /* Configure BUS using SYS_PLL3_CLK */
#if __CORTEX_M == 7
    rootCfg.mux = kCLOCK_BUS_ClockRoot_MuxSysPll3Out;
    rootCfg.div = 2;
    CLOCK_SetRootClock(kCLOCK_Root_Bus, &amp;amp;rootCfg);
#endif

    [...]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could it be, that the PIT counter isn't running during the handling of the interrupt? Or is the clock-source just not that stable on the EVAL-board? Would I be better of using the GPT for such high-precision timers?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Oct 2021 11:40:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/RT1176-EVAL-Clock-drift-when-using-Periodic-Interrupt-Timer-PIT/m-p/1356452#M16731</guid>
      <dc:creator>raddeh</dc:creator>
      <dc:date>2021-10-15T11:40:18Z</dc:date>
    </item>
    <item>
      <title>Re: RT1176-EVAL: Clock drift when using Periodic Interrupt Timer (PIT)</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/RT1176-EVAL-Clock-drift-when-using-Periodic-Interrupt-Timer-PIT/m-p/1359079#M16794</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;Hope you are well.&amp;nbsp; I will gladly help you with this.&lt;/P&gt;
&lt;P&gt;I don´t think that the interrupt is causing this drift but I suggest you reserve the IRQ_Handler only for setting or clearing flags. You can create a callback that uses the function update_clock() each time the interruption is executed.&lt;/P&gt;
&lt;P&gt;The precision of the timer is determined by the root clock, using the GPT will not make a considerable difference since they can be fed by the same clock.&lt;BR /&gt;The 24Mhz that feds the PLL3 has a good precision of +-20ppm so it is a good result.&lt;BR /&gt;I also suggest you use the latest version of the SDK(2.10.1)&lt;/P&gt;
&lt;P&gt;You can also check the RTC functionality of the SNVS module, there is one example at the SDK of your board.&lt;BR /&gt;&lt;BR /&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>Thu, 21 Oct 2021 01:58:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/RT1176-EVAL-Clock-drift-when-using-Periodic-Interrupt-Timer-PIT/m-p/1359079#M16794</guid>
      <dc:creator>Omar_Anguiano</dc:creator>
      <dc:date>2021-10-21T01:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: RT1176-EVAL: Clock drift when using Periodic Interrupt Timer (PIT)</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/RT1176-EVAL-Clock-drift-when-using-Periodic-Interrupt-Timer-PIT/m-p/1509927#M21229</link>
      <description>&lt;P&gt;I discovered the issue: I was using the internal oscillators, not the highly stable external one of my board. Changing the clock_config.c via the MCUXpresso Config Tool fixed the clock drift.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2022 06:25:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/RT1176-EVAL-Clock-drift-when-using-Periodic-Interrupt-Timer-PIT/m-p/1509927#M21229</guid>
      <dc:creator>raddeh</dc:creator>
      <dc:date>2022-08-23T06:25:06Z</dc:date>
    </item>
  </channel>
</rss>

