<?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 free counter using fm1 with mke06z128 in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/free-counter-using-fm1-with-mke06z128/m-p/2313170#M68215</link>
    <description>&lt;P class=""&gt;&lt;SPAN&gt;I am setting up a free counter to perform an upward count on MKE06Z128VQH4 using FTM1. My configuration is done via ConfigTool, as shown in the image. My current application uses an interrupt triggered by a rising/falling edge KBI to measure pulse signals. I already measured this signal with a logic analyzer, and it gives me approximately 480 µs for one pulse and 960 µs for another.&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN&gt;Since I configured my counter with a clock = 20 MHz and a prescaler = 16, I consider each tick to be 0.8 µs. Therefore, the counter values should be very close or fairly close to the expected values. However, the measured values are far from what I expected. I’m sharing my test code.&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;void interruption_kbi(void)
   {

       uint16_t now = FTM1-&amp;gt;CNT;
       uint16_t dt;

       if (now &amp;gt;= last_time)
           dt = now - last_time;
       else
           dt = (0xFFFF - last_time) + now + 1;

       last_time = now;
      
       valor_timer = dt;
       
       timerarr[countim]=valor_timer;
       countim++;       

       KBI_ClearInterruptFlag(KBI0);
   }&lt;/LI-CODE&gt;&lt;P class=""&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="count.JPG" style="width: 766px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/375731iA05229D2A55845B1/image-size/large?v=v2&amp;amp;px=999" role="button" title="count.JPG" alt="count.JPG" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;count.JPG&lt;/span&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN&gt;the result is:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;timerarr[0]	uint16_t	451	
timerarr[1]	uint16_t	317	
timerarr[2]	uint16_t	307	
timerarr[3]	uint16_t	64540	
timerarr[4]	uint16_t	1767	
timerarr[5]	uint16_t	1173	
timerarr[6]	uint16_t	2343	
timerarr[7]	uint16_t	61048	
timerarr[8]	uint16_t	1751	
timerarr[9]	uint16_t	1174	
timerarr[10]	uint16_t	2347	
timerarr[11]	uint16_t	60455	
timerarr[12]	uint16_t	1750	
timerarr[13]	uint16_t	2344	
timerarr[14]	uint16_t	61050	
timerarr[15]	uint16_t	1171	&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 05 Feb 2026 19:18:05 GMT</pubDate>
    <dc:creator>Iotelctronic</dc:creator>
    <dc:date>2026-02-05T19:18:05Z</dc:date>
    <item>
      <title>free counter using fm1 with mke06z128</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/free-counter-using-fm1-with-mke06z128/m-p/2313170#M68215</link>
      <description>&lt;P class=""&gt;&lt;SPAN&gt;I am setting up a free counter to perform an upward count on MKE06Z128VQH4 using FTM1. My configuration is done via ConfigTool, as shown in the image. My current application uses an interrupt triggered by a rising/falling edge KBI to measure pulse signals. I already measured this signal with a logic analyzer, and it gives me approximately 480 µs for one pulse and 960 µs for another.&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN&gt;Since I configured my counter with a clock = 20 MHz and a prescaler = 16, I consider each tick to be 0.8 µs. Therefore, the counter values should be very close or fairly close to the expected values. However, the measured values are far from what I expected. I’m sharing my test code.&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;void interruption_kbi(void)
   {

       uint16_t now = FTM1-&amp;gt;CNT;
       uint16_t dt;

       if (now &amp;gt;= last_time)
           dt = now - last_time;
       else
           dt = (0xFFFF - last_time) + now + 1;

       last_time = now;
      
       valor_timer = dt;
       
       timerarr[countim]=valor_timer;
       countim++;       

       KBI_ClearInterruptFlag(KBI0);
   }&lt;/LI-CODE&gt;&lt;P class=""&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="count.JPG" style="width: 766px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/375731iA05229D2A55845B1/image-size/large?v=v2&amp;amp;px=999" role="button" title="count.JPG" alt="count.JPG" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;count.JPG&lt;/span&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN&gt;the result is:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;timerarr[0]	uint16_t	451	
