<?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: FRDM-K64  FTM measure pulse width in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K64-160-FTM-measure-pulse-width/m-p/576285#M34243</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, that code doesn't take into account the case of FTMx_CNT overflow.&lt;/P&gt;&lt;P&gt;So if you want that code get the correct result, you need ensure FTMx_CNT doesn't overflow.(FTMx_CNT period &amp;gt; PWM period)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="measure pulse width.jpg"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/37360iC98BA4B8E3265EAF/image-size/large?v=v2&amp;amp;px=999" role="button" title="measure pulse width.jpg" alt="measure pulse width.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;You can increase the overflow period of FTMx_CNT by setup "ftmInfo.prescale".&lt;/P&gt;&lt;P&gt;If kFTM_Prescale_Divide_1, then pulseWidth = ((capture2Val - capture1Val) + 1) / (FTM_SOURCE_CLOCK / 1000000);&lt;/P&gt;&lt;P&gt;If kFTM_Prescale_Divide_128, then&amp;nbsp; pulseWidth = 128*((capture2Val - capture1Val) + 1) / (FTM_SOURCE_CLOCK / 1000000);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Robin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 21 Jul 2016 09:34:29 GMT</pubDate>
    <dc:creator>Robin_Shen</dc:creator>
    <dc:date>2016-07-21T09:34:29Z</dc:date>
    <item>
      <title>FRDM-K64  FTM measure pulse width</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K64-160-FTM-measure-pulse-width/m-p/576281#M34239</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;I am trying to measure the percentage of a PWM signa&lt;/SPAN&gt;&lt;SPAN style="color: #51626f; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;l on a FRDM-K64 board. I am using the FTM2 FlexTimer in dual edge capture mode on channels 0-1. &lt;SPAN&gt; I'm getting the interrupts both for the rising and falling edge of the pulses&lt;/SPAN&gt;.But after entering the interrupt function, simply enter a rising edge of a subroutine, but there is no falling entered a subroutine, why is there such a situation&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;code:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="plain" name="code"&gt;#include "board.h" #include "fsl_debug_console.h" #include "pin_mux.h" #include "clock_config.h" #include "fsl_ftm.h" /*******************************************************************************&amp;nbsp; * Definitions&amp;nbsp; ******************************************************************************/ /* The Flextimer instance/channel used for board */ #define DEMO_FTM_BASEADDR FTM2&amp;nbsp;&amp;nbsp; /* FTM channel pair used for the dual-edge capture, channel pair 0 uses channels 0 and 1 */ #define BOARD_FTM_INPUT_CAPTURE_CHANNEL_PAIR kFTM_Chnl_0&amp;nbsp;&amp;nbsp; /* Interrupt number and interrupt handler for the FTM instance used */ #define FTM_INTERRUPT_NUMBER FTM2_IRQn #define FTM_INPUT_CAPTURE_HANDLER FTM2_IRQHandler&amp;nbsp;&amp;nbsp; /* Interrupt to enable and flag to read; depends on the FTM channel used for dual-edge capture */ #define FTM_CHANNEL0_INTERRUPT_ENABLE kFTM_Chnl0InterruptEnable&amp;nbsp;&amp;nbsp; #define FTM_CHANNEL1_INTERRUPT_ENABLE kFTM_Chnl1InterruptEnable&amp;nbsp;&amp;nbsp; #define FTM_CHANNEL0_FLAG kFTM_Chnl0Flag #define FTM_CHANNEL1_FLAG kFTM_Chnl1Flag&amp;nbsp;&amp;nbsp; /* Get source clock for FTM driver */ #define FTM_SOURCE_CLOCK CLOCK_GetFreq(kCLOCK_BusClk)&amp;nbsp;&amp;nbsp; /*******************************************************************************&amp;nbsp; * Prototypes&amp;nbsp; ******************************************************************************/&amp;nbsp;&amp;nbsp; /*******************************************************************************&amp;nbsp; * Variables&amp;nbsp; ******************************************************************************/ volatile bool ftmIsrFlag = false; /*******************************************************************************&amp;nbsp; * Code&amp;nbsp; ******************************************************************************/ void FTM_INPUT_CAPTURE_HANDLER(void) { &amp;nbsp;&amp;nbsp;&amp;nbsp; if ((FTM_GetStatusFlags(DEMO_FTM_BASEADDR) &amp;amp; FTM_CHANNEL0_FLAG) == FTM_CHANNEL0_FLAG) &amp;nbsp;&amp;nbsp;&amp;nbsp; { &amp;nbsp;&amp;nbsp;&amp;nbsp; PRINTF("\r\n/**********************rasing interrupt****************************\n"); &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FTM_ClearStatusFlags(DEMO_FTM_BASEADDR, FTM_CHANNEL0_FLAG); &amp;nbsp;&amp;nbsp;&amp;nbsp; } &amp;nbsp;&amp;nbsp;&amp;nbsp; if ((FTM_GetStatusFlags(DEMO_FTM_BASEADDR) &amp;amp; FTM_CHANNEL1_FLAG) == FTM_CHANNEL1_FLAG) &amp;nbsp; { &amp;nbsp; PRINTF("\r\n/**********************falling interrupt****************************\n"); &amp;nbsp; FTM_ClearStatusFlags(DEMO_FTM_BASEADDR, FTM_CHANNEL1_FLAG); &amp;nbsp; } }&amp;nbsp;&amp;nbsp; /*!&amp;nbsp; * @brief Main function&amp;nbsp; */ int main(void) { &amp;nbsp;&amp;nbsp;&amp;nbsp; ftm_config_t ftmInfo; &amp;nbsp;&amp;nbsp;&amp;nbsp; ftm_dual_edge_capture_param_t edgeParam; &amp;nbsp;&amp;nbsp;&amp;nbsp; /* Board pin, clock, debug console init */ &amp;nbsp;&amp;nbsp;&amp;nbsp; BOARD_InitPins(); &amp;nbsp;&amp;nbsp;&amp;nbsp; BOARD_BootClockRUN(); &amp;nbsp;&amp;nbsp;&amp;nbsp; BOARD_InitDebugConsole();&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; /* Print a note to terminal */ &amp;nbsp;&amp;nbsp;&amp;nbsp; PRINTF("\r\nFTM dual-edge capture example\r\n"); &amp;nbsp;&amp;nbsp;&amp;nbsp; PRINTF("\r\nSYSTEM Clock:%d\r\n",CLOCK_GetFreq(kCLOCK_CoreSysClk)); &amp;nbsp;&amp;nbsp;&amp;nbsp; PRINTF("\r\nBUS Clock:%d\r\n",CLOCK_GetFreq(kCLOCK_BusClk));&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; FTM_GetDefaultConfig(&amp;amp;ftmInfo); &amp;nbsp;&amp;nbsp;&amp;nbsp; ftmInfo.prescale = kFTM_Prescale_Divide_128; &amp;nbsp;&amp;nbsp;&amp;nbsp; /* Initialize FTM module */ &amp;nbsp;&amp;nbsp;&amp;nbsp; FTM_Init(DEMO_FTM_BASEADDR, &amp;amp;ftmInfo);&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; edgeParam.mode = kFTM_Continuous; &amp;nbsp;&amp;nbsp;&amp;nbsp; //Set capture edges to calculate the pulse width of input signal &amp;nbsp;&amp;nbsp;&amp;nbsp; edgeParam.currChanEdgeMode = kFTM_RisingEdge; &amp;nbsp;&amp;nbsp;&amp;nbsp; edgeParam.nextChanEdgeMode = kFTM_FallingEdge;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; /* Setup dual-edge capture on a FTM channel pair */ &amp;nbsp;&amp;nbsp;&amp;nbsp; FTM_SetupDualEdgeCapture(DEMO_FTM_BASEADDR, BOARD_FTM_INPUT_CAPTURE_CHANNEL_PAIR, &amp;amp;edgeParam, 0);&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; /* Set the timer to be in free-running mode */ &amp;nbsp;&amp;nbsp;&amp;nbsp; DEMO_FTM_BASEADDR-&amp;gt;MOD = 0xffff; &amp;nbsp;&amp;nbsp;&amp;nbsp; /* Enable channel interrupt when the second edge is detected */ &amp;nbsp;&amp;nbsp;&amp;nbsp; FTM_EnableInterrupts(DEMO_FTM_BASEADDR, FTM_CHANNEL0_INTERRUPT_ENABLE); &amp;nbsp;&amp;nbsp;&amp;nbsp; FTM_EnableInterrupts(DEMO_FTM_BASEADDR, FTM_CHANNEL1_INTERRUPT_ENABLE); &amp;nbsp;&amp;nbsp;&amp;nbsp; /* Enable at the NVIC */ &amp;nbsp;&amp;nbsp;&amp;nbsp; EnableIRQ(FTM_INTERRUPT_NUMBER);&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; FTM_StartTimer(DEMO_FTM_BASEADDR, kFTM_SystemClock);&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; while (1) &amp;nbsp;&amp;nbsp;&amp;nbsp; { &amp;nbsp;&amp;nbsp;&amp;nbsp; ; &amp;nbsp;&amp;nbsp;&amp;nbsp; } }&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;P&gt;&lt;STRONG&gt;Original Attachment has been moved to: &lt;A _jive_internal="true" href="https://community.nxp.com/docs/DOC-337665" rel="nofollow noopener noreferrer" target="_blank"&gt;main.c.zip&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jul 2016 09:37:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K64-160-FTM-measure-pulse-width/m-p/576281#M34239</guid>
      <dc:creator>yuanhanchen</dc:creator>
      <dc:date>2016-07-15T09:37:14Z</dc:date>
    </item>
    <item>
      <title>Re: FRDM-K64  FTM measure pulse width</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K64-160-FTM-measure-pulse-width/m-p/576282#M34240</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi yuanhan,&lt;/P&gt;&lt;P&gt;If you want measure pulse width, please refer the code in attached file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Robin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jul 2016 09:28:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K64-160-FTM-measure-pulse-width/m-p/576282#M34240</guid>
      <dc:creator>Robin_Shen</dc:creator>
      <dc:date>2016-07-19T09:28:40Z</dc:date>
    </item>
    <item>
      <title>Re: FRDM-K64  FTM measure pulse width</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K64-160-FTM-measure-pulse-width/m-p/576283#M34241</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rbin_Shen,&lt;/P&gt;&lt;P&gt;Thank for your help,I've looked at your code, I also had a look at this example, the code for this but there is a problem, this code does not take into account the case of overflow interrupt, and overflow interrupt calculated according to the desired value in the first interval along the overflow interrupt flag is set to 0, so it is necessary in the first direction to generate an interrupt, but I list the code shows: generate interrupt flag is wrong, but why is wrong. Can you help me?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jul 2016 09:42:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K64-160-FTM-measure-pulse-width/m-p/576283#M34241</guid>
      <dc:creator>yuanhanchen</dc:creator>
      <dc:date>2016-07-19T09:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: FRDM-K64  FTM measure pulse width</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K64-160-FTM-measure-pulse-width/m-p/576284#M34242</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;IF that 'ftm_dual_edge_capture' demo code had defined capture1Val and capture2Val as uint16_t, (and only allowed the promotion to 32-bit math in the '+1' operation)&amp;nbsp; then the 'natural' 16-bit-integer math would preclude any requirement to worry about 'overflow' as long as the overall pulse width to measure is less than one full FTM cycle.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jul 2016 18:57:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K64-160-FTM-measure-pulse-width/m-p/576284#M34242</guid>
      <dc:creator>egoodii</dc:creator>
      <dc:date>2016-07-19T18:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: FRDM-K64  FTM measure pulse width</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K64-160-FTM-measure-pulse-width/m-p/576285#M34243</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, that code doesn't take into account the case of FTMx_CNT overflow.&lt;/P&gt;&lt;P&gt;So if you want that code get the correct result, you need ensure FTMx_CNT doesn't overflow.(FTMx_CNT period &amp;gt; PWM period)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="measure pulse width.jpg"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/37360iC98BA4B8E3265EAF/image-size/large?v=v2&amp;amp;px=999" role="button" title="measure pulse width.jpg" alt="measure pulse width.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;You can increase the overflow period of FTMx_CNT by setup "ftmInfo.prescale".&lt;/P&gt;&lt;P&gt;If kFTM_Prescale_Divide_1, then pulseWidth = ((capture2Val - capture1Val) + 1) / (FTM_SOURCE_CLOCK / 1000000);&lt;/P&gt;&lt;P&gt;If kFTM_Prescale_Divide_128, then&amp;nbsp; pulseWidth = 128*((capture2Val - capture1Val) + 1) / (FTM_SOURCE_CLOCK / 1000000);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Robin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Jul 2016 09:34:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K64-160-FTM-measure-pulse-width/m-p/576285#M34243</guid>
      <dc:creator>Robin_Shen</dc:creator>
      <dc:date>2016-07-21T09:34:29Z</dc:date>
    </item>
    <item>
      <title>Re: FRDM-K64  FTM measure pulse width</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K64-160-FTM-measure-pulse-width/m-p/576286#M34244</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes -- as long as capture1Val and capture2Val are declared as 16-bit unsigned, and FTMxCNT is 0xFFFF (full 65536 counts)., and then you CAN IGNORE OVERFLOW.&amp;nbsp; For THEN a pulse (not clear if user is looking for 'high time', 'low time', or 'full pulse time') that happens to fall across an 'overflow time point' will get the proper mathematical result:&amp;nbsp; For example, 1 - 0xFFFF in 16 bit math is a proper 2, in 32bit it is 0xFFFF0002.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Jul 2016 12:37:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K64-160-FTM-measure-pulse-width/m-p/576286#M34244</guid>
      <dc:creator>egoodii</dc:creator>
      <dc:date>2016-07-21T12:37:47Z</dc:date>
    </item>
    <item>
      <title>Re: FRDM-K64  FTM measure pulse width</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K64-160-FTM-measure-pulse-width/m-p/576287#M34245</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, &lt;SPAN style="font-weight: bold; font-size: 12.600000381469727px; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #51626f;"&gt;&lt;A _jive_internal="true" data-avatarid="-1" data-content-finding="Community" data-userid="19946" data-username="egoodii" href="https://community.nxp.com/people/egoodii" style="padding: 0 3px 0 0; font-weight: inherit; font-style: inherit; font-size: 1.1em; font-family: inherit; color: #017bba; text-decoration: underline;"&gt;EARL GOODRICH&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Thank you for your answer, your answer was helpful。&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Jul 2016 07:22:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K64-160-FTM-measure-pulse-width/m-p/576287#M34245</guid>
      <dc:creator>yuanhanchen</dc:creator>
      <dc:date>2016-07-22T07:22:19Z</dc:date>
    </item>
    <item>
      <title>Re: FRDM-K64  FTM measure pulse width</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K64-160-FTM-measure-pulse-width/m-p/576288#M34246</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-weight: bold; font-size: 12.600000381469727px; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #51626f;"&gt;Hi,&lt;A _jive_internal="true" data-avatarid="-1" data-userid="213933" data-username="Robin_Shen" href="https://community.nxp.com/people/Robin_Shen" style="padding: 0 3px 0 0; font-weight: inherit; font-style: inherit; font-size: 1.1em; font-family: inherit; color: #017bba;"&gt;Robin_Shen&lt;/A&gt;​&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Thank you for your answer, your answer was very helpful。&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Jul 2016 07:24:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K64-160-FTM-measure-pulse-width/m-p/576288#M34246</guid>
      <dc:creator>yuanhanchen</dc:creator>
      <dc:date>2016-07-22T07:24:47Z</dc:date>
    </item>
  </channel>
</rss>

