<?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 ProcessorsのトピックRe: How to Timing microseconds-RT1064</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/How-to-Timing-microseconds-RT1064/m-p/1720965#M212431</link>
    <description>&lt;P&gt;I&amp;nbsp;use&amp;nbsp;&lt;SPAN&gt;&lt;SPAN class=""&gt;kCLOCK_IpgClk as GPT Clock and set the compare value as 150. &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;I count the interrupt number, and after 200 and 500000 counts, change the GPIO_pin, it can work well, as the picture shows bellow:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="irisxxxxxx_0-1694505398600.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/240570iA694272A49F724E0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="irisxxxxxx_0-1694505398600.png" alt="irisxxxxxx_0-1694505398600.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;But if after 150 and 500000 counts to change the GPIO, It cannot work.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="irisxxxxxx_1-1694505454583.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/240571iCB21DA4614893317/image-size/medium?v=v2&amp;amp;px=400" role="button" title="irisxxxxxx_1-1694505454583.png" alt="irisxxxxxx_1-1694505454583.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 12 Sep 2023 08:03:59 GMT</pubDate>
    <dc:creator>ahhhhhhhhhhh</dc:creator>
    <dc:date>2023-09-12T08:03:59Z</dc:date>
    <item>
      <title>How to Timing microseconds-RT1064</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/How-to-Timing-microseconds-RT1064/m-p/1720715#M212395</link>
      <description>&lt;P&gt;Hi Community,&lt;/P&gt;&lt;P&gt;I want to make the user LED ON for 100us and OFF for 1s based on RT1064 evaluation Kit. And I modify the example program of GPT, but the minimum timing I can use is 1ms. When I set the compare value lower than 250000, there was something wrong. How to solve it?&lt;/P&gt;&lt;P&gt;Here is the code:&lt;/P&gt;&lt;P&gt;#include "fsl_debug_console.h"&lt;BR /&gt;#include "pin_mux.h"&lt;BR /&gt;#include "clock_config.h"&lt;BR /&gt;#include "board.h"&lt;BR /&gt;#include "fsl_gpt.h"&lt;/P&gt;&lt;P&gt;/*******************************************************************************&lt;BR /&gt;* Definitions&lt;BR /&gt;******************************************************************************/&lt;BR /&gt;#define GPT_IRQ_ID GPT2_IRQn&lt;BR /&gt;#define EXAMPLE_GPT GPT2&lt;BR /&gt;#define EXAMPLE_GPT_IRQHandler GPT2_IRQHandler&lt;/P&gt;&lt;P&gt;#define EXAMPLE_LED_GPIO BOARD_USER_LED_GPIO&lt;BR /&gt;#define EXAMPLE_LED_GPIO_PIN BOARD_USER_LED_PIN&lt;BR /&gt;/* Get source clock for GPT driver (GPT prescaler = 0) */&lt;BR /&gt;#define EXAMPLE_GPT_CLK_FREQ CLOCK_GetFreq(kCLOCK_PerClk)&lt;/P&gt;&lt;P&gt;/*******************************************************************************&lt;BR /&gt;* Prototypes&lt;BR /&gt;******************************************************************************/&lt;/P&gt;&lt;P&gt;/*******************************************************************************&lt;BR /&gt;* Variables&lt;BR /&gt;******************************************************************************/&lt;/P&gt;&lt;P&gt;volatile bool gptIsrFlag = false;&lt;BR /&gt;volatile uint32_t g_systickCounter;&lt;BR /&gt;volatile uint32_t count=0;&lt;/P&gt;&lt;P&gt;/*******************************************************************************&lt;BR /&gt;* Code&lt;BR /&gt;******************************************************************************/&lt;BR /&gt;void EXAMPLE_GPT_IRQHandler(void)&lt;BR /&gt;{&lt;BR /&gt;/* Clear interrupt flag.*/&lt;BR /&gt;GPT_ClearStatusFlags(EXAMPLE_GPT, kGPT_OutputCompare1Flag);&lt;/P&gt;&lt;P&gt;gptIsrFlag = true;&lt;BR /&gt;count+=1;&lt;BR /&gt;/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F, Cortex-M7, Cortex-M7F Store immediate overlapping&lt;BR /&gt;exception return operation might vector to incorrect interrupt */&lt;BR /&gt;SDK_ISR_EXIT_BARRIER;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;/*!&lt;BR /&gt;* @brief Main function&lt;BR /&gt;*/&lt;BR /&gt;int main(void)&lt;BR /&gt;{&lt;BR /&gt;uint32_t gptFreq = 250000; //why cannot use 25?&lt;BR /&gt;&lt;BR /&gt;gpt_config_t gptConfig;&lt;/P&gt;&lt;P&gt;/* Board pin, clock, debug console init */&lt;BR /&gt;BOARD_ConfigMPU();&lt;BR /&gt;BOARD_InitBootPins();&lt;BR /&gt;BOARD_InitBootClocks();&lt;BR /&gt;BOARD_InitDebugConsole();&lt;/P&gt;&lt;P&gt;GPT_GetDefaultConfig(&amp;amp;gptConfig);&lt;/P&gt;&lt;P&gt;/* Initialize GPT module */&lt;BR /&gt;GPT_Init(EXAMPLE_GPT, &amp;amp;gptConfig);&lt;/P&gt;&lt;P&gt;/* Divide GPT clock source frequency by 3 inside GPT module */&lt;BR /&gt;GPT_SetClockDivider(EXAMPLE_GPT, 3);&lt;/P&gt;&lt;P&gt;/* Get GPT clock frequency */&lt;BR /&gt;//gptFreq = EXAMPLE_GPT_CLK_FREQ;&lt;/P&gt;&lt;P&gt;/* GPT frequency is divided by 3 inside module */&lt;BR /&gt;//gptFreq /= 3;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/* Set both GPT modules to 100us duration */&lt;BR /&gt;GPT_SetOutputCompareValue(EXAMPLE_GPT, kGPT_OutputCompare_Channel1, gptFreq);&lt;/P&gt;&lt;P&gt;/* Enable GPT Output Compare1 interrupt */&lt;BR /&gt;GPT_EnableInterrupts(EXAMPLE_GPT, kGPT_OutputCompare1InterruptEnable);&lt;/P&gt;&lt;P&gt;/* Enable at the Interrupt */&lt;BR /&gt;EnableIRQ(GPT_IRQ_ID);&lt;/P&gt;&lt;P&gt;// PRINTF("\r\nPress any key to start the example");&lt;BR /&gt;// GETCHAR();&lt;/P&gt;&lt;P&gt;/* Start Timer */&lt;BR /&gt;PRINTF("\r\nStarting GPT timer ...");&lt;BR /&gt;GPT_StartTimer(EXAMPLE_GPT);&lt;/P&gt;&lt;P&gt;while (true)&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/* Check whether occur interupt and toggle LED */&lt;BR /&gt;if (true == gptIsrFlag)&lt;BR /&gt;{&lt;BR /&gt;if(count==1)&lt;BR /&gt;{&lt;BR /&gt;GPIO_PinWrite(EXAMPLE_LED_GPIO, EXAMPLE_LED_GPIO_PIN, 0U);&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;if(count==100)&lt;BR /&gt;{&lt;BR /&gt;count=0;&lt;BR /&gt;GPIO_PinWrite(EXAMPLE_LED_GPIO, EXAMPLE_LED_GPIO_PIN, 1U);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;PRINTF("\r\n GPT interrupt is occurred !");&lt;BR /&gt;gptIsrFlag = false;&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;__WFI();&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2023 02:14:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/How-to-Timing-microseconds-RT1064/m-p/1720715#M212395</guid>
      <dc:creator>ahhhhhhhhhhh</dc:creator>
      <dc:date>2023-09-12T02:14:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to Timing microseconds-RT1064</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/How-to-Timing-microseconds-RT1064/m-p/1720965#M212431</link>
      <description>&lt;P&gt;I&amp;nbsp;use&amp;nbsp;&lt;SPAN&gt;&lt;SPAN class=""&gt;kCLOCK_IpgClk as GPT Clock and set the compare value as 150. &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;I count the interrupt number, and after 200 and 500000 counts, change the GPIO_pin, it can work well, as the picture shows bellow:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="irisxxxxxx_0-1694505398600.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/240570iA694272A49F724E0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="irisxxxxxx_0-1694505398600.png" alt="irisxxxxxx_0-1694505398600.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;But if after 150 and 500000 counts to change the GPIO, It cannot work.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="irisxxxxxx_1-1694505454583.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/240571iCB21DA4614893317/image-size/medium?v=v2&amp;amp;px=400" role="button" title="irisxxxxxx_1-1694505454583.png" alt="irisxxxxxx_1-1694505454583.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2023 08:03:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/How-to-Timing-microseconds-RT1064/m-p/1720965#M212431</guid>
      <dc:creator>ahhhhhhhhhhh</dc:creator>
      <dc:date>2023-09-12T08:03:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to Timing microseconds-RT1064</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/How-to-Timing-microseconds-RT1064/m-p/1721104#M212452</link>
      <description>&lt;P&gt;To achieve a 100 microseconds (us) LED ON and 1-second OFF timing with the RT1064 evaluation kit, modify your code as follows:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;#include "fsl_debug_console.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "board.h"
