<?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: Conditionally setup FTM Output Compare  in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806114#M48992</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the instructive example. I've set it up for my TWR-K64 board, to test the outputs and timing. Below is what I found, along with some proposed solutions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Initial test&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_2.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68602i6D668CAB34F063E0/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_2.png" alt="pastedImage_2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Running your code exactly as you attached it produces the above results. How did you generate your figures? Are those measured signals on an oscilloscope, or is it a simulated output? Anyway, there are two major problems with this code:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Setting up the Output Compare with&amp;nbsp;&lt;EM&gt;kFTM_NoOutputSignal&lt;/EM&gt; causes the signal to decay.&lt;/LI&gt;&lt;LI&gt;The FTM_SetSoftwareTrigger() call restarts the FTM counter at 0, so the CH1 period is not consistent if a trigger event occurs during the a given FTM cycle. This is because the FTM module is initialized with SWRSTCNT = 1.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;First fix: don't use &lt;EM&gt;kFTM_NoOutputSignal&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_5.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68742i3AF28C99D2D9429E/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_5.png" alt="pastedImage_5.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;/EM&gt;Instead of using&amp;nbsp;&lt;EM&gt;kFTM_NoOutputSignal&lt;/EM&gt;, I simply set up the Output Compare with whatever state the output is currently in. For example, if the output is in the high state, I call:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;FTM_SetupOutputCompare(BOARD_FTM_BASEADDR, BOARD_FTM_OUT_CHANNEL, &lt;EM&gt;kFTM_SetOnMatch&lt;/EM&gt;, compareValue);&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;And similarly if the output is in the low state, I use&amp;nbsp;&lt;EM&gt;kFTM_ClearOnMatch.&lt;/EM&gt; Since the compareValue is greater than MOD, these commands don't actually cause "set" or "clear" operations, but they do seem to prevent the signal droop shown in&amp;nbsp;the first figure.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'll note that I also found that this extra call to FTM_SetupOutputCompare(), in which a compareValue &amp;gt; MOD is used, is unnecessary. It simply changes the&amp;nbsp;total delay between rising and falling edges out the Output Compare channel (since it involves a couple extra instructions).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Second fix: SWRSTCNT = 0&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The documentation for the SWRSTCNT bit isn't very clear, but&amp;nbsp;according to&amp;nbsp;AN5142 (Features of the FlexTimer Module): "&lt;STRONG&gt;&lt;EM&gt;If the SWRSTCNT bit is set, the FTM counter restarts with FTM_CNTIN register value&lt;/EM&gt;&lt;/STRONG&gt; and the FTM_MOD and FTM_CnV registers are updated immediately. If the SWRSTCNT bit is cleared, the FTM counter continues to count normally and the FTM_MOD and FTM_CnV register update at the next loading point."&lt;/P&gt;&lt;P&gt;This suggests that the initial state of SWRSTCNT = 1 is the issue. As you can see from the first two figures, any time a GPIO toggle occurs, the FTM counter is restarted, and the PWM period is irregular.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_6.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68781iBAD316054C4C5C30/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_6.png" alt="pastedImage_6.png" /&gt;&lt;/span&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Setting SWRSTCNT = 0&amp;nbsp;does fix the periodicity of the FTM0_CH1 PWM output (above). However, it also causes the Output Compare setup to never occur, and so the FTM0_CH0 output remains stuck in a low state.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Third fix: set up loading points at CNTMIN and CNTMAX&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;By default, the FTM is initialized with FTM_SYNC = 0b1000, (or SYNCHOM = 1, REINIT = 0, CNTMAX = 0, and CNTMIN = 0). With SWRSTCNT = 0, the FTM_SetSoftwareTrigger() no longer caused an immediate update of the CnV register, so I had to enable loading points. After setting CNTMIN = 1 and CNTMAX = 1, I found the following behavior:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_9.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68831i29BE3B85BF037E40/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_9.png" alt="pastedImage_9.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;As you can see, the FTM0_CH0 output compare toggle always happens one FTM cycle&amp;nbsp;&lt;EM&gt;after&lt;/EM&gt; the output compare is set up. This is the desired and expected behavior with SWRSTCNT = 0, along with CNTMIN = 1 and CNTMAX = 1. So this all looks great.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;But the issue remains for my DDS project:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;However, I tried to use the same FTM initialization for my DDS code in another project, and I no longer see the desired/expected behavior. As shown below, the SetOnMatch behavior is inconsistent. Sometimes, as in Fig. 1 the SetOnMatch occurs in the same period as FTM_SetupOutputCompare(). And other times, as in Fig. 2, the SetOnMatch occurs in the next FTM cycle (after ISR2).&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_12.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68603i4EF48CB140BDB39D/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_12.png" alt="pastedImage_12.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I don't understand this non-deterministic behavior. As best I can tell, I have the FTM initialized the same way for both projects. That is:&lt;/P&gt;&lt;P&gt;FTM_MODE = 5 (0b101)&lt;/P&gt;&lt;P&gt;FTM_SYNC = 11 (0b1011)&lt;/P&gt;&lt;P&gt;FTM_COMBINE = 538976288 (0b100000001000000010000000100000)&lt;/P&gt;&lt;P&gt;FTM_SYNCONF = 7860 (0b1111010110100)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So again, I'm at an impasse as to why my code is behaving incorrectly.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 08 Sep 2018 00:31:23 GMT</pubDate>
    <dc:creator>aberger</dc:creator>
    <dc:date>2018-09-08T00:31:23Z</dc:date>
    <item>
      <title>Conditionally setup FTM Output Compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806099#M48977</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to use Output Compare to set (and clear) an FTM channel as a square-wave output, synchronized to a direct digital synthesis (DDS) waveform being generated by the same FTM module.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="DDS_with_outputCompare.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/67130iACDADE608CFB9E9D/image-size/large?v=v2&amp;amp;px=999" role="button" title="DDS_with_outputCompare.png" alt="DDS_with_outputCompare.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The FTM_MOD determines the update frequency of the 32-bit DDS phase accumulator. On each FTM overflow, the DDSphase accumulator is incremented by the frequency tuning word (FTW). When the phase accumulator is within a single FTW of overflowing, I calculate the FTM Count at which the projected DDS phase is expected to overflow, and set the Output Compare register to this value. (I am using the FTM_SetupOutputCompare() function from the fsl_ftm.c driver module to do so).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Strangely, when I observe the relative timing of the DDS update and the Output Compare "set",&amp;nbsp;they are always separated by some fixed delay, and not by the value I have calculated. This fixed delay occurs regardless of the FTW (i.e. the DDS output frequency). The fixed delay also occurs&amp;nbsp;if I manually set the Output Compare value to some fixed number less than FTM_MOD, instead of using the formula from the above figure. (For concreteness, the measured delay is almost one full FTM_MOD period).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there some reason that the Output Compare register would not be updated immediately?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Aug 2018 00:46:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806099#M48977</guid>
      <dc:creator>aberger</dc:creator>
      <dc:date>2018-08-21T00:46:27Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally setup FTM Output Compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806100#M48978</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The fixed delay was caused by MOD register update.&lt;/P&gt;&lt;P&gt;In general, the MOD register value isn't updated when the new value written into the register.&lt;/P&gt;&lt;P&gt;The MOD register synchronization will bring that delay.&lt;/P&gt;&lt;P&gt;Thank you for the attention.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Mike&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&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, 22 Aug 2018 06:09:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806100#M48978</guid>
      <dc:creator>Hui_Ma</dc:creator>
      <dc:date>2018-08-22T06:09:51Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally setup FTM Output Compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806101#M48979</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am not updating the MOD register. I am updating only the CnV register. According to table &lt;STRONG&gt;40.4.10.3 CnV Register update&lt;/STRONG&gt;, if CLKS[1:0] ≠ 0:0, and&amp;nbsp; FTMEN = 1 (which is the case here), the CnV register us updated:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;If the selected mode is output compare then CnV register is updated&lt;BR /&gt;according to the SYNCEN bit. If (SYNCEN = 0) then CnV register is updated&lt;BR /&gt;after CnV register was written at the next change of the FTM counter, the&lt;BR /&gt;end of the prescaler counting. If (SYNCEN = 1) then CnV register is updated&lt;BR /&gt;by the C(n)V and C(n+1)V register synchronization.&lt;/LI&gt;&lt;LI&gt;If the selected mode is not output compare and (SYNCEN = 1) then CnV&lt;BR /&gt;register is updated by the C(n)V and C(n+1)V register synchronization.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the FTM configuration I am using:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;const ftm_config_t FTM_0_config = {&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;.prescale = kFTM_Prescale_Divide_1,&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;.bdmMode = kFTM_BdmMode_0,&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;.pwmSyncMode = kFTM_SoftwareTrigger,&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;.reloadPoints = 0,&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;.faultMode = kFTM_Fault_Disable,&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;.faultFilterValue = 0,&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;.deadTimePrescale = kFTM_Deadtime_Prescale_1,&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;.deadTimeValue = 0,&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;.extTriggers = kFTM_InitTrigger,&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;.chnlInitState = 0,&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;.chnlPolarity = 0,&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;.useGlobalTimeBase = false&lt;BR /&gt;};&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By checking the SYNCEN bit of the COMBINE register, I discovered that I'm actually in the second case described above, where the&amp;nbsp;"&lt;SPAN&gt;CnV&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;register is updated by the C(n)V and C(n+1)V register synchronization."&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am using MCUXpresso Config Tools to initialize&amp;nbsp;this FTM module. Am I able disable SYNCEN from there? If I uncheck all "Synchronization methods," the configuration throws an error (see below).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_89.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/67164i312D78FF4CEE868E/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_89.png" alt="pastedImage_89.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'm not actually using FTM_0 for PWM, but the only modes available to me are:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1. Edge-Aligned Modes&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2. Center-Aligned PWM Mode&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3. Quadrature Decoder Mode&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Why is there no "Output Compare" mode selectable?&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Aug 2018 17:16:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806101#M48979</guid>
      <dc:creator>aberger</dc:creator>
      <dc:date>2018-08-22T17:16:50Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally setup FTM Output Compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806102#M48980</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please you provide the FTM register value for double check.&lt;/P&gt;&lt;P&gt;Do you using the K64 chip?&lt;/P&gt;&lt;P&gt;From the MCUXpresso Config tool, the Channel setting provides pin function selection, such as "Output compare":&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/67438i26F24B35E49589A1/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_1.png" alt="pastedImage_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Mike&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&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>Thu, 23 Aug 2018 09:24:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806102#M48980</guid>
      <dc:creator>Hui_Ma</dc:creator>
      <dc:date>2018-08-23T09:24:40Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally setup FTM Output Compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806103#M48981</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think I've found (in principle) a better way to do this, but I am unable to get it to work in practice. I would like to use the "intermediate load" function provided by the PWMLOAD register. The goal is to:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;calculate the Output Compare value, as described above&lt;/LI&gt;&lt;LI&gt;write that value to the C(n)V register buffer&lt;/LI&gt;&lt;LI&gt;on the next wrap around from MOD to CNTIN, load the C(n)V register with the buffered value&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To implement this, I use the following code:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;// 0. enable LDOK to enable loading of C(n)V register with its buffered value&lt;/P&gt;&lt;P&gt;&amp;nbsp;FTM_0_PERIPHERAL-&amp;gt;PWMLOAD |= (1U &amp;lt;&amp;lt; 9);&lt;SPAN&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// 1. calculate the Output Compare value&lt;/P&gt;&lt;P&gt;uint32_t compareValue;&lt;/P&gt;&lt;P&gt;compareValue = (uint32_t)(((float)(UINT32_MAX - DDS.phase)/FTW)*(COUNT_MOD+1)) &amp;amp; COUNT_MOD;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// 2. write the compare value to the C(n)V register buffer and setup the channel for "Set on Match"&lt;/P&gt;&lt;P&gt;uint32_t reg;&lt;/P&gt;&lt;P&gt;reg = FTM_0_PERIPHERAL-&amp;gt;CONTROLS[1].CnSC; &amp;nbsp;// capture the current state of the FTM register&lt;BR /&gt; reg &amp;amp;= ~(0x3C); &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;&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;// clear the MSnB:MSnA and ELSnB:ELSnA&amp;nbsp;bits&lt;BR /&gt; reg |= 0x1C; &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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// setup CnSC for "Set On Match"&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt; FTM_0_PERIPHERAL-&amp;gt;CONTROLS[1].CnSC = reg;&lt;BR /&gt; FTM_0_PERIPHERAL-&amp;gt;CONTROLS[1].CnV = compareValue;&amp;nbsp;&amp;nbsp;&amp;nbsp;// write the compareValue to the CnV buffer&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If SYNCEN = 1 for CH1 (which is the channel I am using here), then the CH1 set always occurs almost&amp;nbsp;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;one full FTM_MOD period after the compareValue is written to the CnV buffer, regardless of the value of compareValue.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;If SYNCEN = 0 for CH1, then it appears that the compareValue is immediately written to the C(n)V register, and not to the buffer using the intermediate load.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;What is the proper setup to FTM module to achieve the goal described above?&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Aug 2018 17:42:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806103#M48981</guid>
      <dc:creator>aberger</dc:creator>
      <dc:date>2018-08-23T17:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally setup FTM Output Compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806104#M48982</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From the above description, there need to make the FTM works in Output Compare mode.&lt;/P&gt;&lt;P&gt;The SDK provided FTM driver has below code to make the FTM works in Output compare mode:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68863iEF35CE045AD54BA5/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_1.png" alt="pastedImage_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;It will clear all the [DECAPEN] &amp;amp; [COMBINE] &amp;amp; [CPWMS] bits setting.&lt;/P&gt;&lt;P&gt;Customer can enable the FTM timer to start output compare mode.&lt;/P&gt;&lt;P&gt;When customer want to change CnV value, customer can call the software sync trigger with SDK provided API function FTM_SetSoftwareTrigger().&lt;/P&gt;&lt;P&gt;I am using below code test FTM output compare CnV register modification.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; BOARD_FTM_BASEADDR-&amp;gt;MOD = 0x2000;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; BOARD_FTM_BASEADDR-&amp;gt;CONTROLS[BOARD_FTM_OUT_CHANNEL].CnV = 0x1000;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Update the buffered registers */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FTM_SetSoftwareTrigger(BOARD_FTM_BASEADDR, true);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FTM_StartTimer(BOARD_FTM_BASEADDR, kFTM_SystemClock);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .............&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Delay one second here&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ............&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; BOARD_FTM_BASEADDR-&amp;gt;MOD = 0x1000;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; BOARD_FTM_BASEADDR-&amp;gt;CONTROLS[BOARD_FTM_OUT_CHANNEL].CnV = 0x800;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Update the buffered registers */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FTM_SetSoftwareTrigger(BOARD_FTM_BASEADDR, true);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/67410i177DEC5F8DF77032/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_1.png" alt="pastedImage_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Wish it helps.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Mike&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&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>Mon, 27 Aug 2018 06:39:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806104#M48982</guid>
      <dc:creator>Hui_Ma</dc:creator>
      <dc:date>2018-08-27T06:39:20Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally setup FTM Output Compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806105#M48983</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mike,&lt;/P&gt;&lt;P&gt;Thanks for your patient explanations.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do you have your FTM SYNCONF set up? I would like to use&amp;nbsp;SWRSTCNT = 0, so that the CnV register is updated&amp;nbsp;at the next loading point (i.e. on overflow) after&amp;nbsp;FTM_SetSoftwareTrigger(BOARD_FTM_BASEADDR, true) is called, and not immediately when the software trigger is set.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Therefore, I am executing the following code:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P style="color: #51626f; border: 0px;"&gt;// set SYNCONF so that the software trigger does not activate the FTM counter synchronization.&lt;/P&gt;&lt;P style="color: #51626f; border: 0px;"&gt;FTM_0_PERIPHERAL-&amp;gt;SYNCONF &amp;amp;= ~(1U &amp;lt;&amp;lt; 8);&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="color: #51626f; border: 0px;"&gt;&lt;/P&gt;&lt;P style="color: #51626f; border: 0px;"&gt;&lt;SPAN&gt;// in the FTM overflow ISR:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="color: #51626f; border: 0px;"&gt;&lt;SPAN&gt;// 1.&amp;nbsp;&lt;/SPAN&gt;calculate the Output Compare value&lt;/P&gt;&lt;P style="color: #51626f; border: 0px;"&gt;uint32_t compareValue;&lt;/P&gt;&lt;P style="color: #51626f; border: 0px;"&gt;compareValue = (uint32_t)(((float)(UINT32_MAX - DDS.phase)/FTW)*(COUNT_MOD+1)) &amp;amp; COUNT_MOD;&lt;/P&gt;&lt;P style="color: #51626f; border: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="color: #51626f; border: 0px;"&gt;// 2. write the compare value to the C(n)V register buffer and setup the channel for "Set on Match"&lt;/P&gt;&lt;P style="color: #51626f; border: 0px;"&gt;&lt;SPAN style="font-family: inherit;"&gt;FTM_SetupOutputCompare(FTM_0_PERIPHERAL, kFTM_Chnl_1, kFTM_SetOnMatch, compareValue); &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="color: #51626f; border: 0px;"&gt;FTM_SetSoftwareTrigger(FTM_0_PERIPHERAL, true);&amp;nbsp;&amp;nbsp;&amp;nbsp;// enable loading of CnV register at next wraparound&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P style="color: #51626f; border: 0px;"&gt;However, this again results in a fixed delay between FTM_SetSoftwareTrigger and the actual SetOnMatch of the FTM0_CH1 output, regardless of the compareValue used for the Output Compare.&lt;/P&gt;&lt;P style="color: #51626f; border: 0px;"&gt;&lt;/P&gt;&lt;P style="color: #51626f; border: 0px;"&gt;For your reference, the FTM SYNCONF register is set to:&amp;nbsp;0x00001eb4&lt;/P&gt;&lt;P style="color: #51626f; border: 0px;"&gt;And the FTM COMBINE register is set to: 0x20202020&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Aug 2018 18:26:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806105#M48983</guid>
      <dc:creator>aberger</dc:creator>
      <dc:date>2018-08-27T18:26:51Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally setup FTM Output Compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806106#M48984</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Andy,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please check below the FTM0_SYNC and FTM0_SYNCONF register value:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/67749i54AF459797A86FED/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_1.png" alt="pastedImage_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The FTM0_COMBINE register value is same with yours.&lt;/P&gt;&lt;P&gt;I tried another setting to use legacy PWM synchronization mode, while get the same result.&lt;/P&gt;&lt;P&gt;Below is the registers value:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_2.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/67828iE17F5EBCA8761903/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_2.png" alt="pastedImage_2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for the attention.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Mike&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&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>Tue, 28 Aug 2018 03:21:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806106#M48984</guid>
      <dc:creator>Hui_Ma</dc:creator>
      <dc:date>2018-08-28T03:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally setup FTM Output Compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806107#M48985</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I do not get the same behavior for the two cases you've shown above (FTM0_SYNCONF =&amp;nbsp;0x00001FB4 and&amp;nbsp;&lt;SPAN&gt;FTM0_SYNCONF =&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;0x00001E34).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For&amp;nbsp;FTM0_SYNCONF =&amp;nbsp;&lt;SPAN&gt;0x00001E34, with SWRSTCNT = 0 and SYNCMODE = 0, I measure the same fixed delay between the start of the FTM ISR and the FTM0_CH1 output set. My FTM_MOD = 4095, such that it is running at 14.648 kHz (a 68.3 µs period). I always measure 65.6 µs between the start of the overflow ISR and the output set (see picture below)&lt;span class="lia-inline-image-display-wrapper" image-alt="OutputCompare_fixedDelay.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/67630iC22447877C3EA867/image-size/large?v=v2&amp;amp;px=999" role="button" title="OutputCompare_fixedDelay.png" alt="OutputCompare_fixedDelay.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If instead,&amp;nbsp;&lt;SPAN&gt;FTM0_SYNCONF =&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;0x00001FB4&lt;SPAN&gt;&amp;nbsp;(&lt;/SPAN&gt;&lt;/SPAN&gt;SWRSTCNT = 1 and&amp;nbsp;SYNCMODE = 1), I get a variable delay between the start of the FTM ISR and the output compare set (which is the desirable behavior, as I'm using a new calculated value for Output Compare each time).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, with this setting (SWRSTCNT = 1), the&amp;nbsp;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;FTM_SetSoftwareTrigger call immediately writes the C(n)V register, and so the CH1 output is set&amp;nbsp;&lt;STRONG&gt;in the same period as the output compare value is calculated. This is not desired.&lt;/STRONG&gt; I would like to write the Output Compare value to the C(n)V buffer, and then have that buffered value loaded into the register at the next FTM overflow. As I understand it, this should be the behavior when SWRSTCNT = 0. However, when I clear that register bit, I get the fixed delay behavior shown in the top picture. Instead, I would like to achieve something like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="OutputCompare_properSequence.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/67699i3190A020B1AED6B6/image-size/large?v=v2&amp;amp;px=999" role="button" title="OutputCompare_properSequence.png" alt="OutputCompare_properSequence.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;From the K64 Reference Manual, it seems that this type of behavior should be achievable either with SWRSTCNT = 0 (see below flow chart).&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_6.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/67751i755F196C4C651E01/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_6.png" alt="pastedImage_6.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Does this flow chart also apply to C(n)V register synchronization? If so, then why, when I have SYNCMODE = 1, SWWRBUF = 1, and SWRSTCNT = 0, is the delay between the FTM ISR (which indicates FTM_CNT = 0) and the Output Compare Set a fixed value (discarding the calculated value for Output Compare)?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Alternatively, it seems that using the PWMLOAD register should also provide the functionality I am looking for, but I have also been unable to make that work (see my reply from August 23).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Aug 2018 17:38:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806107#M48985</guid>
      <dc:creator>aberger</dc:creator>
      <dc:date>2018-08-28T17:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally setup FTM Output Compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806108#M48986</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Andy,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry for the later reply.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From you latest post, the FTM interrupt happen with fixed frequency (&lt;SPAN&gt;14.648 kHz&lt;/SPAN&gt;) is expected (MOD value is fixed).&lt;/P&gt;&lt;P&gt;While, I still have question about your application.&lt;/P&gt;&lt;P&gt;In below picture, you set FTM works in Output compare mode with match set at Interrupt service routine (ISR1). Right?&lt;/P&gt;&lt;P&gt;So, the CnV value also be set at ISR1.&lt;/P&gt;&lt;P&gt;What's the original CnV value before enter into ISR1?&amp;nbsp; (If original CnV value more then MOD?)&lt;/P&gt;&lt;P&gt;If you using the &lt;SPAN&gt;FTM0_SYNCONF =&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;0x00001FB4&lt;SPAN&gt;&amp;nbsp;(&lt;/SPAN&gt;&lt;/SPAN&gt;SWRSTCNT = 1 and&amp;nbsp;SYNCMODE = 1) with software sync trigger.&lt;/P&gt;&lt;P&gt;The &lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;FTM_SetSoftwareTrigger call immediately writes the C(n)V register is expected.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;Base on above behavior, If you could set FTM module working mode (output compare mode) at ISR2? &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;If yes, then you could set the CnV value with required counter number and software trigger SYNC to write CnV register value with (&lt;SPAN&gt;FTM0_SYNCONF =&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;0x00001FB4&lt;SPAN&gt;&amp;nbsp;(&lt;/SPAN&gt;&lt;/SPAN&gt;SWRSTCNT = 1 and&amp;nbsp;SYNCMODE = 1)).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/67797iF4DDBBA960324494/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_1.png" alt="pastedImage_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you for the attention.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Mike&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&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>Fri, 31 Aug 2018 03:04:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806108#M48986</guid>
      <dc:creator>Hui_Ma</dc:creator>
      <dc:date>2018-08-31T03:04:36Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally setup FTM Output Compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806109#M48987</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, the FTM interrup&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;t frequency&lt;/SPAN&gt; is expected to be 14.648 kHz (MOD value is fixed at 4095).&lt;/P&gt;&lt;P&gt;In ISR1, I am:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;calculating the output compare value, &lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;compareValue&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;setting up Output Compare by calling&amp;nbsp;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;FTM_SetupOutputCompare(FTM_0_PERIPHERAL, kFTM_Chnl_1, kFTM_SetOnMatch, compareValue)&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;setting the software trigger by calling&amp;nbsp;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;FTM_SetSoftwareTrigger(FTM_0_PERIPHERAL, true)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As you point out, if&amp;nbsp;&lt;SPAN style="color: #51626f; background-color: #ffffff; border: 0px;"&gt;FTM0_SYNCONF =&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff; border: 0px;"&gt;0x00001FB4&lt;SPAN style="border: 0px; font-weight: inherit;"&gt;&amp;nbsp;(&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;SWRSTCNT = 1 and&amp;nbsp;SYNCMODE = 1), then the above sequence immediately writes the C(n)V register, and the Output Compare also occurs in ISR1. This is almost what I need except that sometimes,&amp;nbsp;by the time step 3 has executed, the output compare value that I calculate is less than the current FTM_CNT value. Therefore, my idea is to always calculate the output compare value in ISR1, but wait to execute the SetOnMatch until the next FTM cycle. On that next FTM cycle, if the C(n)V value is loaded at FTM_CNT = 0, then the SetOnMatch can occur anywhere in the FTM cycle (from FTM_CNT = 0 to 4095), since I don't have to wait for the 3 steps of ISR execution listed above. This is why I would like to use the SWRSTCNT = 0 bit to wait until the next loading point to write the C(n)V register with its buffered value.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;To answer your other question regarding the previous C(n)V value: briefly put, the C(n)V value I calculate is always less than MOD.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;A longer explanation: as I mentioned in the original post, I am trying to use the Output Compare to generate a square wave with 50% duty cycle, whose edges are synchronized to a DDS waveform of arbitrary frequency. Each time the DDS 32-bit phase accumulator wraps from UINT32_MAX to 0, I generate a rising edge. And when the phase accumulator passes from UINT32_MAX/2 to (UINT32_MAX/2+1), I generate a falling edge. (This is the goal anyway). Therefore, when the rising edge Output Compare C(n)V is calculated for a SetOnMatch event (as in the above scope traces), the previous C(n)V value was used for a ClearOnMatch event (falling edge). The C(n)V value is variable for each DDS cycle (since the DDS period is variable, and has no fixed relationship to the FTM frequency of 14.648 kHz), but again, C(n)V is&amp;nbsp;always be less than MOD. In fact the formula I use for the rising and falling edges guarantees it:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;For rising edges:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6; color: #51626f;"&gt;compareValue = (uint32_t)(((float)(UINT32_MAX - DDS.phase)/FTW)*(COUNT_MOD+1)) &amp;amp; COUNT_MOD;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;For falling edges:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6; color: #51626f;"&gt;compareValue = (uint32_t)(((float)(UINT32_HALFMAX - DDS.phase)/FTW)*(COUNT_MOD+1)) &amp;amp; COUNT_MOD;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;where COUNT_MOD = 4095. Because of the final bitwise AND operation at the end of each formula, compareValue is strictly &amp;lt;= 4095.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your continued help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Aug 2018 16:07:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806109#M48987</guid>
      <dc:creator>aberger</dc:creator>
      <dc:date>2018-08-31T16:07:50Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally setup FTM Output Compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806110#M48988</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for the detailed info.&lt;/P&gt;&lt;P&gt;I think the blue signal is generated by software to toggle a GPIO pin when the FTM&amp;nbsp; timer overflow happened (in FTM interrupt).&lt;/P&gt;&lt;P&gt;Why yellow rising edge is before the second blue rising edge?&lt;/P&gt;&lt;P&gt;I think you set the CnV value is quite close to CNTIN value, the FTM counter doesn't stop counting when enter into interrupt service routine. So the output compare channel set before the GPIO toggle.&lt;/P&gt;&lt;P&gt;Have you tried the FTM PWM load function? What's the behavior of that function?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Mike&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&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, 05 Sep 2018 05:21:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806110#M48988</guid>
      <dc:creator>Hui_Ma</dc:creator>
      <dc:date>2018-09-05T05:21:24Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally setup FTM Output Compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806111#M48989</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The questions you have asked are exactly my questions. I don't understand why the yellow rising edge occurs before the second blue rising edge. &lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;As I understand it, when SWRSTCNT = 0, the C(n)V register value is loaded&amp;nbsp;at the next loading point after SWSYNC is set. However, when I use&amp;nbsp;&lt;SPAN&gt;SWRSTCNT = 0, calculate a variable compareValue, and then set SWSYNC, I get&amp;nbsp;&lt;/SPAN&gt;the fixed delay behavior shown&amp;nbsp;(65.6 µs between the start of ISR1 and the yellow rising edge). This doesn't make sense to me. The C(n)V value will be different on each cycle, so generally&amp;nbsp;takes on a random value between CNTIN and MOD, and yet the delay is always 65.6 µs.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;I have tried using PWMLOAD instead of SWRSTCNT. Please see my reply from August 23. Unfortunately, it results in the same behavior as when I use&amp;nbsp;&lt;SPAN&gt;SWRSTCNT = 0. That is, i&lt;/SPAN&gt;&lt;/SPAN&gt;f SYNCEN = 1 for CH1 (which is the channel I am using here), then the CH1 set always occurs almost&amp;nbsp;&lt;SPAN style="background-color: #ffffff; border: 0px; font-weight: inherit;"&gt;one full FTM_MOD period after the compareValue is written to the CnV buffer, regardless of the value of compareValue. And i&lt;/SPAN&gt;&lt;SPAN style="background-color: #ffffff; border: 0px; font-weight: inherit;"&gt;f SYNCEN = 0 for CH1, then the compareValue is immediately written to the C(n)V register, and not to the buffer using the intermediate load.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff; border: 0px; font-weight: inherit;"&gt;Because the blue channel in the scope traces is generated by a software toggle of a GPIO pin, I added another output pin to the FTM module and set it to output a 50% duty cycle PWM signal at the FTM frequency. This provides a hardware-defined reference for where the FTM wrap-around occurs.&amp;nbsp;This makes obvious that&amp;nbsp;the Output Compare (yellow) channel is set when FTM_CNT = CNTIN, even though the Output Compare value is not equal to CNTIN.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="OutputCompare_withPWMreference.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68127i0E7A029BD6E4F961/image-size/large?v=v2&amp;amp;px=999" role="button" title="OutputCompare_withPWMreference.png" alt="OutputCompare_withPWMreference.png" /&gt;&lt;/span&gt;It seems that the compare value used for the Output Compare = 0, even though that is not what is written to the C(n)V buffer in ISR1. Why would that be?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Sep 2018 16:55:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806111#M48989</guid>
      <dc:creator>aberger</dc:creator>
      <dc:date>2018-09-05T16:55:25Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally setup FTM Output Compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806112#M48990</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Andy,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am doing a test with FRDM-K64F board.&lt;/P&gt;&lt;P&gt;I will let you know my test result later.&lt;/P&gt;&lt;P&gt;Thank you for the patience.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Mike&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&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>Thu, 06 Sep 2018 09:24:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806112#M48990</guid>
      <dc:creator>Hui_Ma</dc:creator>
      <dc:date>2018-09-06T09:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally setup FTM Output Compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806113#M48991</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Andy,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did a test with FRDM-K64F board.&lt;/P&gt;&lt;P&gt;The FTM0 refer clock is 60MHz, using FTM0_CH1 pin generate 24KHz Edge-Aligned PWM signal(High-true pulses&lt;BR /&gt;(clear Output on match)) with 50% duty cycle as FTM counter monitor.&lt;/P&gt;&lt;P&gt;The &lt;STRONG&gt;FTM0 MOD value&lt;/STRONG&gt; is fixed to &lt;STRONG style="color: #ff0000;"&gt;0x9C3&lt;/STRONG&gt; (60MHz/24KHz = 2500).&lt;/P&gt;&lt;P&gt;FTM0_CH0 pin as output compare pin will generate square signal with 1.33KHz .&lt;/P&gt;&lt;P&gt;I use a delay() function to emulate modify FTM0_CH0 output compare mode and CnV value periodically.&lt;/P&gt;&lt;P&gt;There is a GPIO pin will toggle after each delay() function to detect/verify the CnV value actual load point.&lt;/P&gt;&lt;P&gt;Below is the overall signals:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68386i0BC96F432A4663AF/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_1.png" alt="pastedImage_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;During FTM0 module initialization, I set the FTM0_CH0 pin output compare value to 0xA00 (more than MOD register value (0x9C3)) with below code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;uint32_t compareValue = &lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;0xA00&lt;/STRONG&gt;&lt;/SPAN&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; /* Setup the output compare mode to toggle output on a match */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FTM_SetupOutputCompare(BOARD_FTM_BASEADDR, BOARD_FTM_OUT_CHANNEL, kFTM_SetOnMatch, compareValue);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FTM_StartTimer(BOARD_FTM_BASEADDR, kFTM_SystemClock);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; GPIO_PortToggle(BOARD_TOGGLE_GPIO, 1u &amp;lt;&amp;lt; BOARD_TOGGLE_GPIO_PIN);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; GPIO_PortToggle(BOARD_TOGGLE_GPIO, 1u &amp;lt;&amp;lt; BOARD_TOGGLE_GPIO_PIN);&lt;/P&gt;&lt;P&gt;Then after delay to set FTM0_CH0 pin CnV value to 0x270 (half of the CH1 PWM high voltage) with below code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; delay();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GPIO_PortToggle(BOARD_TOGGLE_GPIO, 1u &amp;lt;&amp;lt; BOARD_TOGGLE_GPIO_PIN);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GPIO_PortToggle(BOARD_TOGGLE_GPIO, 1u &amp;lt;&amp;lt; BOARD_TOGGLE_GPIO_PIN);&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BOARD_FTM_BASEADDR-&amp;gt;CONTROLS[BOARD_FTM_OUT_CHANNEL].CnV = &lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;0x270&lt;/STRONG&gt;&lt;/SPAN&gt;;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Update the buffered registers */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FTM_SetSoftwareTrigger(BOARD_FTM_BASEADDR, true);&lt;/P&gt;&lt;P&gt;Below is actual signal:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_8.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68598iFBF56F8C8B6EE615/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_8.png" alt="pastedImage_8.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After the first CH0 output compare set match, before set CH0 pin clear on match.&lt;/P&gt;&lt;P&gt;It need to set the CH0 pin with no output signal setting and CnV change back to 0xA00 (more than MOD) with below code.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_16.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68737i73C7D694A16809DE/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_16.png" alt="pastedImage_16.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Then we can set CH0 with clear on match mode and update CnV value to 0x752 (middle of CH1 PWM low voltage):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_17.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68777i531EC6FC1F40CCA6/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_17.png" alt="pastedImage_17.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Below is the actual signal:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_18.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68828i353F5748C620339C/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_18.png" alt="pastedImage_18.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;With the similar code, before next CH0 set on match, it need to set the CH0 pin with no output signal setting and CnV change back to 0xA00 (more than MOD). The actual signal is below:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_19.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68870i3E230DCBD8FA6A26/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_19.png" alt="pastedImage_19.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_20.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68921iB60231B419D17EC5/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_20.png" alt="pastedImage_20.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think you could refer above code at your application FTM interrupt service routine.&lt;/P&gt;&lt;P&gt;My test project is based on MCUXpresso SDK for FRDM-K64F board [output_compare] project with default path:&lt;/P&gt;&lt;P&gt;..\FRDM-K64F\boards\frdmk64f\driver_examples\ftm\output_compare&lt;/P&gt;&lt;P&gt;Please check detailed info with attached source code.&lt;/P&gt;&lt;P&gt;Wish it helps.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Mike&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&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>Fri, 07 Sep 2018 05:29:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806113#M48991</guid>
      <dc:creator>Hui_Ma</dc:creator>
      <dc:date>2018-09-07T05:29:26Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally setup FTM Output Compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806114#M48992</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the instructive example. I've set it up for my TWR-K64 board, to test the outputs and timing. Below is what I found, along with some proposed solutions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Initial test&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_2.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68602i6D668CAB34F063E0/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_2.png" alt="pastedImage_2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Running your code exactly as you attached it produces the above results. How did you generate your figures? Are those measured signals on an oscilloscope, or is it a simulated output? Anyway, there are two major problems with this code:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Setting up the Output Compare with&amp;nbsp;&lt;EM&gt;kFTM_NoOutputSignal&lt;/EM&gt; causes the signal to decay.&lt;/LI&gt;&lt;LI&gt;The FTM_SetSoftwareTrigger() call restarts the FTM counter at 0, so the CH1 period is not consistent if a trigger event occurs during the a given FTM cycle. This is because the FTM module is initialized with SWRSTCNT = 1.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;First fix: don't use &lt;EM&gt;kFTM_NoOutputSignal&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_5.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68742i3AF28C99D2D9429E/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_5.png" alt="pastedImage_5.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;/EM&gt;Instead of using&amp;nbsp;&lt;EM&gt;kFTM_NoOutputSignal&lt;/EM&gt;, I simply set up the Output Compare with whatever state the output is currently in. For example, if the output is in the high state, I call:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;FTM_SetupOutputCompare(BOARD_FTM_BASEADDR, BOARD_FTM_OUT_CHANNEL, &lt;EM&gt;kFTM_SetOnMatch&lt;/EM&gt;, compareValue);&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;And similarly if the output is in the low state, I use&amp;nbsp;&lt;EM&gt;kFTM_ClearOnMatch.&lt;/EM&gt; Since the compareValue is greater than MOD, these commands don't actually cause "set" or "clear" operations, but they do seem to prevent the signal droop shown in&amp;nbsp;the first figure.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'll note that I also found that this extra call to FTM_SetupOutputCompare(), in which a compareValue &amp;gt; MOD is used, is unnecessary. It simply changes the&amp;nbsp;total delay between rising and falling edges out the Output Compare channel (since it involves a couple extra instructions).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Second fix: SWRSTCNT = 0&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The documentation for the SWRSTCNT bit isn't very clear, but&amp;nbsp;according to&amp;nbsp;AN5142 (Features of the FlexTimer Module): "&lt;STRONG&gt;&lt;EM&gt;If the SWRSTCNT bit is set, the FTM counter restarts with FTM_CNTIN register value&lt;/EM&gt;&lt;/STRONG&gt; and the FTM_MOD and FTM_CnV registers are updated immediately. If the SWRSTCNT bit is cleared, the FTM counter continues to count normally and the FTM_MOD and FTM_CnV register update at the next loading point."&lt;/P&gt;&lt;P&gt;This suggests that the initial state of SWRSTCNT = 1 is the issue. As you can see from the first two figures, any time a GPIO toggle occurs, the FTM counter is restarted, and the PWM period is irregular.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_6.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68781iBAD316054C4C5C30/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_6.png" alt="pastedImage_6.png" /&gt;&lt;/span&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Setting SWRSTCNT = 0&amp;nbsp;does fix the periodicity of the FTM0_CH1 PWM output (above). However, it also causes the Output Compare setup to never occur, and so the FTM0_CH0 output remains stuck in a low state.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Third fix: set up loading points at CNTMIN and CNTMAX&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;By default, the FTM is initialized with FTM_SYNC = 0b1000, (or SYNCHOM = 1, REINIT = 0, CNTMAX = 0, and CNTMIN = 0). With SWRSTCNT = 0, the FTM_SetSoftwareTrigger() no longer caused an immediate update of the CnV register, so I had to enable loading points. After setting CNTMIN = 1 and CNTMAX = 1, I found the following behavior:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_9.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68831i29BE3B85BF037E40/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_9.png" alt="pastedImage_9.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;As you can see, the FTM0_CH0 output compare toggle always happens one FTM cycle&amp;nbsp;&lt;EM&gt;after&lt;/EM&gt; the output compare is set up. This is the desired and expected behavior with SWRSTCNT = 0, along with CNTMIN = 1 and CNTMAX = 1. So this all looks great.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;But the issue remains for my DDS project:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;However, I tried to use the same FTM initialization for my DDS code in another project, and I no longer see the desired/expected behavior. As shown below, the SetOnMatch behavior is inconsistent. Sometimes, as in Fig. 1 the SetOnMatch occurs in the same period as FTM_SetupOutputCompare(). And other times, as in Fig. 2, the SetOnMatch occurs in the next FTM cycle (after ISR2).&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_12.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68603i4EF48CB140BDB39D/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_12.png" alt="pastedImage_12.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I don't understand this non-deterministic behavior. As best I can tell, I have the FTM initialized the same way for both projects. That is:&lt;/P&gt;&lt;P&gt;FTM_MODE = 5 (0b101)&lt;/P&gt;&lt;P&gt;FTM_SYNC = 11 (0b1011)&lt;/P&gt;&lt;P&gt;FTM_COMBINE = 538976288 (0b100000001000000010000000100000)&lt;/P&gt;&lt;P&gt;FTM_SYNCONF = 7860 (0b1111010110100)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So again, I'm at an impasse as to why my code is behaving incorrectly.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Sep 2018 00:31:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806114#M48992</guid>
      <dc:creator>aberger</dc:creator>
      <dc:date>2018-09-08T00:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally setup FTM Output Compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806115#M48993</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Andy,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using USB Logic analyzer tool to capture the output signals.&lt;/P&gt;&lt;P&gt;I will continue check your comments next week.&lt;/P&gt;&lt;P&gt;Thank you for the patience.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;best regards,&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Sep 2018 01:44:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806115#M48993</guid>
      <dc:creator>Hui_Ma</dc:creator>
      <dc:date>2018-09-09T01:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally setup FTM Output Compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806116#M48994</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Andy,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Today, I did the test again.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;About the output signal decay behavior, sorry for I am using software logic analyzer tool, I don't find that problem.&lt;/P&gt;&lt;P&gt;As your mentioned fix way, After change the FTM_SetupOutputCompare() function with previous compareMode, the issue was fixed.&lt;/P&gt;&lt;P&gt;Today, I am using scope to measure the signals, the Yellow signal is GPIO toggle, Purple signal is output compare signal, the Green signal is edge aligned PWM. Below is overview scope screen picture:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68402i0A4F765778248000/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_1.png" alt="pastedImage_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Below is the first output compare set (GPIO toggle to output set delta time is about 31us):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_5.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68403i5B3D9E4C11641B09/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_5.png" alt="pastedImage_5.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Below is the second output compare set (delta time is 27us).&lt;/P&gt;&lt;P&gt;You could find there with difference at different times software sync trigger with different delta time.&lt;/P&gt;&lt;P&gt;FTM0 counter is not clear during software sync trigger.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_7.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68451i25B19FF286C18E1A/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_7.png" alt="pastedImage_7.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Below is the first output compare clear(delta time is 50us):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_6.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68404i1E7B3F27B1075A69/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_6.png" alt="pastedImage_6.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Below is the second output compare clear (delta time is 46us), which also shows the FTM0 counter is not clear by software sync trigger.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_8.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68499i581ADB8108FDC88C/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_8.png" alt="pastedImage_8.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then I checked the FTM0_SYNCONF[SWRSTCNT] bit, which is not set as expected.&lt;/P&gt;&lt;P&gt;Please check my application FTM0 whole registers value:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_2.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68452i31CBE00D51BCB53B/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_2.png" alt="pastedImage_2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_3.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68494i63A36AB3A5CC64E4/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_3.png" alt="pastedImage_3.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;From the registers value, it using the Legacy PWM synchronization mode.&lt;/P&gt;&lt;P&gt;Please check your MCUXpresso SDK software for FRDM-K64F board version, I am using V2.4.2&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_4.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68509i976C1BA8D812927C/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_4.png" alt="pastedImage_4.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I couldn't regenerate your mentioned second issue and third issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for the attention.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;best regards,&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Sep 2018 06:00:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806116#M48994</guid>
      <dc:creator>Hui_Ma</dc:creator>
      <dc:date>2018-09-10T06:00:50Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally setup FTM Output Compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806117#M48995</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Andy,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For I was using delay() function to update FTM0 CnV value, there should exist below issue for the software sync trigger time was very close to FTM0 counter overflow. So the output compare set will not set at the next cycle, would be delay to next next cycle. Please check attached signal for the detailed info.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68495iD2E00FE7A98D3039/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_1.png" alt="pastedImage_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_2.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68525iA29765A1C7BCDC2A/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_2.png" alt="pastedImage_2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;If customer set the software sync trigger point not close to FTM counter overflow, this issue doesn't happen.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I mask the below code and found below strange signal, which only happen once with whole captured signals scanning:&lt;/P&gt;&lt;P&gt;BOARD_FTM_BASEADDR-&amp;gt;CONTROLS[BOARD_FTM_OUT_CHANNEL].CnV = 0xA00;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/68627i90FBD2520884A9DE/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_1.png" alt="pastedImage_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;While, If I didn't mask above code, this strange signal never happened from captured siganls.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for the attention.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;best regards,&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Sep 2018 07:08:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806117#M48995</guid>
      <dc:creator>Hui_Ma</dc:creator>
      <dc:date>2018-09-10T07:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally setup FTM Output Compare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806118#M48996</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It makes sense that&amp;nbsp;you did&amp;nbsp;not experience the same issues as I did, because you have initialized SWRSTCNT = 0 and FTM_SYNC = 0xB (which means CNTMAX = 1 and CNTMIN = 1). Therefore, your SetSoftwareTrigger does not cause the FTM counter to restart (since SWRSTCNT = 0), and you do have the max and min loading points enabled.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Therefore, your test code (based on ftm_output_compare.c) is behaving identically to mine. (See the screenshot from the section labeled "Third fix" above).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will need to dig deeper to figure out why my actual project does not replicate this behavior.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Sep 2018 18:00:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Conditionally-setup-FTM-Output-Compare/m-p/806118#M48996</guid>
      <dc:creator>aberger</dc:creator>
      <dc:date>2018-09-10T18:00:56Z</dc:date>
    </item>
  </channel>
</rss>

