<?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: Problem With Input Capture of K20D50M in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Problem-With-Input-Capture-of-K20D50M/m-p/926529#M53918</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Uma Horse,&lt;/P&gt;&lt;P&gt;I can see you configure FTM1 work as &lt;STRONG&gt;Input Capture mode&lt;/STRONG&gt; and &lt;EM&gt;Capture on Rising Edge Only&lt;/EM&gt; in initialiseFTM1.&lt;BR /&gt;But seems that you need: period = fallIC1Edge - riseIC1Edge;&lt;BR /&gt;Why not direct configure FTM1 work as &lt;STRONG&gt;Dual Edge Capture mode&lt;/STRONG&gt;?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="Dual Edge Capture mode.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/85184i1F10EC0F4A894134/image-size/large?v=v2&amp;amp;px=999" role="button" title="Dual Edge Capture mode.png" alt="Dual Edge Capture mode.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Here you can refer:&lt;BR /&gt;&lt;A _jive_internal="true" href="https://community.nxp.com/thread/430432"&gt;FRDM-K64&amp;amp;#160; FTM measure pulse width&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" href="https://community.nxp.com/thread/466387"&gt;k64F precision pulse width measurement&lt;/A&gt;&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;P style="min- padding: 0px;"&gt;&amp;nbsp;&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, 03 Jun 2019 08:23:00 GMT</pubDate>
    <dc:creator>Robin_Shen</dc:creator>
    <dc:date>2019-06-03T08:23:00Z</dc:date>
    <item>
      <title>Problem With Input Capture of K20D50M</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Problem-With-Input-Capture-of-K20D50M/m-p/926528#M53917</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;I tried to make K20D50M to measure distance using HC-SR04 sensor with FTM, but the result show 0 and it doesn't change when I put the object near and further away from the sensor. I have put the code for reference&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;// Global variable for ISR to save period in&lt;BR /&gt;static volatile uint16_t period;&lt;/P&gt;&lt;P&gt;//Initialise Output Compare for TRIG pin&lt;BR /&gt;void initialiseFTM0(void) {&lt;BR /&gt;// Initialise C.1(Alt4) = FTM0.Ch0, used to drive pin&lt;BR /&gt;SIM_SCGC5 |= SIM_SCGC5_PORTC_MASK;&lt;BR /&gt;PORTC_PCR1 = PORT_PCR_MUX(4)|PORT_PCR_DSE_MASK;&lt;BR /&gt;// Enable clock to FTM&lt;BR /&gt;SIM_SCGC6 |= SIM_SCGC6_FTM0_MASK;&lt;BR /&gt;// Common registers&lt;BR /&gt;FTM0_SC = FTM_SC_CLKS(0);&lt;BR /&gt;FTM0_CNTIN = 0;&lt;BR /&gt;FTM0_CNT = 0;&lt;BR /&gt;FTM0_MOD = 0xFFFF;&lt;BR /&gt;FTM0_SC = FTM_SC_CLKS(1)|FTM_SC_PS(6);&lt;BR /&gt;// Enable FTM0 interrupts in NVIC&lt;BR /&gt;NVIC_EnableIrq(INT_FTM0);&lt;BR /&gt;// Channel register&lt;BR /&gt;FTM0_C0SC = FTM_CnSC_CHIE_MASK|FTM_CnSC_ELSA_MASK|FTM_CnSC_ELSB_MASK|FTM_CnSC_MSA_MASK;&lt;BR /&gt;FTM0_C0V = 0;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;//Initialise Input Capture for ECHO pin&lt;BR /&gt;void initialiseFTM1(void) {&lt;BR /&gt;// Initialise B.1(Alt3) = FTM1.Ch1, used to drive pin&lt;BR /&gt;SIM_SCGC5 |= SIM_SCGC5_PORTB_MASK;&lt;BR /&gt;PORTB_PCR1 = PORT_PCR_MUX(3)|PORT_PCR_DSE_MASK;&lt;BR /&gt;// Enable clock to FTM&lt;BR /&gt;SIM_SCGC6 |= SIM_SCGC6_FTM1_MASK;&lt;BR /&gt;// Common registers&lt;BR /&gt;FTM1_SC = FTM_SC_CLKS(0);&lt;BR /&gt;FTM1_CNTIN = 0;&lt;BR /&gt;FTM1_CNT = 0;&lt;BR /&gt;FTM1_MOD = 0x258;&lt;BR /&gt;FTM1_SC = FTM_SC_CLKS(1)|FTM_SC_PS(0);&lt;BR /&gt;// Enable FTM0 interrupts in NVIC&lt;BR /&gt;NVIC_EnableIrq(INT_FTM1);&lt;BR /&gt;// Channel register&lt;BR /&gt;FTM1_C1SC = FTM_CnSC_CHIE_MASK|FTM_CnSC_ELSA_MASK;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;//Output Compare&lt;BR /&gt;void FTM0_IRQHandler(void) &lt;BR /&gt;{&lt;BR /&gt;// Rising edges on the pin are detected&lt;BR /&gt;if ((FTM0_C0SC &amp;amp; FTM_CnSC_CHF_MASK) != 0) &lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;if ((FTM0_C0SC &amp;amp; FTM_CnSC_ELSA_MASK) != 0) &lt;BR /&gt; {&lt;BR /&gt; FTM0_C0SC = FTM_CnSC_CHIE_MASK|FTM_CnSC_MSA_MASK|FTM_CnSC_ELSB_MASK; //high&lt;BR /&gt; FTM0_C0V = 60;&lt;BR /&gt; }&lt;BR /&gt; else &lt;BR /&gt; {&lt;BR /&gt; FTM0_C0SC = FTM_CnSC_CHIE_MASK|FTM_CnSC_MSA_MASK|FTM_CnSC_ELSA_MASK|FTM_CnSC_ELSB_MASK;// low&lt;BR /&gt; FTM0_C0V = 0;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;if (FTM0_STATUS != 0) &lt;BR /&gt;{&lt;BR /&gt; // Unexpected interrupt - die here for debug&lt;BR /&gt; __asm("bkpt");&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;//Input Capture&lt;BR /&gt;void FTM1_IRQHandler(void) &lt;BR /&gt;{&lt;BR /&gt;static uint16_t riseIC1Edge;&lt;BR /&gt;static uint16_t fallIC1Edge;&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt;// Rising edges on the pin are detected&lt;BR /&gt;if ((FTM1_C1SC &amp;amp; FTM_CnSC_CHF_MASK) != 0) &lt;BR /&gt;{&lt;BR /&gt; if ((FTM1_C1SC &amp;amp; FTM_CnSC_ELSA_MASK) != 0) &lt;BR /&gt; {&lt;BR /&gt; uint16_t valueMin = FTM1_C1V;&lt;BR /&gt; riseIC1Edge = valueMin;&lt;BR /&gt; FTM1_C1SC = FTM_CnSC_CHIE_MASK|FTM_CnSC_ELSB_MASK;&lt;BR /&gt; &lt;BR /&gt; }&lt;BR /&gt; else &lt;BR /&gt; {&lt;BR /&gt; uint16_t valueMax = FTM1_C1V;&lt;BR /&gt; fallIC1Edge = valueMax;&lt;BR /&gt; FTM1_C1SC = FTM_CnSC_CHIE_MASK|FTM_CnSC_ELSA_MASK;&lt;BR /&gt; period = fallIC1Edge - riseIC1Edge;&lt;BR /&gt; }&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt;}&lt;BR /&gt; if (FTM1_STATUS != 0) &lt;BR /&gt; {&lt;BR /&gt; __asm("bkpt");&lt;BR /&gt; }&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void getDistanceCentimeters()&lt;BR /&gt;{&lt;BR /&gt; int distanceCentimeters;&lt;BR /&gt; distanceCentimeters = (period*10^-6)/56;&lt;BR /&gt; printf("Distance = %i cm \n", distanceCentimeters);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;void delay()&lt;BR /&gt;{&lt;BR /&gt; int delayCount;&lt;BR /&gt; for (delayCount = 0;delayCount &amp;lt;1000000;delayCount++)&lt;BR /&gt; {&lt;BR /&gt; __asm("bkpt");&lt;BR /&gt; }&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;int main() {&lt;BR /&gt; clock_initialise();&lt;BR /&gt; initialiseFTM0();&lt;BR /&gt; initialiseFTM1();&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; for(;;)&lt;BR /&gt; {&lt;BR /&gt; getDistanceCentimeters();&lt;BR /&gt; //delay();&lt;BR /&gt; }&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so, is there somthing wrng with my code?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 May 2019 08:46:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Problem-With-Input-Capture-of-K20D50M/m-p/926528#M53917</guid>
      <dc:creator>seahorse333</dc:creator>
      <dc:date>2019-05-30T08:46:19Z</dc:date>
    </item>
    <item>
      <title>Re: Problem With Input Capture of K20D50M</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Problem-With-Input-Capture-of-K20D50M/m-p/926529#M53918</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Uma Horse,&lt;/P&gt;&lt;P&gt;I can see you configure FTM1 work as &lt;STRONG&gt;Input Capture mode&lt;/STRONG&gt; and &lt;EM&gt;Capture on Rising Edge Only&lt;/EM&gt; in initialiseFTM1.&lt;BR /&gt;But seems that you need: period = fallIC1Edge - riseIC1Edge;&lt;BR /&gt;Why not direct configure FTM1 work as &lt;STRONG&gt;Dual Edge Capture mode&lt;/STRONG&gt;?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="Dual Edge Capture mode.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/85184i1F10EC0F4A894134/image-size/large?v=v2&amp;amp;px=999" role="button" title="Dual Edge Capture mode.png" alt="Dual Edge Capture mode.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Here you can refer:&lt;BR /&gt;&lt;A _jive_internal="true" href="https://community.nxp.com/thread/430432"&gt;FRDM-K64&amp;amp;#160; FTM measure pulse width&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" href="https://community.nxp.com/thread/466387"&gt;k64F precision pulse width measurement&lt;/A&gt;&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;P style="min- padding: 0px;"&gt;&amp;nbsp;&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, 03 Jun 2019 08:23:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Problem-With-Input-Capture-of-K20D50M/m-p/926529#M53918</guid>
      <dc:creator>Robin_Shen</dc:creator>
      <dc:date>2019-06-03T08:23:00Z</dc:date>
    </item>
  </channel>
</rss>

