<?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中的主题 Re: Using FTM compare</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Using-FTM-compare/m-p/936601#M54221</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In a nutshell: stop the timer when updating &lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;FTM2_C0V&lt;/SPAN&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In my case:&lt;/P&gt;&lt;P&gt;void SetShortTimeout(uint16_t us)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; FTM2_SC = FTM_SC_CLKS(0) | FTM_SC_PS(6); // Stop the timer&lt;BR /&gt;&amp;nbsp; FTM2_C0V = FTM2_CNT + us;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // New compare value&lt;BR /&gt;&amp;nbsp; FTM2_C0SC &amp;amp;= ~FTM_CnSC_CHF_MASK;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Reset of the event flag&lt;BR /&gt;&amp;nbsp; FTM2_SC = FTM_SC_CLKS(1) | FTM_SC_PS(6); // Restart the timer&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good workaround... perfect for me and in this case. Thank you very much.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But this operation disturbs the main counter, i.e. all the 8 channels!&lt;/P&gt;&lt;P&gt;How awful...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 19 Sep 2019 07:16:08 GMT</pubDate>
    <dc:creator>mauriziospagni</dc:creator>
    <dc:date>2019-09-19T07:16:08Z</dc:date>
    <item>
      <title>Using FTM compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Using-FTM-compare/m-p/936595#M54215</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I want to use one timer (FTM2 in my case) of a&amp;nbsp;MKE02Z32VLC2 to set a flag after a specified time. In this case, just for testing, it's fixed at 10000 timer steps but in practice it will be variable.&lt;/P&gt;&lt;P&gt;The standard procedure, used thousand of times in other projects with many other processors, is replicated in this processor as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FTM2_C0SC = FTM_CnSC_MSA_MASK; // MS = 0:1 (compare), ELS = 0:0, interrupt disabled&lt;/P&gt;&lt;P&gt;FTM2_SC = FTM_SC_CLKS(1) | FTM_SC_PS(6); // System clock, prescaler 64&lt;/P&gt;&lt;P&gt;while (1)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Output pin Toggle&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;FTM2_C0V = FTM2_CNT + 10000; // Set the compare value&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;FTM2_C0SC &amp;amp;= ~FTM_CnSC_CHF_MASK; // Reset of the event flag&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do {} while ((FTM2_C0SC &amp;amp; FTM_CnSC_CHF_MASK) == 0); // Wait for the compare event&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But in this case it doesn't work. I see the output toggling every timer rollover. It seems that FTM2_C0V is not set.&lt;/P&gt;&lt;P&gt;I know that FTM2_C0V is really updated only after the timer has advanced one step, but here it seems it's simply ignored.&lt;/P&gt;&lt;P&gt;By the way: the timer clock is much slower than the CPU clock.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was unable to find any example on the 'net.&lt;/P&gt;&lt;P&gt;Any idea?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Sep 2019 16:00:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Using-FTM-compare/m-p/936595#M54215</guid>
      <dc:creator>mauriziospagni</dc:creator>
      <dc:date>2019-09-17T16:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using FTM compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Using-FTM-compare/m-p/936596#M54216</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Maurizio Spagni,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It seems that you only need the timer set a flag after a specified time, don't need one pin output waveform.&lt;BR /&gt;Then I recommend you use &lt;STRONG&gt;PIT&lt;/STRONG&gt; instead of use &lt;STRONG&gt;FTM&lt;/STRONG&gt; &lt;EM&gt;Output Compare mode&lt;/EM&gt;.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="PIT.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/87851i4AD0E4EC02320298/image-size/large?v=v2&amp;amp;px=999" role="button" title="PIT.png" alt="PIT.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="FTM Output Compare mode.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/87894i9A6A9666A18D36CD/image-size/large?v=v2&amp;amp;px=999" role="button" title="FTM Output Compare mode.png" alt="FTM Output Compare mode.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px; font-size: 14px;"&gt;Best Regards,&lt;/P&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px; font-size: 14px;"&gt;Robin&lt;/P&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px; font-size: 14px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px; font-size: 14px;"&gt;-----------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Sep 2019 02:24:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Using-FTM-compare/m-p/936596#M54216</guid>
      <dc:creator>Robin_Shen</dc:creator>
      <dc:date>2019-09-18T02:24:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using FTM compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Using-FTM-compare/m-p/936597#M54217</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Robin,&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;Robin_Shen wrote:&lt;/P&gt;It seems that you only need the timer set a flag after a specified time, don't need one pin output waveform.&lt;/BLOCKQUOTE&gt;&lt;P&gt;Yes, right that, but the thing is absolutely&lt;STRONG&gt; a-periodical.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I mean: sometime in the program execution I neet to know when some time has passed, so I set the compare at (current time + delay) (i.e. FTM2_C0V = FTM2_CNT + delta) then the program does something else and, synchronously, periodically polls the event flag (FTM_CnSC_CHF).&lt;/P&gt;&lt;P&gt;That's common practice since the times of Motorola HC08.&lt;/P&gt;&lt;P&gt;And the thing doesn't change even if I use the interrupts.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My question is more specifically addressed on: why the FTM behaves in this odd mode? What I overlooked?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Maurizio&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Sep 2019 06:32:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Using-FTM-compare/m-p/936597#M54217</guid>
      <dc:creator>mauriziospagni</dc:creator>
      <dc:date>2019-09-18T06:32:35Z</dc:date>
    </item>
    <item>
      <title>Re: Using FTM compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Using-FTM-compare/m-p/936598#M54218</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This works:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FTM2_C0SC = FTM_CnSC_MSA_MASK; // MS = 0:1 (compare), ELS = 0:0, interrupt disabled&lt;/P&gt;&lt;P&gt;FTM2_SC = FTM_SC_CLKS(1) | FTM_SC_PS(6); // System clock, prescaler 64&lt;/P&gt;&lt;P&gt;while (1)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; uint32_t foo;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Output pin Toggle&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; foo = FTM2_CNT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;FTM2_C0V = foo + 10000; // Set the compare value&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do {} while (foo == FTM2_CNT); // Wait for the actual loading of FTM2_C0V&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;FTM2_C0SC &amp;amp;= ~FTM_CnSC_CHF_MASK; // Reset of the event flag&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do {} while ((FTM2_C0SC &amp;amp; FTM_CnSC_CHF_MASK) == 0); // Wait for the compare event&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but it's absurd I need to waste time waiting for FTM2_C0V to be loaded.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Sep 2019 06:44:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Using-FTM-compare/m-p/936598#M54218</guid>
      <dc:creator>mauriziospagni</dc:creator>
      <dc:date>2019-09-18T06:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: Using FTM compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Using-FTM-compare/m-p/936599#M54219</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It seems that I'm not alone!&lt;/P&gt;&lt;P&gt;The problem was already met &lt;A _jive_internal="true" href="https://community.nxp.com/thread/320796"&gt;here.&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I missed that post when I browsed the community because I was looking for "compare".&lt;/P&gt;&lt;P&gt;Anyway, as far as I understand, the problem was not solved.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;N.B. A slightly better (but still completely unsatisfactory) way to make it work is as follow:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;while (1)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; uint16_t foo;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Output pin Toggle&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; foo = FTM2_CNT + 10000;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;FTM2_C0V = foo; // Set the compare value&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do {} while (FTM2_C0V != foo); // Wait for the actual loading of FTM2_C0V&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;FTM2_C0SC &amp;amp;= ~FTM_CnSC_CHF_MASK; // Reset of the event flag&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do {} while ((FTM2_C0SC &amp;amp; FTM_CnSC_CHF_MASK) == 0); // Wait for the compare event&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Sep 2019 14:43:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Using-FTM-compare/m-p/936599#M54219</guid>
      <dc:creator>mauriziospagni</dc:creator>
      <dc:date>2019-09-18T14:43:18Z</dc:date>
    </item>
    <item>
      <title>Re: Using FTM compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Using-FTM-compare/m-p/936600#M54220</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="26.4.10.3 CnV register update.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/83156i2EDC4FF4CB63042F/image-size/large?v=v2&amp;amp;px=999" role="button" title="26.4.10.3 CnV register update.png" alt="26.4.10.3 CnV register update.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;Since&amp;nbsp;the thing is absolutely&lt;/SPAN&gt;&lt;STRONG style="color: #51626f; background-color: #ffffff; border: 0px; font-weight: bold;"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;a-periodical, &lt;/STRONG&gt;would you please try:&lt;/P&gt;&lt;P&gt;first&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;FTM2_C0V = 10000;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;then&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;&lt;SPAN&gt;FTM2_SC |= FTM_SC_CLKS(1);&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Sep 2019 06:46:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Using-FTM-compare/m-p/936600#M54220</guid>
      <dc:creator>Robin_Shen</dc:creator>
      <dc:date>2019-09-19T06:46:42Z</dc:date>
    </item>
    <item>
      <title>Re: Using FTM compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Using-FTM-compare/m-p/936601#M54221</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In a nutshell: stop the timer when updating &lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;FTM2_C0V&lt;/SPAN&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In my case:&lt;/P&gt;&lt;P&gt;void SetShortTimeout(uint16_t us)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; FTM2_SC = FTM_SC_CLKS(0) | FTM_SC_PS(6); // Stop the timer&lt;BR /&gt;&amp;nbsp; FTM2_C0V = FTM2_CNT + us;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // New compare value&lt;BR /&gt;&amp;nbsp; FTM2_C0SC &amp;amp;= ~FTM_CnSC_CHF_MASK;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Reset of the event flag&lt;BR /&gt;&amp;nbsp; FTM2_SC = FTM_SC_CLKS(1) | FTM_SC_PS(6); // Restart the timer&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good workaround... perfect for me and in this case. Thank you very much.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But this operation disturbs the main counter, i.e. all the 8 channels!&lt;/P&gt;&lt;P&gt;How awful...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Sep 2019 07:16:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Using-FTM-compare/m-p/936601#M54221</guid>
      <dc:creator>mauriziospagni</dc:creator>
      <dc:date>2019-09-19T07:16:08Z</dc:date>
    </item>
  </channel>
</rss>

