<?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 FTM Capture not working as expected in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FTM-Capture-not-working-as-expected/m-p/1857957#M66338</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I don't understand why using the system clock in my calculation of&amp;nbsp;CHnFVAL[3:0]&amp;nbsp; doesn't work but using System Clock /2 does. Implemented code provided.&lt;/P&gt;&lt;P&gt;SystemClk = 120MHz; Pre-scaler = divide by 1&lt;/P&gt;&lt;P&gt;Filter:&lt;/P&gt;&lt;P&gt;The signal to be captured by FTM1 Ch0 is Freq_Mon = 1MHz.&lt;BR /&gt;The signal when present has been verified by oscilloscope.&lt;/P&gt;&lt;P&gt;The minimum pulse width to be passed by the filter is:&lt;/P&gt;&lt;P&gt;1/2 Freq_Mon = 500ns.&lt;BR /&gt;&lt;BR /&gt;From the manual [Ref: P972 K24 Sub-Family Reference Manual, Rev. 2, January 2014]&lt;BR /&gt;it states that:&lt;/P&gt;&lt;P&gt;minimum pulse width = CHnFVAL[3:0] x 4 system clocks&lt;/P&gt;&lt;P&gt;4 system clocks = 1/120MHz x 4&lt;BR /&gt;&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; = 8.3ns x 4&lt;BR /&gt;&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; = 33.33ns&lt;/P&gt;&lt;P&gt;so&lt;/P&gt;&lt;P&gt;CHnFVAL[3:0] = 500ns / 33.33ns&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = 15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Stops capturing. Tried 14 and get same result&lt;/P&gt;&lt;P&gt;However:&lt;/P&gt;&lt;P&gt;Setting CHnFVAL[3:0] = 7 passes a pulse of 500ns&lt;BR /&gt;Setting CHnFVAL[3:0] = 8 stops a pulse of 500ns&lt;/P&gt;&lt;P&gt;This infers the system clock is divided by 2. i.e. 60MHz&lt;/P&gt;&lt;P&gt;e.g.&lt;/P&gt;&lt;P&gt;4 system clocks = 1/60MHz x 4&lt;BR /&gt;&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; = 16.67ns x 4&lt;BR /&gt;&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; = 66.67ns&lt;/P&gt;&lt;P&gt;so&lt;/P&gt;&lt;P&gt;CHnFVAL[3:0]&amp;nbsp; &amp;nbsp;= 500ns / 66.67ns&lt;BR /&gt;&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; = 7.5&amp;nbsp; (7) works fine, but I don't understand why?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Implementation: NB: the ISR is started every 500ms by the application code. The ISR disables itself every 2nd rising edge.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;void FTM1_DRV_InputCaptureInit(void)
{
    // Enable clock to the FTM1 module
    SIM_SCGC6 |= SIM_SCGC6_FTM1_MASK;
    
    // Configure pin 64 and its alternate function for FTM1 Ch 0. pin PTA12 (64)    
    PORTA_PCR12 = PORT_PCR_MUX(3);
    
    // Disable write protection for FTM1 registers
    FTM1_MODE |= FTM_MODE_WPDIS_MASK;
    
    // Configure FTM1 as input capture
    FTM1_SC = 0;                        // Ensure FTM1 is disabled for setup
    FTM1_SC &amp;amp;= ~FTM_SC_TOIE_MASK;       // Disable Timer Overflow Interrupt
    FTM1_SC &amp;amp;= ~FTM_SC_TOF_MASK;        // Clear Timer Overflow Event flag
    FTM1_CNTIN = 0;                     // Count reset to 0
    FTM1_MOD = 0xFFFF;                  // Set the modulo register for maximum count

    // The clk source is set to 120MHz by FTM1_DRV_CaptureStart() every 500ms.    
    FTM1_SC &amp;amp;= ~FTM_SC_CLKS(7);         // Select NO clock.
    FTM1_SC |= FTM_SC_PS(0);            // Select prescaler divide by 1.
    
    // Configure FTM1 Channel 0 for input capture on rising edge only
    FTM1_C0SC = FTM_CnSC_ELSA_MASK;     // Capture on rising edge
       
    FTM1_FILTER |= FTM_FILTER_CH0FVAL(7);  // Half the input period
                                           // (120MHz / 4) x FVAL = 500ns 
                                           // FVAL = 500 / 33.33 = 15.
                                           // This value stops the ISR
                                           // (Using 60MHz / 4) x FVAL = 500ns
                                           // FVAL = 500 / 66.67 = 7.5
                                           // Use 7 and runs ok
                                           // Dont know why using the value of
                                           // SYS_CLK doesnt work.
                                           // The frequency set in SC reg is SYS_CLK
                                            
#ifdef DEBUG_CPT
    // Enable CAPTEST mode for FTM1 (simulate input capture events internally)
    FTM1_CONF |= FTM_CONF_CAPTEST_MASK;
#endif

    /* Configure NVIC. Register interrupt into Ram Vector table */
    os_install_int_handler (g_ftmIrqId[HW_FTM1], FTM1_ISR);
    
    NVIC_SetPriority(FTM1_IRQn, 1); // ISR runs every 500ms for ?ns
    
    NVIC_ClearPendingIRQ(g_ftmIrqId[HW_FTM1]);
    
    /* Enable FTM interrupt in NVIC level.*/
    INT_SYS_EnableIRQ(g_ftmIrqId[HW_FTM1]);
    
    // Make sure these are reset at initailization.
    count = 0;
    freq_mon_fault = false;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;oid FTM1_DRV_CaptureStart(void)
{
    //__ITM_EVENT8(1,1);   

    captureStarted = true;              // Used by PIT3 isr handler
    
    // Reset the counter
    FTM1_CNT = 0;
    
    // Start counter
    FTM1_SC   |= FTM_SC_CLKS(1);          // Select Sys clock. 120MHz
    FTM1_SC   |= FTM_SC_PS(0);            // Select prescaler divide by 1
    FTM1_C0SC |= FTM_CnSC_CHIE_MASK;     // Enable channel interrupts
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 01 May 2024 12:12:03 GMT</pubDate>
    <dc:creator>DaveTonyCook</dc:creator>
    <dc:date>2024-05-01T12:12:03Z</dc:date>
    <item>
      <title>FTM Capture not working as expected</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FTM-Capture-not-working-as-expected/m-p/1857957#M66338</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I don't understand why using the system clock in my calculation of&amp;nbsp;CHnFVAL[3:0]&amp;nbsp; doesn't work but using System Clock /2 does. Implemented code provided.&lt;/P&gt;&lt;P&gt;SystemClk = 120MHz; Pre-scaler = divide by 1&lt;/P&gt;&lt;P&gt;Filter:&lt;/P&gt;&lt;P&gt;The signal to be captured by FTM1 Ch0 is Freq_Mon = 1MHz.&lt;BR /&gt;The signal when present has been verified by oscilloscope.&lt;/P&gt;&lt;P&gt;The minimum pulse width to be passed by the filter is:&lt;/P&gt;&lt;P&gt;1/2 Freq_Mon = 500ns.&lt;BR /&gt;&lt;BR /&gt;From the manual [Ref: P972 K24 Sub-Family Reference Manual, Rev. 2, January 2014]&lt;BR /&gt;it states that:&lt;/P&gt;&lt;P&gt;minimum pulse width = CHnFVAL[3:0] x 4 system clocks&lt;/P&gt;&lt;P&gt;4 system clocks = 1/120MHz x 4&lt;BR /&gt;&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; = 8.3ns x 4&lt;BR /&gt;&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; = 33.33ns&lt;/P&gt;&lt;P&gt;so&lt;/P&gt;&lt;P&gt;CHnFVAL[3:0] = 500ns / 33.33ns&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = 15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Stops capturing. Tried 14 and get same result&lt;/P&gt;&lt;P&gt;However:&lt;/P&gt;&lt;P&gt;Setting CHnFVAL[3:0] = 7 passes a pulse of 500ns&lt;BR /&gt;Setting CHnFVAL[3:0] = 8 stops a pulse of 500ns&lt;/P&gt;&lt;P&gt;This infers the system clock is divided by 2. i.e. 60MHz&lt;/P&gt;&lt;P&gt;e.g.&lt;/P&gt;&lt;P&gt;4 system clocks = 1/60MHz x 4&lt;BR /&gt;&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; = 16.67ns x 4&lt;BR /&gt;&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; = 66.67ns&lt;/P&gt;&lt;P&gt;so&lt;/P&gt;&lt;P&gt;CHnFVAL[3:0]&amp;nbsp; &amp;nbsp;= 500ns / 66.67ns&lt;BR /&gt;&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; = 7.5&amp;nbsp; (7) works fine, but I don't understand why?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Implementation: NB: the ISR is started every 500ms by the application code. The ISR disables itself every 2nd rising edge.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;void FTM1_DRV_InputCaptureInit(void)
{
    // Enable clock to the FTM1 module
    SIM_SCGC6 |= SIM_SCGC6_FTM1_MASK;
    
    // Configure pin 64 and its alternate function for FTM1 Ch 0. pin PTA12 (64)    
    PORTA_PCR12 = PORT_PCR_MUX(3);
    
    // Disable write protection for FTM1 registers
    FTM1_MODE |= FTM_MODE_WPDIS_MASK;
    
    // Configure FTM1 as input capture
    FTM1_SC = 0;                        // Ensure FTM1 is disabled for setup
    FTM1_SC &amp;amp;= ~FTM_SC_TOIE_MASK;       // Disable Timer Overflow Interrupt
    FTM1_SC &amp;amp;= ~FTM_SC_TOF_MASK;        // Clear Timer Overflow Event flag
    FTM1_CNTIN = 0;                     // Count reset to 0
    FTM1_MOD = 0xFFFF;                  // Set the modulo register for maximum count

    // The clk source is set to 120MHz by FTM1_DRV_CaptureStart() every 500ms.    
    FTM1_SC &amp;amp;= ~FTM_SC_CLKS(7);         // Select NO clock.
    FTM1_SC |= FTM_SC_PS(0);            // Select prescaler divide by 1.
    
    // Configure FTM1 Channel 0 for input capture on rising edge only
    FTM1_C0SC = FTM_CnSC_ELSA_MASK;     // Capture on rising edge
       
    FTM1_FILTER |= FTM_FILTER_CH0FVAL(7);  // Half the input period
                                           // (120MHz / 4) x FVAL = 500ns 
                                           // FVAL = 500 / 33.33 = 15.
                                           // This value stops the ISR
                                           // (Using 60MHz / 4) x FVAL = 500ns
                                           // FVAL = 500 / 66.67 = 7.5
                                           // Use 7 and runs ok
                                           // Dont know why using the value of
                                           // SYS_CLK doesnt work.
                                           // The frequency set in SC reg is SYS_CLK
                                            
#ifdef DEBUG_CPT
    // Enable CAPTEST mode for FTM1 (simulate input capture events internally)
    FTM1_CONF |= FTM_CONF_CAPTEST_MASK;
#endif

    /* Configure NVIC. Register interrupt into Ram Vector table */
    os_install_int_handler (g_ftmIrqId[HW_FTM1], FTM1_ISR);
    
    NVIC_SetPriority(FTM1_IRQn, 1); // ISR runs every 500ms for ?ns
    
    NVIC_ClearPendingIRQ(g_ftmIrqId[HW_FTM1]);
    
    /* Enable FTM interrupt in NVIC level.*/
    INT_SYS_EnableIRQ(g_ftmIrqId[HW_FTM1]);
    
    // Make sure these are reset at initailization.
    count = 0;
    freq_mon_fault = false;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;oid FTM1_DRV_CaptureStart(void)
{
    //__ITM_EVENT8(1,1);   

    captureStarted = true;              // Used by PIT3 isr handler
    
    // Reset the counter
    FTM1_CNT = 0;
    
    // Start counter
    FTM1_SC   |= FTM_SC_CLKS(1);          // Select Sys clock. 120MHz
    FTM1_SC   |= FTM_SC_PS(0);            // Select prescaler divide by 1
    FTM1_C0SC |= FTM_CnSC_CHIE_MASK;     // Enable channel interrupts
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2024 12:12:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FTM-Capture-not-working-as-expected/m-p/1857957#M66338</guid>
      <dc:creator>DaveTonyCook</dc:creator>
      <dc:date>2024-05-01T12:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: FTM Capture not working as expected</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FTM-Capture-not-working-as-expected/m-p/1859407#M66349</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;First of all, I suppose that capture signal digital filtering uses the system clock, it is not related to the CLKS bits/PS bits in FTMx_SC.&lt;/P&gt;
&lt;P&gt;Regarding the calculation of the digital filtering minimum pulse width = CHnFVAL[3:0] x 4 system clocks, assume the system clock frequency is 120mhz, the capture signal is 1MHz,&lt;/P&gt;
&lt;P&gt;the formula is correct.&lt;/P&gt;
&lt;P&gt;CHnFVAL[3:0] = 500ns / 33.33ns&lt;BR /&gt;= 15 // Stops capturing. Tried 14 and get same result&lt;/P&gt;
&lt;P&gt;Pls check the actual system clock frequency,you can output the flash clock to the CLKOUT pin, then calculate the system clock by checking the SIM_CLKDIV1 reg.&lt;/P&gt;
&lt;P&gt;Hope it can help you&lt;/P&gt;
&lt;P&gt;BR&lt;/P&gt;
&lt;P&gt;XiangJun Rong&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2024 06:12:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FTM-Capture-not-working-as-expected/m-p/1859407#M66349</guid>
      <dc:creator>xiangjun_rong</dc:creator>
      <dc:date>2024-05-06T06:12:07Z</dc:date>
    </item>
    <item>
      <title>Re: FTM Capture not working as expected</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FTM-Capture-not-working-as-expected/m-p/1860465#M66354</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;All CLKOUT pin possibilities are used for other system functions and have already been routed on the PCB making it difficult to isolate a likely candidate. I chose to reassign pin 58 on the 144pin LQFP K24 device from TRACE_CLKOUT to CLKOUT.&lt;/P&gt;&lt;P&gt;Using this pin allows connection of scope to the debug header which is easily accessible on our board. It does however disable the debugger so the status of the SIM_CLKDIV1 reg. must be determined before the pin reassignment.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DaveTonyCook_0-1715077235916.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/277455i7BA6D1040F6D2762/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DaveTonyCook_0-1715077235916.png" alt="DaveTonyCook_0-1715077235916.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;From debugger register view I get:&lt;/P&gt;&lt;P&gt;SIM_CLKDIV1 reg. value = 0x104 i.e. OUTDIV2 = 0x1; OUTDIV4 = 0x4:&lt;/P&gt;&lt;P&gt;OUTDIV4 = 0x4 sets Flash CLK = SysCoreClk / 5&lt;/P&gt;&lt;P&gt;Routing the flash clock to pin 58 as follows:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// Configure pin 58 as CLKOUT
PORTA_PCR6 = PORT_PCR_MUX(5)

// Output flash clock to CLKOUT pin 58
SIM-&amp;gt;SOPT2 |= SIM_SOPT2_CLKOUTSEL(2);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Measure Flash CLK on CLKOUT at pin 58 gives 25MHz as expected&amp;nbsp;&lt;/P&gt;&lt;P&gt;OUTDIV4 = 0x4 sets Flash CLK = SysCoreClk / 5&amp;nbsp;&lt;/P&gt;&lt;P&gt;&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; = 120MHz / 5&lt;/P&gt;&lt;P&gt;&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;= 25MHz by calculation&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This verifies that the System Core Clock is in fact 120MHz so what is causing the problem. Why does setting&amp;nbsp;&lt;SPAN&gt;CHnFVAL[3:0] =&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;15 Stop capturing?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2024 10:29:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FTM-Capture-not-working-as-expected/m-p/1860465#M66354</guid>
      <dc:creator>DaveTonyCook</dc:creator>
      <dc:date>2024-05-07T10:29:15Z</dc:date>
    </item>
  </channel>
</rss>