#include "fsl_gpt.h"

volatile bool gptIsrFlag = false;

void EXAMPLE_GPT_IRQHandler(void)
{
    GPT_ClearStatusFlags(EXAMPLE_GPT, kGPT_OutputCompare1Flag);
    GPIO_PinWrite(EXAMPLE_LED_GPIO, EXAMPLE_LED_GPIO_PIN, 1U);  // Turn LED ON
    for (uint32_t i = 0; i &amp;lt; 25; i++) {
        __NOP();  // Introduce a 100us delay
    }
    GPIO_PinWrite(EXAMPLE_LED_GPIO, EXAMPLE_LED_GPIO_PIN, 0U);  // Turn LED OFF
    gptIsrFlag = true;
}

int main(void)
{
    gpt_config_t gptConfig;
    uint32_t gptFreq = 1000; // 1ms

    BOARD_ConfigMPU();
    BOARD_InitBootPins();
    BOARD_InitBootClocks();
    BOARD_InitDebugConsole();

    GPT_GetDefaultConfig(&amp;amp;gptConfig);
    GPT_Init(EXAMPLE_GPT, &amp;amp;gptConfig);
    GPT_SetOutputCompareValue(EXAMPLE_GPT, kGPT_OutputCompare_Channel1, gptFreq);
    GPT_EnableInterrupts(EXAMPLE_GPT, kGPT_OutputCompare1InterruptEnable);
    EnableIRQ(GPT_IRQ_ID);

    PRINTF("\r\nStarting GPT timer ...");
    GPT_StartTimer(EXAMPLE_GPT);

    while (true)
    {
        __WFI();
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This code turns the LED ON for 100us and OFF for 1ms using the GPT module for precise timing. The key modification is the introduction of a __NOP() loop to create a 100us delay inside the interrupt handler.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2023 10:15:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/How-to-Timing-microseconds-RT1064/m-p/1721104#M212452</guid>
      <dc:creator>tanu500</dc:creator>
      <dc:date>2023-09-12T10:15:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to Timing microseconds-RT1064</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/How-to-Timing-microseconds-RT1064/m-p/1721586#M212495</link>
      <description>&lt;P&gt;Thanks a lot, It works. But I still have some confusions about the clock.&lt;/P&gt;&lt;P&gt;I divide the GPT clock and change the value, then every 1 s , it will enter an interrupt.&amp;nbsp;&lt;/P&gt;&lt;P&gt;uint32_t gptFreq = 25000000;&lt;/P&gt;&lt;P&gt;/* Divide GPT clock source frequency by 3 inside GPT module */&lt;BR /&gt;GPT_SetClockDivider(EXAMPLE_GPT, 3);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But how to determine the time of _nop()? I found that when I set&amp;nbsp;20000 times nop, then it will delay about 100us. So what clock it should use?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;void EXAMPLE_GPT_IRQHandler(void)&lt;BR /&gt;{&lt;BR /&gt;/* Clear interrupt flag.*/&lt;BR /&gt;GPT_ClearStatusFlags(EXAMPLE_GPT, kGPT_OutputCompare1Flag);&lt;BR /&gt;GPIO_PinWrite(EXAMPLE_LED_GPIO, EXAMPLE_LED_GPIO_PIN, 1U); // Turn LED ON&lt;BR /&gt;for (uint32_t i = 0; i &amp;lt; 20000; i++) {&lt;BR /&gt;__NOP(); // Introduce a 100us delay&lt;BR /&gt;}&lt;BR /&gt;GPIO_PinWrite(EXAMPLE_LED_GPIO, EXAMPLE_LED_GPIO_PIN, 0U); // Turn LED OFF&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2023 03:25:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/How-to-Timing-microseconds-RT1064/m-p/1721586#M212495</guid>
      <dc:creator>ahhhhhhhhhhh</dc:creator>
      <dc:date>2023-09-13T03:25:14Z</dc:date>
    </item>
  </channel>
</rss>

