<?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>Kinetis MicrocontrollersのトピックMK66F microsecond timer or DWT</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/MK66F-microsecond-timer-or-DWT/m-p/1846801#M66296</link>
    <description>&lt;P&gt;µcontroller: MK66F. &amp;nbsp;SDK: 2.11.0. &amp;nbsp;MCUXpresso v11.9.0&lt;/P&gt;&lt;P&gt;I'm writing an app on the MK66F that uses an &lt;FONT color="#FF9900"&gt;HC-SR04&lt;/FONT&gt; and part of the process is to determine the delay from the echo signal. &amp;nbsp;I'm using an LPTMR instance to count how long it takes for a rising and falling interrupt to occur on the GPIO input pin. &amp;nbsp;That part all works. &amp;nbsp;But the delay between rising and falling, according the values I get from&amp;nbsp;&lt;FONT color="#FF9900"&gt;&lt;SPAN&gt;LPTMR_GetCurrentTimerCount&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="inherit"&gt;&lt;FONT color="#FF9900"&gt;( LPTMR0 );&lt;/FONT&gt; can be too small to measure in integers: the difference between finish and start can come back as 0, so I'm thinking my timer is counting in milliseconds, instead of microseconds. &amp;nbsp;Depending on the distance, the echo delay can be less than a millisecond, and I need this resolution.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="inherit"&gt;By default, the DWT register isn't available in this SDK. &amp;nbsp;Ok, no worries, but how do I get microsecond level in my LPTMR?&lt;/FONT&gt;&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt; LPTMR_GetDefaultConfig( &amp;amp;tmrConfig );&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; LPTMR_Init( LPTMR0, &amp;amp;tmrConfig );&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; LPTMR_SetTimerPeriod( LPTMR0, 0xFFFF );&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; LPTMR_StartTimer( LPTMR0 );&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;This is the code I'm using to configure and start the LPTMR instance. &amp;nbsp;Or do I implement&amp;nbsp;&lt;SPAN&gt;&lt;FONT color="#FF9900"&gt;SDK_DELAY_USE_DWT&lt;/FONT&gt; as a project define and use &lt;FONT color="#FF9900"&gt;getCpuCycleCount&lt;/FONT&gt;()?&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
    <pubDate>Mon, 15 Apr 2024 06:49:45 GMT</pubDate>
    <dc:creator>aaronm</dc:creator>
    <dc:date>2024-04-15T06:49:45Z</dc:date>
    <item>
      <title>MK66F microsecond timer or DWT</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/MK66F-microsecond-timer-or-DWT/m-p/1846801#M66296</link>
      <description>&lt;P&gt;µcontroller: MK66F. &amp;nbsp;SDK: 2.11.0. &amp;nbsp;MCUXpresso v11.9.0&lt;/P&gt;&lt;P&gt;I'm writing an app on the MK66F that uses an &lt;FONT color="#FF9900"&gt;HC-SR04&lt;/FONT&gt; and part of the process is to determine the delay from the echo signal. &amp;nbsp;I'm using an LPTMR instance to count how long it takes for a rising and falling interrupt to occur on the GPIO input pin. &amp;nbsp;That part all works. &amp;nbsp;But the delay between rising and falling, according the values I get from&amp;nbsp;&lt;FONT color="#FF9900"&gt;&lt;SPAN&gt;LPTMR_GetCurrentTimerCount&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="inherit"&gt;&lt;FONT color="#FF9900"&gt;( LPTMR0 );&lt;/FONT&gt; can be too small to measure in integers: the difference between finish and start can come back as 0, so I'm thinking my timer is counting in milliseconds, instead of microseconds. &amp;nbsp;Depending on the distance, the echo delay can be less than a millisecond, and I need this resolution.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="inherit"&gt;By default, the DWT register isn't available in this SDK. &amp;nbsp;Ok, no worries, but how do I get microsecond level in my LPTMR?&lt;/FONT&gt;&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt; LPTMR_GetDefaultConfig( &amp;amp;tmrConfig );&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; LPTMR_Init( LPTMR0, &amp;amp;tmrConfig );&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; LPTMR_SetTimerPeriod( LPTMR0, 0xFFFF );&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; LPTMR_StartTimer( LPTMR0 );&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;This is the code I'm using to configure and start the LPTMR instance. &amp;nbsp;Or do I implement&amp;nbsp;&lt;SPAN&gt;&lt;FONT color="#FF9900"&gt;SDK_DELAY_USE_DWT&lt;/FONT&gt; as a project define and use &lt;FONT color="#FF9900"&gt;getCpuCycleCount&lt;/FONT&gt;()?&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 15 Apr 2024 06:49:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/MK66F-microsecond-timer-or-DWT/m-p/1846801#M66296</guid>
      <dc:creator>aaronm</dc:creator>
      <dc:date>2024-04-15T06:49:45Z</dc:date>
    </item>
    <item>
      <title>Re: MK66F microsecond timer or DWT</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/MK66F-microsecond-timer-or-DWT/m-p/1847006#M66298</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have checked the LPTMR module of K66, it does not have capture function, so it is not suitable for your application.&lt;/P&gt;
