<?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のトピックK64F LPTMR as pulse counter not working as expected</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/K64F-LPTMR-as-pulse-counter-not-working-as-expected/m-p/423835#M24340</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to implement a pulse counter by using LPTMR0 of MK64FN1M0VLL12 chip. I want to use PTC5 pin for pulse counting. Here is my code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14478536164143775 jive_text_macro" data-renderedposition="113_8_901_512" jivemacro_uid="_14478536164143775" modifiedtitle="true"&gt;&lt;P&gt;//enable clock for PORTC&lt;/P&gt;&lt;P&gt;SIM-&amp;gt;SCGC5 |= (1UL &amp;lt;&amp;lt; 11);&lt;/P&gt;&lt;P&gt;//set PORTC pin 5 as pulse counter pin (PIN ALT3: LPTMR0_ALT2)&lt;/P&gt;&lt;P&gt;PORTC-&amp;gt;PCR[5] = (1UL &amp;lt;&amp;lt; 9) | (1UL &amp;lt;&amp;lt; 8);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//enable clock for LPTMR0&lt;/P&gt;&lt;P&gt;SIM-&amp;gt;SCGC5 |= (1UL &amp;lt;&amp;lt; 0); &lt;/P&gt;&lt;P&gt;// reset LPTMR&lt;/P&gt;&lt;P&gt;LPTMR0-&amp;gt;CSR = 0; &lt;/P&gt;&lt;P&gt;LPTMR0-&amp;gt;PSR = 0;&lt;/P&gt;&lt;P&gt;LPTMR0-&amp;gt;CMR = 0; // no need for compare value because i will use counter in free running mode&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//select LPTMR0_ALT2 (PTC5) as pulse counter pin&lt;/P&gt;&lt;P&gt;LPTMR0-&amp;gt;CSR |= (1 &amp;lt;&amp;lt; 5); &lt;/P&gt;&lt;P&gt;//counter is free running&lt;/P&gt;&lt;P&gt;LPTMR0-&amp;gt;CSR |= (1 &amp;lt;&amp;lt; 2); &lt;/P&gt;&lt;P&gt;//select pulse counter mode&lt;/P&gt;&lt;P&gt;LPTMR0-&amp;gt;CSR |= (1 &amp;lt;&amp;lt; 1);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//pulse counter input pin directly clocks counter value (bypass glitch filter)&lt;/P&gt;&lt;P&gt;LPTMR0-&amp;gt;PSR = (1 &amp;lt;&amp;lt; 2);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//enable LPTMR module&lt;/P&gt;&lt;P&gt;LPTMR0-&amp;gt;CSR |= (1 &amp;lt;&amp;lt; 0);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;while (true) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LPTMR0-&amp;gt;CNR = 1; // write any value first to CNR to read CNR value&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("counter value: %lu\r\n", LPTMR0-&amp;gt;CNR);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wait(1.0f);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am expecting this code to return the current pulse count on pulse pin every second. But if I connect PTC5 to GND (no pulse) the pulse counter starts to increment (16000 after 1 second). My question is why it does behave like this? It should not detect any pulses because it is connected to GND. Also when I connect the pin to +3.3V it does behave like this. Am I missing some point here?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 18 Nov 2015 13:49:22 GMT</pubDate>
    <dc:creator>arminbego</dc:creator>
    <dc:date>2015-11-18T13:49:22Z</dc:date>
    <item>
      <title>K64F LPTMR as pulse counter not working as expected</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/K64F-LPTMR-as-pulse-counter-not-working-as-expected/m-p/423835#M24340</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to implement a pulse counter by using LPTMR0 of MK64FN1M0VLL12 chip. I want to use PTC5 pin for pulse counting. Here is my code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14478536164143775 jive_text_macro" data-renderedposition="113_8_901_512" jivemacro_uid="_14478536164143775" modifiedtitle="true"&gt;&lt;P&gt;//enable clock for PORTC&lt;/P&gt;&lt;P&gt;SIM-&amp;gt;SCGC5 |= (1UL &amp;lt;&amp;lt; 11);&lt;/P&gt;&lt;P&gt;//set PORTC pin 5 as pulse counter pin (PIN ALT3: LPTMR0_ALT2)&lt;/P&gt;&lt;P&gt;PORTC-&amp;gt;PCR[5] = (1UL &amp;lt;&amp;lt; 9) | (1UL &amp;lt;&amp;lt; 8);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//enable clock for LPTMR0&lt;/P&gt;&lt;P&gt;SIM-&amp;gt;SCGC5 |= (1UL &amp;lt;&amp;lt; 0); &lt;/P&gt;&lt;P&gt;// reset LPTMR&lt;/P&gt;&lt;P&gt;LPTMR0-&amp;gt;CSR = 0; &lt;/P&gt;&lt;P&gt;LPTMR0-&amp;gt;PSR = 0;&lt;/P&gt;&lt;P&gt;LPTMR0-&amp;gt;CMR = 0; // no need for compare value because i will use counter in free running mode&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//select LPTMR0_ALT2 (PTC5) as pulse counter pin&lt;/P&gt;&lt;P&gt;LPTMR0-&amp;gt;CSR |= (1 &amp;lt;&amp;lt; 5); &lt;/P&gt;&lt;P&gt;//counter is free running&lt;/P&gt;&lt;P&gt;LPTMR0-&amp;gt;CSR |= (1 &amp;lt;&amp;lt; 2); &lt;/P&gt;&lt;P&gt;//select pulse counter mode&lt;/P&gt;&lt;P&gt;LPTMR0-&amp;gt;CSR |= (1 &amp;lt;&amp;lt; 1);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//pulse counter input pin directly clocks counter value (bypass glitch filter)&lt;/P&gt;&lt;P&gt;LPTMR0-&amp;gt;PSR = (1 &amp;lt;&amp;lt; 2);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//enable LPTMR module&lt;/P&gt;&lt;P&gt;LPTMR0-&amp;gt;CSR |= (1 &amp;lt;&amp;lt; 0);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;while (true) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LPTMR0-&amp;gt;CNR = 1; // write any value first to CNR to read CNR value&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("counter value: %lu\r\n", LPTMR0-&amp;gt;CNR);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wait(1.0f);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am expecting this code to return the current pulse count on pulse pin every second. But if I connect PTC5 to GND (no pulse) the pulse counter starts to increment (16000 after 1 second). My question is why it does behave like this? It should not detect any pulses because it is connected to GND. Also when I connect the pin to +3.3V it does behave like this. Am I missing some point here?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Nov 2015 13:49:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/K64F-LPTMR-as-pulse-counter-not-working-as-expected/m-p/423835#M24340</guid>
      <dc:creator>arminbego</dc:creator>
      <dc:date>2015-11-18T13:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: K64F LPTMR as pulse counter not working as expected</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/K64F-LPTMR-as-pulse-counter-not-working-as-expected/m-p/423836#M24341</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Armin Bego,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I use your code and test it on my TWR-K64, when I connect PTC5 to ground, the out put data is always 0, and never increase, but when I connect PTC5 to a PWM wave, the CNR can be increased. It works ok on my side, I think you should check your ground, whether it has the little pulse?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Beside, I attached my test project, you can use my project(KDS3.0) and run it on your side.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If you still have question, please contact me!&lt;/P&gt;&lt;P&gt;Have a great day,&lt;/P&gt;&lt;P&gt;Jingjing&lt;/P&gt;&lt;P&gt;&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>Thu, 19 Nov 2015 06:56:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/K64F-LPTMR-as-pulse-counter-not-working-as-expected/m-p/423836#M24341</guid>
      <dc:creator>kerryzhou</dc:creator>
      <dc:date>2015-11-19T06:56:07Z</dc:date>
    </item>
    <item>
      <title>Re: K64F LPTMR as pulse counter not working as expected</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/K64F-LPTMR-as-pulse-counter-not-working-as-expected/m-p/423837#M24342</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your effort Jingjing Zhou,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i checked my ground and +3.3V signal. There is no noise. Also I have tried my code on another FRDM-K64 board, it behaves the same. I also tried to compile it with online mbed compiler, no succes.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Nov 2015 14:33:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/K64F-LPTMR-as-pulse-counter-not-working-as-expected/m-p/423837#M24342</guid>
      <dc:creator>arminbego</dc:creator>
      <dc:date>2015-11-19T14:33:53Z</dc:date>
    </item>
    <item>
      <title>Re: K64F LPTMR as pulse counter not working as expected</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/K64F-LPTMR-as-pulse-counter-not-working-as-expected/m-p/423838#M24343</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Armin Bego,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I also test it on our FRDM-K64, it also woks ok, attached is the project for K64, it will printf the result, following is my FRDM-K64 test result:&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;counter value: 1903&lt;/P&gt;&lt;P&gt;counter value: 1951&lt;/P&gt;&lt;P&gt;counter value: 1995&lt;/P&gt;&lt;P&gt;counter value: 2041&lt;/P&gt;&lt;P&gt;counter value: 2086&lt;/P&gt;&lt;P&gt;counter value: 2130&lt;/P&gt;&lt;P&gt;counter value: 2175&lt;/P&gt;&lt;P&gt;counter value: 2220&lt;/P&gt;&lt;P&gt;counter value: 2265&lt;/P&gt;&lt;P&gt;counter value: 2310&lt;/P&gt;&lt;P&gt;counter value: 2355&lt;/P&gt;&lt;P&gt;counter value: 2400&lt;/P&gt;&lt;P&gt;counter value: 2445&lt;/P&gt;&lt;P&gt;counter value: 2494&lt;/P&gt;&lt;P&gt;counter value: 2539&lt;/P&gt;&lt;P&gt;counter value: 2583&lt;/P&gt;&lt;P&gt;counter value: 2623&lt;/P&gt;&lt;P&gt;counter value: 2625&lt;/P&gt;&lt;P&gt;counter value: 2625&lt;/P&gt;&lt;P&gt;counter value: 2625&lt;/P&gt;&lt;P&gt;counter value: 2625&lt;/P&gt;&lt;P&gt;counter value: 2625&lt;/P&gt;&lt;P&gt;counter value: 2625&lt;/P&gt;&lt;P&gt;counter value: 2625&lt;/P&gt;&lt;P&gt;counter value: 2625&lt;/P&gt;&lt;P&gt;counter value: 2625&lt;/P&gt;&lt;P&gt;counter value: 2625&lt;/P&gt;&lt;P&gt;counter value: 2625&lt;/P&gt;&lt;P&gt;counter value: 2625&lt;/P&gt;&lt;P&gt;counter value: 2625&lt;/P&gt;&lt;P&gt;counter value: 2625&lt;/P&gt;&lt;P&gt;counter value: 2625&lt;/P&gt;&lt;P&gt;counter value: 2625&lt;/P&gt;&lt;P&gt;counter value: 2625&lt;/P&gt;&lt;P&gt;counter value: 2625&lt;/P&gt;&lt;P&gt;When I connect it to the PWM, it will increase, if I connect it to the ground, the vaulue will not increase, and stopped in 2625, you can use my project and test it on your FRDM-K64.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Besides, take care, PTC5 is the pin15 in J1, you should make sure you connect the correct pin.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Wish it helps you!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have a great day,&lt;/P&gt;&lt;P&gt;Jingjing&lt;/P&gt;&lt;P&gt;&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, 20 Nov 2015 05:19:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/K64F-LPTMR-as-pulse-counter-not-working-as-expected/m-p/423838#M24343</guid>
      <dc:creator>kerryzhou</dc:creator>
      <dc:date>2015-11-20T05:19:50Z</dc:date>
    </item>
    <item>
      <title>Re: K64F LPTMR as pulse counter not working as expected</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/K64F-LPTMR-as-pulse-counter-not-working-as-expected/m-p/423839#M24344</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your support! Your project compiled and worked well for me too. The problem I had was this line&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="_jivemacro_uid_14483708521105113 jive_macro_code jive_text_macro" data-renderedposition="50_8_901_16" jivemacro_uid="_14483708521105113"&gt;&lt;P&gt;wait(&lt;SPAN class="number"&gt;1.0f);&lt;/SPAN&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The version of mbed library internally manipulates LPTMR0 when using the wait(); function. That was the reason why I was experiencing strange behaviour. With the latest version of mbed it works very well.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Nov 2015 13:15:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/K64F-LPTMR-as-pulse-counter-not-working-as-expected/m-p/423839#M24344</guid>
      <dc:creator>arminbego</dc:creator>
      <dc:date>2015-11-24T13:15:41Z</dc:date>
    </item>
  </channel>
</rss>

