<?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>LPC MicrocontrollersのトピックRe: Problem with Timer0 in LPC1769</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/Problem-with-Timer0-in-LPC1769/m-p/725868#M29341</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Timer clock frequency is definitely correct. I think sufficient evidence for that is that I get interrupt on whatever period I like by writing appropriate value to MR3, e.g. I assign MR3=CLOCK*4567-1 and get interrupt every 4567us precisely, but I want to get interrupt on match with MR0, which I assign a smaller value, e.g. MR0=CLOCK*2500-1, and I configure MCR accordingly, i.e.&amp;nbsp; MCR = (1&amp;lt;&amp;lt;0) | (1&amp;lt;&amp;lt;10).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I might give my all timer initialization routine [I do not use lpcopen]:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void Timer0_Init(void) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;PCONP |= (1&amp;lt;&amp;lt;1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;PCLKSEL0 = (PCLKSEL0&amp;amp;(~(3&amp;lt;&amp;lt;2))) | (1&amp;lt;&amp;lt;2); //pclk=cclk&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;T0TCR = 2; //counters disabled and reset&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;T0CTCR = 0; //timer mode&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;T0PR = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;T0MR0 = CLOCK*500-1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;T0MR3 = CLOCK*1000-1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;T0MCR = (1&amp;lt;&amp;lt;0) | (1&amp;lt;&amp;lt;10); //interrupt on MR0, reset on MR3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;IPR0 = (IPR0&amp;amp;(~(0x1f&amp;lt;&amp;lt;11))) | (1&amp;lt;&amp;lt;11); //interrupt priority&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ISER0 = (1&amp;lt;&amp;lt;1); //interrupt enable&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;T0TCR = 1; //counters enabled&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A few notes also:&lt;/P&gt;&lt;P&gt;- I tried to change Timer0 to Timer1 and get the same results;&lt;/P&gt;&lt;P&gt;- T0IR indicates that the interrupt source is MR0, although interrupt happens on the period according to MR3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a hypothesis that interrupt is asserted only when T0TC is reset to zero and I might think of a few tests that would confirm that, but I'm not sure I will do them, because I achieved my goal with other means than with such a usage of Timer as I described and I have to move forward. I wrote here with the expectation that this is a universal error and that someone would duplicate it and get the same result.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 06 Mar 2018 11:11:48 GMT</pubDate>
    <dc:creator>vycska</dc:creator>
    <dc:date>2018-03-06T11:11:48Z</dc:date>
    <item>
      <title>Problem with Timer0 in LPC1769</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Problem-with-Timer0-in-LPC1769/m-p/725866#M29339</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I configure MR0 = CLOCK*500-1 and MR3 = CLOCK*1000-1 [CLOCK is the cpu frequency in MHz, which in my case is 100]. PR=0. Thus, MR0 corresponds to 0.5ms and MR3 to 1ms, that is the time until match.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I then configure MCR to interrupt on MR0 and to reset counter on MR3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I should get an interrupt periodically every 0.5ms because of MR0, BUT I get interrupt every 1 ms [precisely; I can vary MR0 and MR3 values, but interrupt always happens on the period according to the MR3 value]. What might be explanation of such behavior?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Mar 2018 13:22:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Problem-with-Timer0-in-LPC1769/m-p/725866#M29339</guid>
      <dc:creator>vycska</dc:creator>
      <dc:date>2018-03-02T13:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Timer0 in LPC1769</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Problem-with-Timer0-in-LPC1769/m-p/725867#M29340</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Vytautas C.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; At first, you must make sure your Timer frequency is correct.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Do you test the official lpcopen code for LPC1769, which you can find it from this link:&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://www.nxp.com/support/developer-resources/software-development-tools/lpc-developer-resources-/lpcopen-libraries-and-examples/lpcopen-software-development-platform-lpc17xx:LPCOPEN-SOFTWARE-FOR-LPC17XX" rel="nofollow noopener noreferrer" title="https://www.nxp.com/support/developer-resources/software-development-tools/lpc-developer-resources-/lpcopen-libraries-and-examples/lpcopen-software-development-platform-lpc17xx:LPCOPEN-SOFTWARE-FOR-LPC17XX" target="_blank"&gt;LPCOpen Software for LPC17XX|NXP&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="language-c line-numbers"&gt;&lt;CODE&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class="token function"&gt;SystemCoreClockUpdate&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class="token function"&gt;Board_Init&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class="comment token"&gt;/* Enable timer 1 clock */&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class="token function"&gt;Chip_TIMER_Init&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;LPC_TIMER0&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class="comment token"&gt;/* Timer rate is system clock rate */&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;timerFreq &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;Chip_Clock_GetSystemClockRate&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class="comment token"&gt;/* Timer setup for match and interrupt at TICKRATE_HZ */&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class="token function"&gt;Chip_TIMER_Reset&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;LPC_TIMER0&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class="token function"&gt;Chip_TIMER_MatchEnableInt&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;LPC_TIMER0&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class="token function"&gt;Chip_TIMER_SetMatch&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;LPC_TIMER0&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;timerFreq &lt;SPAN class="operator token"&gt;/&lt;/SPAN&gt; TICKRATE_HZ1&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class="token function"&gt;Chip_TIMER_ResetOnMatchEnable&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;LPC_TIMER0&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class="token function"&gt;Chip_TIMER_Enable&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;LPC_TIMER0&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class="comment token"&gt;/* Enable timer interrupt */&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class="token function"&gt;NVIC_ClearPendingIRQ&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;TIMER0_IRQn&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class="token function"&gt;NVIC_EnableIRQ&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;TIMER0_IRQn&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The match value is timerFreq / TICKRATE_HZ1. timerFreq = Chip_Clock_GetSystemClockRate();&lt;/P&gt;&lt;P&gt;Please check the lpcopen code on your side again.&lt;/P&gt;&lt;P&gt;If you still have question about it, please kindly let me know!&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>Mon, 05 Mar 2018 09:18:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Problem-with-Timer0-in-LPC1769/m-p/725867#M29340</guid>
      <dc:creator>kerryzhou</dc:creator>
      <dc:date>2018-03-05T09:18:20Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Timer0 in LPC1769</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Problem-with-Timer0-in-LPC1769/m-p/725868#M29341</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Timer clock frequency is definitely correct. I think sufficient evidence for that is that I get interrupt on whatever period I like by writing appropriate value to MR3, e.g. I assign MR3=CLOCK*4567-1 and get interrupt every 4567us precisely, but I want to get interrupt on match with MR0, which I assign a smaller value, e.g. MR0=CLOCK*2500-1, and I configure MCR accordingly, i.e.&amp;nbsp; MCR = (1&amp;lt;&amp;lt;0) | (1&amp;lt;&amp;lt;10).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I might give my all timer initialization routine [I do not use lpcopen]:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void Timer0_Init(void) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;PCONP |= (1&amp;lt;&amp;lt;1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;PCLKSEL0 = (PCLKSEL0&amp;amp;(~(3&amp;lt;&amp;lt;2))) | (1&amp;lt;&amp;lt;2); //pclk=cclk&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;T0TCR = 2; //counters disabled and reset&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;T0CTCR = 0; //timer mode&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;T0PR = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;T0MR0 = CLOCK*500-1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;T0MR3 = CLOCK*1000-1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;T0MCR = (1&amp;lt;&amp;lt;0) | (1&amp;lt;&amp;lt;10); //interrupt on MR0, reset on MR3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;IPR0 = (IPR0&amp;amp;(~(0x1f&amp;lt;&amp;lt;11))) | (1&amp;lt;&amp;lt;11); //interrupt priority&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ISER0 = (1&amp;lt;&amp;lt;1); //interrupt enable&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;T0TCR = 1; //counters enabled&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A few notes also:&lt;/P&gt;&lt;P&gt;- I tried to change Timer0 to Timer1 and get the same results;&lt;/P&gt;&lt;P&gt;- T0IR indicates that the interrupt source is MR0, although interrupt happens on the period according to MR3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a hypothesis that interrupt is asserted only when T0TC is reset to zero and I might think of a few tests that would confirm that, but I'm not sure I will do them, because I achieved my goal with other means than with such a usage of Timer as I described and I have to move forward. I wrote here with the expectation that this is a universal error and that someone would duplicate it and get the same result.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Mar 2018 11:11:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Problem-with-Timer0-in-LPC1769/m-p/725868#M29341</guid>
      <dc:creator>vycska</dc:creator>
      <dc:date>2018-03-06T11:11:48Z</dc:date>
    </item>
  </channel>
</rss>

