<?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 Reading Counter value in LPTMR? in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Reading-Counter-value-in-LPTMR/m-p/772004#M46940</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'm trying to simply read (polling) the timer counter value in the LPTMR on the FRDM KL43Z board.&amp;nbsp; Thought that I'd try that before trying interrupts or anything fancy.&amp;nbsp; Having read through the documentation I'm aware that I have to enable the clock source to the LPTMR and I read that I have to write a bogus value to the CNR register prior to reading it.&amp;nbsp; However, all I seem to get is a 0 value from CNR when I step through the code in debug mode.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm using MCUXpresso 10.1 and trying to use a CMSIS-style approach to accessing the registers.&amp;nbsp; Monitoring the register values as I step through the code, the registers appear to be changing as they are supposed to.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is the code that I'm using.&amp;nbsp; Any hints as to what I might be doing wrong?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;James&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;int main(void) {&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; /* Init board hardware. */&lt;BR /&gt; BOARD_InitBootPins();&lt;BR /&gt; BOARD_InitBootClocks();&lt;BR /&gt; BOARD_InitBootPeripherals();&lt;BR /&gt; /* Init FSL debug console. */&lt;BR /&gt; BOARD_InitDebugConsole();&lt;/P&gt;&lt;P&gt;/* Set up low power timer */&lt;/P&gt;&lt;P&gt;// System Register 5 has the Low Power Timer in it.&lt;BR /&gt; // Enable clock on the lower power timer.&lt;BR /&gt; // Bit 0 is the LPTMR clock gate enable bit. 1 for enable.&lt;BR /&gt; SIM-&amp;gt;SCGC5 |= SIM_SCGC5_LPTMR_MASK; /* enable clock: SIM_SCGC5: LPTMR=1 */&lt;/P&gt;&lt;P&gt;// Disable the Low Power Timer&lt;BR /&gt; LPTMR0-&amp;gt;CSR &amp;amp;= ~LPTMR_CSR_TEN_MASK; // invert and AND.&lt;/P&gt;&lt;P&gt;// CNR overflow reset, Time counter; don't enable yet.&lt;BR /&gt; LPTMR0-&amp;gt;CSR = 0b0000000011001100;&lt;/P&gt;&lt;P&gt;// Prescale: use 8MHz clock; full prescale enabled.&lt;BR /&gt; LPTMR0-&amp;gt;PSR = 0b0000000001111000;&lt;/P&gt;&lt;P&gt;// Last Step... enable timer&lt;BR /&gt; LPTMR0-&amp;gt;CSR |= LPTMR_CSR_TEN_MASK; // Enable the timer via a mask.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; printf("Hello World\n");&lt;/P&gt;&lt;P&gt;/* Force the counter to be placed into memory. */&lt;BR /&gt; volatile static int i = 0 ;&lt;BR /&gt; /* Enter an infinite loop, just incrementing a counter. */&lt;BR /&gt; while(1) {&lt;BR /&gt; // write to the CNR to tell the counter that you want to read it.&lt;BR /&gt; LPTMR0-&amp;gt;CNR = 1u; &lt;BR /&gt; // now read the CNR&lt;BR /&gt; i=LPTMR0-&amp;gt;CNR;&lt;/P&gt;&lt;P&gt;printf("current counter %d\r\n",i);&lt;BR /&gt; }&lt;BR /&gt; return 0 ;&lt;BR /&gt;}&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 24 Feb 2018 02:58:27 GMT</pubDate>
    <dc:creator>drsmith_yorku</dc:creator>
    <dc:date>2018-02-24T02:58:27Z</dc:date>
    <item>
      <title>Reading Counter value in LPTMR?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Reading-Counter-value-in-LPTMR/m-p/772004#M46940</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'm trying to simply read (polling) the timer counter value in the LPTMR on the FRDM KL43Z board.&amp;nbsp; Thought that I'd try that before trying interrupts or anything fancy.&amp;nbsp; Having read through the documentation I'm aware that I have to enable the clock source to the LPTMR and I read that I have to write a bogus value to the CNR register prior to reading it.&amp;nbsp; However, all I seem to get is a 0 value from CNR when I step through the code in debug mode.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm using MCUXpresso 10.1 and trying to use a CMSIS-style approach to accessing the registers.&amp;nbsp; Monitoring the register values as I step through the code, the registers appear to be changing as they are supposed to.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is the code that I'm using.&amp;nbsp; Any hints as to what I might be doing wrong?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;James&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;int main(void) {&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; /* Init board hardware. */&lt;BR /&gt; BOARD_InitBootPins();&lt;BR /&gt; BOARD_InitBootClocks();&lt;BR /&gt; BOARD_InitBootPeripherals();&lt;BR /&gt; /* Init FSL debug console. */&lt;BR /&gt; BOARD_InitDebugConsole();&lt;/P&gt;&lt;P&gt;/* Set up low power timer */&lt;/P&gt;&lt;P&gt;// System Register 5 has the Low Power Timer in it.&lt;BR /&gt; // Enable clock on the lower power timer.&lt;BR /&gt; // Bit 0 is the LPTMR clock gate enable bit. 1 for enable.&lt;BR /&gt; SIM-&amp;gt;SCGC5 |= SIM_SCGC5_LPTMR_MASK; /* enable clock: SIM_SCGC5: LPTMR=1 */&lt;/P&gt;&lt;P&gt;// Disable the Low Power Timer&lt;BR /&gt; LPTMR0-&amp;gt;CSR &amp;amp;= ~LPTMR_CSR_TEN_MASK; // invert and AND.&lt;/P&gt;&lt;P&gt;// CNR overflow reset, Time counter; don't enable yet.&lt;BR /&gt; LPTMR0-&amp;gt;CSR = 0b0000000011001100;&lt;/P&gt;&lt;P&gt;// Prescale: use 8MHz clock; full prescale enabled.&lt;BR /&gt; LPTMR0-&amp;gt;PSR = 0b0000000001111000;&lt;/P&gt;&lt;P&gt;// Last Step... enable timer&lt;BR /&gt; LPTMR0-&amp;gt;CSR |= LPTMR_CSR_TEN_MASK; // Enable the timer via a mask.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; printf("Hello World\n");&lt;/P&gt;&lt;P&gt;/* Force the counter to be placed into memory. */&lt;BR /&gt; volatile static int i = 0 ;&lt;BR /&gt; /* Enter an infinite loop, just incrementing a counter. */&lt;BR /&gt; while(1) {&lt;BR /&gt; // write to the CNR to tell the counter that you want to read it.&lt;BR /&gt; LPTMR0-&amp;gt;CNR = 1u; &lt;BR /&gt; // now read the CNR&lt;BR /&gt; i=LPTMR0-&amp;gt;CNR;&lt;/P&gt;&lt;P&gt;printf("current counter %d\r\n",i);&lt;BR /&gt; }&lt;BR /&gt; return 0 ;&lt;BR /&gt;}&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 24 Feb 2018 02:58:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Reading-Counter-value-in-LPTMR/m-p/772004#M46940</guid>
      <dc:creator>drsmith_yorku</dc:creator>
      <dc:date>2018-02-24T02:58:27Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Counter value in LPTMR?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Reading-Counter-value-in-LPTMR/m-p/772005#M46941</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi James Smith,&lt;/P&gt;&lt;P&gt;&amp;nbsp; I have tested the LPTMR CNR register read in our SDK2.2-FRDM-KL43 LPTMR project, it works OK on my side.&lt;/P&gt;&lt;P&gt;This is the test result:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/18845i5FA6CB2CAA066394/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_1.png" alt="pastedImage_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;You can find, after I add this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t currentCNR = 0U;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LPTMR0-&amp;gt;CNR = 0X11;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; currentCNR = LPTMR0-&amp;gt;CNR;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PRINTF("LPTMR CNR= %X \r\n", currentCNR);&lt;/P&gt;&lt;P&gt;I can find the CNR register is increase in the serial tool.&lt;/P&gt;&lt;P&gt;You also can use the official sample code to test it on your FRDM-KL43.&lt;/P&gt;&lt;P&gt;SDK can be downloaded form this link:&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://mcuxpresso.nxp.com/en/welcome" title="https://mcuxpresso.nxp.com/en/welcome"&gt;Welcome | MCUXpresso SDK Builder&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please use the LPTMR project, folder:SDK_2.2_FRDM-KL43Z\boards\frdmkl43z\driver_examples\lptmr&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;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Kerry&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>Tue, 27 Feb 2018 06:15:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Reading-Counter-value-in-LPTMR/m-p/772005#M46941</guid>
      <dc:creator>kerryzhou</dc:creator>
      <dc:date>2018-02-27T06:15:44Z</dc:date>
    </item>
  </channel>
</rss>