&lt;P&gt;I suggest you use TPM or FTM modules to test the signal duty cycle or cycle time. You can connect the tested signal to the TPM_CHx pin(capture signal), when the rising/falling edge of the capture signal is detected, the current counter value is loaded into _CnV register, and interrupt is fired. Secondly, the TPM and FTM have high driving clock, so you can get high resolution. The LPTMR module is designed to work in low power mode, so it's driving clock is lowerer than that of TPM/FTM, so resolution is lower, btw, it does not support capture function.&lt;/P&gt;
&lt;P&gt;I suggest you download SDK from the link:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://mcuxpresso.nxp.com/en/select" target="_blank"&gt;https://mcuxpresso.nxp.com/en/select&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the SDK, there is input_capture example, located at:&lt;/P&gt;
&lt;P&gt;............\driver_examples\ftm\input_capture&lt;/P&gt;
&lt;P&gt;Hope it can help you&lt;/P&gt;
&lt;P&gt;BR&lt;/P&gt;
&lt;P&gt;XiangJun Rong&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2024 09:33:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/MK66F-microsecond-timer-or-DWT/m-p/1847006#M66298</guid>
      <dc:creator>xiangjun_rong</dc:creator>
      <dc:date>2024-04-15T09:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: MK66F microsecond timer or DWT</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/MK66F-microsecond-timer-or-DWT/m-p/1848726#M66306</link>
      <description>&lt;P&gt;&lt;SPAN&gt;XiangJun, thank you for this insight. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My GPIO interrupt handler is already handling the rise and fall events on the input pin, so I didn't really want "capture" from from FlexTimer. &amp;nbsp;I looked through the Mbed OS code for the MK66F, and found that they use the &lt;FONT color="#FF9900"&gt;Periodic Interrupt Timer&lt;/FONT&gt; (PIT) to generate a cycle count, and I was able to graft much of their code to mine - particularly the &lt;FONT color="#FF9900"&gt;us_ticker_init&lt;/FONT&gt;() and &lt;FONT color="#FF9900"&gt;pit_isr&lt;/FONT&gt;() routines from&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;FONT color="#339966"&gt;mbed-os/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K66F/us_ticker.c&lt;/FONT&gt; - and it seems to work. &amp;nbsp;My GPIO handler will read the &lt;FONT color="#FF9900"&gt;PIT_GetCurrentTimerCount&lt;/FONT&gt;() on&amp;nbsp;&lt;/SPAN&gt;signal rise, and then another count on signal fall so I can count microseconds.&lt;/P&gt;&lt;P&gt;But I thank you for pointing me in this direction.&lt;/P&gt;&lt;P&gt;Aaron&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 05:57:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/MK66F-microsecond-timer-or-DWT/m-p/1848726#M66306</guid>
      <dc:creator>aaronm</dc:creator>
      <dc:date>2024-04-17T05:57:22Z</dc:date>
    </item>
  </channel>
</rss>

