<?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>CodeWarrior for MCU中的主题 Re: How make a delay?</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/How-make-a-delay/m-p/170919#M5271</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The professional way is to use one of the on-chip timers or the RTC (real time clock). You'll have to read about those in the manual.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The hobbyist way is to burn away all CPU capacity in a counting loop with a volatile counter variable. You will have to disassemble the code and count the instructions and their cycles, or alternatively write the function in assembler.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The same for contact debouncing: you will have to debounce the button with a timer, no matter if you are using Freescale or PIC.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 20 Dec 2010 22:57:21 GMT</pubDate>
    <dc:creator>Lundin</dc:creator>
    <dc:date>2010-12-20T22:57:21Z</dc:date>
    <item>
      <title>How make a delay?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/How-make-a-delay/m-p/170918#M5270</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I´m beginner &amp;nbsp;programmer with MC9RS08KA in C, and&amp;nbsp;&lt;SPAN&gt;would like to&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN&gt;help&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN&gt;to&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN&gt;create a&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN&gt;delay&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN&gt;of 700ms. e.g. After press a button, one led turn on after 700ms. I knew the function delay_ms() used in PICs, but I don't know how make with codewarrior. Anyone know?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;tks.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 Dec 2010 22:33:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/How-make-a-delay/m-p/170918#M5270</guid>
      <dc:creator>PedroM</dc:creator>
      <dc:date>2010-12-20T22:33:16Z</dc:date>
    </item>
    <item>
      <title>Re: How make a delay?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/How-make-a-delay/m-p/170919#M5271</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The professional way is to use one of the on-chip timers or the RTC (real time clock). You'll have to read about those in the manual.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The hobbyist way is to burn away all CPU capacity in a counting loop with a volatile counter variable. You will have to disassemble the code and count the instructions and their cycles, or alternatively write the function in assembler.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The same for contact debouncing: you will have to debounce the button with a timer, no matter if you are using Freescale or PIC.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 Dec 2010 22:57:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/How-make-a-delay/m-p/170919#M5271</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2010-12-20T22:57:21Z</dc:date>
    </item>
    <item>
      <title>Re: How make a delay?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/How-make-a-delay/m-p/170920#M5272</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV class="lia"&gt;&lt;P&gt;Hello, and welcome to the forum.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The 'RS08KA8 device has two timer modules, a MTIM and a TPM.&amp;nbsp; Either could be used to generate a delay of 700ms.&amp;nbsp; I will explain a possible approach using the MTIM module.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since the 'RS devices do not have a proper interrupt capability, you will need to poll for the occurrence of MTIM overflow.&amp;nbsp; Depending on your requirements, you could generate the delay in one 700ms increment, or alternatively in a number of smaller increments of perhaps 10ms each, and to count the number of overflows for the required delay period.&amp;nbsp; If you have a number of different intervals to generate, and maybe&amp;nbsp;run concurrently,&amp;nbsp;the second method&amp;nbsp;would be the preferred one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You would need to select the fixed frequency clock source to obtain a sufficiently long timing period, i.e. a frequency between the limits 15.625kHz and 19.531kHz, depending on the internal reference clock trim.&amp;nbsp; This is the internal reference frequency divided by two.&amp;nbsp; It is then a matter of setting the prescale value and the MTIMMOD value to obtain the required delay.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, a trim setting for a fixed frequency clock of 15.625kHz, a prescale setting of 64, and MTIMMOD = 170 would produce a delay in the vicinity of 700ms.&amp;nbsp; The delay formula is PS*(MTIMMOD + 1) / FFCLK.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Dec 2010 12:29:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/How-make-a-delay/m-p/170920#M5272</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2010-12-22T12:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: How make a delay?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/How-make-a-delay/m-p/170921#M5273</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;Hello,&lt;/DIV&gt;&lt;DIV&gt;Tkank very much, for quickily answers and for help. Until i can make one increments as code bellow? This correct?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;if(SIP1_MTIM1){ &amp;nbsp; &amp;nbsp;//timer 20ms&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;q++;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;if(q == 500){ &amp;nbsp; &amp;nbsp;//when it reaches x ms&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;LAMP = 1; &amp;nbsp; &amp;nbsp; //turn off &amp;nbsp;lamp&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;q = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;else {&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; LAMP = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;(void) MTIM1SC_TOF;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;MTIM1SC_TOF = 0;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Dec 2010 19:27:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/How-make-a-delay/m-p/170921#M5273</guid>
      <dc:creator>PedroM</dc:creator>
      <dc:date>2010-12-22T19:27:14Z</dc:date>
    </item>
    <item>
      <title>Re: How make a delay?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/How-make-a-delay/m-p/170922#M5274</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Pedro,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think that it would be a good idea for your delay processing to be generally applicable, and not specifically for the timing of a LED.&amp;nbsp; To do this, I think that you would need two functions - one function to setup the delay in the first instance, and a second function that could be periodically polled to test for a delay timeout condition.&amp;nbsp; Both these functions can then be called from your main loop to meet the requirements of your application.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;// Global variable:unsigned int q;void set_delay( unsigned int x){   q = x;   MTIMSC = 0x20;  // Counter reset   MTIMSC_TOF = 0; // Clear flag}unsigned int test_timeout( void){   if (MTIMSC_TOF) {      MTIMSC_TOF = 0; // Clear flag
      if (q)  q--;   }   return q;
}
&lt;/PRE&gt;&lt;P&gt;The following code snippet might be used to control the LED.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;LAMP = 0;set_delay( 50);         // 1 second delaywhile (test_timeout()); // Wait for timeoutLAMP = 1;&lt;/PRE&gt;&lt;P&gt;If the COP (watchdog) is enabled, you will also need to clear the COP timer while you wait for timeout to occur.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:19:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/How-make-a-delay/m-p/170922#M5274</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2020-10-29T09:19:23Z</dc:date>
    </item>
  </channel>
</rss>

