<?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>Kinetis Microcontrollers中的主题 CMP0 to TMP1_CH0 input capture (KL05)</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/CMP0-to-TMP1-CH0-input-capture-KL05/m-p/745432#M45397</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm using KL05 with Processor Expert on KDS 3.2.0.&lt;/P&gt;&lt;P&gt;I need to measure the time between two rising edges without the error caused by interrupt latency.&amp;nbsp; The level must be variable using the DAC and Comparator.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm having trouble capturing pulses using the CMP0 to trigger TPM1, channel 0 capture.&lt;/P&gt;&lt;P&gt;The capture value is not changing (it does infrequently), however the interrupt flag is being set (the CMP0 interrupt is enabled, but not the TPM1 capture interrupt).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In PE, I have TimerUnit_LDD component with Channel 0 set for Capture mode, and the "Capture input pin" is set to "CMP0_output".&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I already found this was missing from PE generated code: (from the reference manual table 3-1, page 44)&lt;/P&gt;&lt;P&gt;SIM_SOPT4 |= SIM_SOPT4_TPM1CH0SRC_MASK; // Enable CMP0 -&amp;gt; capture TPM1CH0&lt;/P&gt;&lt;P&gt;But even after adding that, the result of TPM_PDD_ReadChannelValueReg(TPM1_BASE_PTR, 0) doesn't change after every pulse.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas? Any example programs that do this?&lt;/P&gt;&lt;P&gt;If capture is broken, can I use DMA to achieve period measurement (seems over-complicated)?&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 22 Jan 2018 22:40:34 GMT</pubDate>
    <dc:creator>phatpaul</dc:creator>
    <dc:date>2018-01-22T22:40:34Z</dc:date>
    <item>
      <title>CMP0 to TMP1_CH0 input capture (KL05)</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/CMP0-to-TMP1-CH0-input-capture-KL05/m-p/745432#M45397</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm using KL05 with Processor Expert on KDS 3.2.0.&lt;/P&gt;&lt;P&gt;I need to measure the time between two rising edges without the error caused by interrupt latency.&amp;nbsp; The level must be variable using the DAC and Comparator.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm having trouble capturing pulses using the CMP0 to trigger TPM1, channel 0 capture.&lt;/P&gt;&lt;P&gt;The capture value is not changing (it does infrequently), however the interrupt flag is being set (the CMP0 interrupt is enabled, but not the TPM1 capture interrupt).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In PE, I have TimerUnit_LDD component with Channel 0 set for Capture mode, and the "Capture input pin" is set to "CMP0_output".&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I already found this was missing from PE generated code: (from the reference manual table 3-1, page 44)&lt;/P&gt;&lt;P&gt;SIM_SOPT4 |= SIM_SOPT4_TPM1CH0SRC_MASK; // Enable CMP0 -&amp;gt; capture TPM1CH0&lt;/P&gt;&lt;P&gt;But even after adding that, the result of TPM_PDD_ReadChannelValueReg(TPM1_BASE_PTR, 0) doesn't change after every pulse.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas? Any example programs that do this?&lt;/P&gt;&lt;P&gt;If capture is broken, can I use DMA to achieve period measurement (seems over-complicated)?&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Jan 2018 22:40:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/CMP0-to-TMP1-CH0-input-capture-KL05/m-p/745432#M45397</guid>
      <dc:creator>phatpaul</dc:creator>
      <dc:date>2018-01-22T22:40:34Z</dc:date>
    </item>
    <item>
      <title>Re: CMP0 to TMP1_CH0 input capture (KL05)</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/CMP0-to-TMP1-CH0-input-capture-KL05/m-p/745433#M45398</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I created a bare bones project to demonstrate the issue.&amp;nbsp; In doing so, I think I've found a work-around.&amp;nbsp; I moved the code which reads the captured value into the Cap1_OnCapture ISR (was in the AC1_OnCompare ISR).&amp;nbsp; Now the capture values look great!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So there are potentially two bugs.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;- The module-to-module interconnect SIM_SOPT4_TPM1CH0SRC is not being set by Processor Expert.&lt;/P&gt;&lt;P&gt;&amp;nbsp;- For some reason, it's not reliable to read the capture value from the CMP0 interrupt.&amp;nbsp; The work-around is to read it in the Cap1_OnCapture (a.k.a. TU1_OnChannel0).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'll post the project if anyone is interested.&amp;nbsp; Comment-out the code in the AC1_OnCompare ISR and un-comment the same code in the Cap1_OnCapture ISR to see the working solution.&amp;nbsp; The input is a square wave on pin 26 (CMP0_IN0), and the measured values are dumped out the UART pin 23 (UART0_TX).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Jan 2018 14:50:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/CMP0-to-TMP1-CH0-input-capture-KL05/m-p/745433#M45398</guid>
      <dc:creator>phatpaul</dc:creator>
      <dc:date>2018-01-23T14:50:31Z</dc:date>
    </item>
    <item>
      <title>Re: CMP0 to TMP1_CH0 input capture (KL05)</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/CMP0-to-TMP1-CH0-input-capture-KL05/m-p/745434#M45399</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I thought I had a working solution, but unfortunately it is still unreliable.&lt;/P&gt;&lt;P&gt;It seems that sometimes the TMP1_CH0 interrupt flag is not set (even though I entered the ISR).&amp;nbsp; And sometimes the flag is set but the capture value I read is garbage (or unchanged).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some clues:&lt;/P&gt;&lt;P&gt;It happens most often when TPM1_CH1 is set to compare and it interrupts at the same time as the capture is supposed to happen.&amp;nbsp; Is it possible that TPM1_CH1 compare could corrupt TPM1_CH0 capture?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Jan 2018 20:33:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/CMP0-to-TMP1-CH0-input-capture-KL05/m-p/745434#M45399</guid>
      <dc:creator>phatpaul</dc:creator>
      <dc:date>2018-01-30T20:33:01Z</dc:date>
    </item>
    <item>
      <title>Re: CMP0 to TMP1_CH0 input capture (KL05)</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/CMP0-to-TMP1-CH0-input-capture-KL05/m-p/745435#M45400</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The input capture will happen after the CMP trigger TPM, so you should read capture d value in TPM interrupt. And you can disable the interrupt of CMP if there is no other needs in CMP interrupt.&lt;BR /&gt;I didn't find Cap1_Reset function in your example.(If TPM1 CH1 is used as Output Compare Mode, then the Cap1_Reset will affect the CH1.) If you don't take TPM &lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;overflow&lt;/STRONG&gt;&lt;/SPAN&gt; into account, it would be better two rising edges happens in one TPM MOD period.(See &lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;diff error 1&lt;/STRONG&gt;&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="diff error.jpg"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/34804i5EA79F38088371C9/image-size/large?v=v2&amp;amp;px=999" role="button" title="diff error.jpg" alt="diff error.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Q1: It seems that sometimes the TMP1_CH0 interrupt flag is not set (even though I entered the ISR). &lt;BR /&gt;A1:&amp;nbsp; If you TPM1_CH1 interrupt happen before TPM1_CH0, then Cap1_OnCapture may not be called but still you will enter PE_ISR(TU1_Interrupt) and TU1_OnChannel1.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="cmp02tpmtest.jpg"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/34822iE86AA0E7D7D7EA37/image-size/large?v=v2&amp;amp;px=999" role="button" title="cmp02tpmtest.jpg" alt="cmp02tpmtest.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Q2: And sometimes the flag is set but the capture value I read is garbage (or unchanged).&lt;BR /&gt;A2: If push_debug16 take too much time and the input &lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;captured several times during UART printf&lt;/STRONG&gt;&lt;/SPAN&gt;, then the captured value is the latest one and the diff will not reflect the real time between two rising edges.(See &lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;diff error 2&lt;/STRONG&gt;&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't think the TPM1_CH1 compare could corrupt TPM1_CH0 capture. Maybe you can attached this example here so that I can test it.&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>Fri, 02 Feb 2018 03:04:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/CMP0-to-TMP1-CH0-input-capture-KL05/m-p/745435#M45400</guid>
      <dc:creator>Robin_Shen</dc:creator>
      <dc:date>2018-02-02T03:04:38Z</dc:date>
    </item>
  </channel>
</rss>