timerarr[1]	uint16_t	317	
timerarr[2]	uint16_t	307	
timerarr[3]	uint16_t	64540	
timerarr[4]	uint16_t	1767	
timerarr[5]	uint16_t	1173	
timerarr[6]	uint16_t	2343	
timerarr[7]	uint16_t	61048	
timerarr[8]	uint16_t	1751	
timerarr[9]	uint16_t	1174	
timerarr[10]	uint16_t	2347	
timerarr[11]	uint16_t	60455	
timerarr[12]	uint16_t	1750	
timerarr[13]	uint16_t	2344	
timerarr[14]	uint16_t	61050	
timerarr[15]	uint16_t	1171	&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Feb 2026 19:18:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/free-counter-using-fm1-with-mke06z128/m-p/2313170#M68215</guid>
      <dc:creator>Iotelctronic</dc:creator>
      <dc:date>2026-02-05T19:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: free counter using fm1 with mke06z128</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/free-counter-using-fm1-with-mke06z128/m-p/2313695#M68219</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/257315"&gt;@Iotelctronic&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Thanks for your post.&lt;/P&gt;
&lt;P&gt;From the ConfigTool screenshot, it appears that you configured the FTM in edge‑aligned mode and set the timer output frequency to 200 Hz. This means you have effectively enabled the timer period function, causing the counter to wrap around at the MOD value rather than at 0xFFFF.&lt;/P&gt;
&lt;DIV&gt;I recommend trying the following two approaches:&lt;/DIV&gt;
&lt;DIV&gt;1.&amp;nbsp; Configure the counter as a true free‑running timer to avoid periodic wrap‑around&lt;/DIV&gt;
&lt;DIV&gt;This allows CNT to increment continuously from 0x0000 to 0xFFFF.&lt;BR /&gt;Disable the timer-related settings in ConfigTool and add the following initialization code:&lt;/DIV&gt;
&lt;DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FTM1-&amp;gt;SC = 0;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;FTM1-&amp;gt;MODE |= FTM_MODE_FTMEN_MASK; &lt;BR /&gt;FTM1-&amp;gt;CNTIN = 0;&lt;BR /&gt;FTM1-&amp;gt;MOD = 0xFFFF; &lt;BR /&gt;FTM1-&amp;gt;CNT = 0;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;FTM1-&amp;gt;SC = FTM_SC_CLKS(1) | FTM_SC_PS(4); // CLKS=01 System clock, PS=100 /16&lt;/P&gt;
&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;2.&amp;nbsp;Keep the current ConfigTool configuration (200 Hz), but correct the wrap‑around logic in the ISR&lt;/DIV&gt;
&lt;DIV&gt;In this case, the counter wraps at the configured MOD value rather than at 0xFFFF, so the wrap‑around calculation should use FTM1-&amp;gt;MOD.&lt;BR /&gt;Updated ISR example:&lt;/DIV&gt;
&lt;DIV&gt;
&lt;P&gt;&lt;BR /&gt;void interruption_kbi(void)&lt;BR /&gt;{&lt;BR /&gt;uint16_t now = FTM1-&amp;gt;CNT;&lt;BR /&gt;uint16_t mod = FTM1-&amp;gt;MOD;&lt;BR /&gt;uint16_t dt;&lt;/P&gt;
&lt;P&gt;if (now &amp;gt;= last_time)&lt;BR /&gt;dt = now - last_time;&lt;BR /&gt;else&lt;BR /&gt;dt = (mod - last_time) + now + 1;&lt;/P&gt;
&lt;P&gt;last_time = now;&lt;BR /&gt;timerarr[countim++] = dt;&lt;/P&gt;
&lt;P&gt;KBI_ClearInterruptFlag(KBI0);&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope it helps.&lt;/P&gt;
&lt;P&gt;BR&lt;/P&gt;
&lt;P&gt;Celeste&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Fri, 06 Feb 2026 10:45:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/free-counter-using-fm1-with-mke06z128/m-p/2313695#M68219</guid>
      <dc:creator>Celeste_Liu</dc:creator>
      <dc:date>2026-02-06T10:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: free counter using fm1 with mke06z128</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/free-counter-using-fm1-with-mke06z128/m-p/2317824#M68236</link>
      <description>&lt;P&gt;&lt;SPAN&gt;thank you for the response, I used the first method by configuring it manually, I verified that the counter is working well, however I am no longer using the counter with kbi, now I am using input capture which I think is better.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Feb 2026 11:40:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/free-counter-using-fm1-with-mke06z128/m-p/2317824#M68236</guid>
      <dc:creator>Iotelctronic</dc:creator>
      <dc:date>2026-02-13T11:40:54Z</dc:date>
    </item>
  </channel>
</rss>

