<?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: KL24 Input Capture for Duty Cycle in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL24-Input-Capture-for-Duty-Cycle/m-p/461735#M27679</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The 'overhead' of PE-generic-code may be hurting you as well (TU2_GetCaptureValue, plus the entry to YOUR ISR from &lt;SPAN style="text-decoration: underline;"&gt;their&lt;/SPAN&gt; handler).&amp;nbsp; Compiler optimization is also something to keep in mind.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your other option is to run the signal to two timer channels, configured for opposing edges.&amp;nbsp; The 'bigger' Kinetis members have timer-modules with the built-in capability to link two consecutive timer-channels to ONE input for just such use.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 31 Mar 2016 18:59:18 GMT</pubDate>
    <dc:creator>egoodii</dc:creator>
    <dc:date>2016-03-31T18:59:18Z</dc:date>
    <item>
      <title>KL24 Input Capture for Duty Cycle</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL24-Input-Capture-for-Duty-Cycle/m-p/461733#M27677</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Having issues setting up Input Capture to measure a Duty cycle. The pulse I'm trying to capture is ~2uS in length, approximately 28uS between pulses.&amp;nbsp; I've got the TimeUnit_LDD set to a 48mhz counter frequency, Channel 0 capture on both edges with Interrupts enabled with a high priority.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My OnChannel0 ISR routine stores 10 samples and then would calculate&amp;nbsp; the duty cycle from those numbers.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;void TU2_OnChannel0(LDD_TUserData *UserDataPtr)&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;{&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; static uint32_t captureValues[10] = {0};&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; static int captureIndex = 0;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; TU2_GetCaptureValue(TU2_DeviceData, 0, &amp;amp;captureValues[captureIndex]);&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; captureIndex++;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; if(captureIndex == 10){&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // TODO: Calculate duty cycle here&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Duty_Cycle = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Reset the index to start a new measure.&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; captureIndex = 0;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; TU2_ResetCounter(TU2_DeviceData);&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; }&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;}&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P&gt;If I breakpoint in the if(captureIndex ==10) what I end up seeing is my captureValues array being populated with pairs of values like the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[991, 991, 2358, 2358, 3725, 3725, 5092, 5092, 6460, 6460]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The time between the even slotted numbers seems to be equivalent to the 28uS period between rising edges I expect. The odd slots are supposed to correspond to the falling edge 2uS later, but I end up with the same counter value as the preceding even slot.&amp;nbsp; The interrupt appears to be happening twice, as my indexes increment.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Mar 2016 22:02:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL24-Input-Capture-for-Duty-Cycle/m-p/461733#M27677</guid>
      <dc:creator>lucianomoretti</dc:creator>
      <dc:date>2016-03-30T22:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: KL24 Input Capture for Duty Cycle</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL24-Input-Capture-for-Duty-Cycle/m-p/461734#M27678</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Figured it out.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I&amp;nbsp; added a GPIO pin toggle to my ISR and then scoped both signals.&amp;nbsp; Interrupt latency is too high.&amp;nbsp; By the time I get to reading the capture register the trailing edge of my pulse has already happened and set it to the time of the END of the pulse.&amp;nbsp; So I'm reading the end twice in a row.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm going to have to disable interrupts and poll the pin manually.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Mar 2016 14:11:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL24-Input-Capture-for-Duty-Cycle/m-p/461734#M27678</guid>
      <dc:creator>lucianomoretti</dc:creator>
      <dc:date>2016-03-31T14:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: KL24 Input Capture for Duty Cycle</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL24-Input-Capture-for-Duty-Cycle/m-p/461735#M27679</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The 'overhead' of PE-generic-code may be hurting you as well (TU2_GetCaptureValue, plus the entry to YOUR ISR from &lt;SPAN style="text-decoration: underline;"&gt;their&lt;/SPAN&gt; handler).&amp;nbsp; Compiler optimization is also something to keep in mind.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your other option is to run the signal to two timer channels, configured for opposing edges.&amp;nbsp; The 'bigger' Kinetis members have timer-modules with the built-in capability to link two consecutive timer-channels to ONE input for just such use.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Mar 2016 18:59:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL24-Input-Capture-for-Duty-Cycle/m-p/461735#M27679</guid>
      <dc:creator>egoodii</dc:creator>
      <dc:date>2016-03-31T18:59:18Z</dc:date>
    </item>
  </channel>
</rss>

