<?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 Re: Is there a delay()? in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Is-there-a-delay/m-p/175062#M5607</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not in our libraries, which are ANSI-compliant. See the following &lt;A href="http://forums.freescale.com/freescale/board/message?board.id=CWDSPCOMM&amp;amp;message.id=1296&amp;amp;query.id=14034#M1296" target="_blank"&gt;thread&lt;/A&gt;. You can search these forums and study some of the delay functions that have been written over time to solve this type of problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;---Tom&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 23 Apr 2009 21:16:31 GMT</pubDate>
    <dc:creator>J2MEJediMaster</dc:creator>
    <dc:date>2009-04-23T21:16:31Z</dc:date>
    <item>
      <title>Is there a delay()?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Is-there-a-delay/m-p/175061#M5606</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi I want to implement delays in my code. Is there a predefined function like delay()?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Apr 2009 20:53:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Is-there-a-delay/m-p/175061#M5606</guid>
      <dc:creator>Simulator_Displ</dc:creator>
      <dc:date>2009-04-23T20:53:07Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a delay()?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Is-there-a-delay/m-p/175062#M5607</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not in our libraries, which are ANSI-compliant. See the following &lt;A href="http://forums.freescale.com/freescale/board/message?board.id=CWDSPCOMM&amp;amp;message.id=1296&amp;amp;query.id=14034#M1296" target="_blank"&gt;thread&lt;/A&gt;. You can search these forums and study some of the delay functions that have been written over time to solve this type of problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;---Tom&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Apr 2009 21:16:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Is-there-a-delay/m-p/175062#M5607</guid>
      <dc:creator>J2MEJediMaster</dc:creator>
      <dc:date>2009-04-23T21:16:31Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a delay()?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Is-there-a-delay/m-p/175063#M5608</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;You do not say which MCU you are using.&amp;nbsp; The attached collection of delay functions are suitable for the HCS08.&amp;nbsp; For some of the methods, there is extensive use of inline assembly for tighter timing control.&amp;nbsp; For a quick and dirty delay function -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;void delay( int val)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;{&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; for ( ; val; val--);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I seem to recall that the time per loop is about 22 cycles for the HCS08.&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>Fri, 24 Apr 2009 01:05:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Is-there-a-delay/m-p/175063#M5608</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2009-04-24T01:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a delay()?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Is-there-a-delay/m-p/175064#M5609</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much for you delay functions. I am attempting to use them on my HCSO8, specifically the M9S08QG8. However I am getting an error when I do. I first copied the entire text of the Delay_HCS08.c file into my Main.c file, making sure they were outside the main function. Then I added the header to my includes folder, and added the necessary #include "Delay_HCS08.h"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However when I try to compile I get the following errors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error: C18103: Factor expected&lt;/P&gt;&lt;P&gt;Error: C18104: ')' expected&lt;/P&gt;&lt;P&gt;Error: C18123: end of line expected&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All three errors point to the following line of code:&lt;/P&gt;&lt;P&gt;LDHX&amp;nbsp; #(N1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Additonally I get two warnings that the pragma No_ENTRY and NO_EXIT lines were not handled.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be greatly appriciated.&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Josh&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Feb 2011 15:47:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Is-there-a-delay/m-p/175064#M5609</guid>
      <dc:creator>beowulf</dc:creator>
      <dc:date>2011-02-15T15:47:37Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a delay()?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Is-there-a-delay/m-p/175065#M5610</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The compiler is free to optimize away that whole function entirely, as it contains no side effects. "val" must be declared volatile to prevent that from happening.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Feb 2011 16:58:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Is-there-a-delay/m-p/175065#M5610</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2011-02-15T16:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a delay()?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Is-there-a-delay/m-p/175066#M5611</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Im sorry, but I don't understand. Could you please explain in more detail. Additionally, I tried to define val as a global variable with the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;int volatile val;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But this did not change my errors. I did some looking and I read that the HCS08 has additional addressing options for LDHX command. Perhaps this is the problem?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks agian,&lt;/P&gt;&lt;P&gt;Josh&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Feb 2011 19:38:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Is-there-a-delay/m-p/175066#M5611</guid>
      <dc:creator>beowulf</dc:creator>
      <dc:date>2011-02-15T19:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a delay()?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Is-there-a-delay/m-p/175067#M5612</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;User an hardware timer to generate a "tick" of 1 or 10 uS then just initialize and compare variable to this "tick" to generate a time delay&lt;/P&gt;&lt;P&gt;(I always have 1 timer dedicated to "tick" need a global tick counter 16 or 32 bit your call&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 19 Feb 2011 01:37:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Is-there-a-delay/m-p/175067#M5612</guid>
      <dc:creator>Juls</dc:creator>
      <dc:date>2011-02-19T01:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a delay()?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Is-there-a-delay/m-p/175068#M5613</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Josh,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found a number of minor problems with the code that prevented proper compilation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;The&amp;nbsp;macro for clearing the COP timer is usually specified as __RESET_WATCHDOG&lt;FONT color="#ff0000"&gt;()&lt;/FONT&gt; rather than __RESET_WATCHDOG.&lt;/LI&gt;&lt;LI&gt;The macro definitions within the header file, for constants N1 and N2,&amp;nbsp;have errors - some brace characters {}&amp;nbsp;had crept in, in place of the required parenthesis ().&amp;nbsp; With some fonts, these are difficult to distinguish from each other.&lt;/LI&gt;&lt;LI&gt;One of the functions was missing a closing parenthesis for the return statement.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Once these problems were fixed, I had no difficulty in compiling the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lundin:&lt;/P&gt;&lt;P&gt;I presume that you are referring to the function:&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;void delay( int val)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;{&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; for ( ; val; val--);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This function did not actually appear within the attached file, so was not the source of the compiling problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With respect to your intimation that the CodeWarrior complier&amp;nbsp;may be&amp;nbsp;free to ignore the programmer's&amp;nbsp;wish to create a simple function, I find very&amp;nbsp;hard to believe.&amp;nbsp; In fact, we know this is not the case for the function in question.&amp;nbsp; The reference guide "HCS08 Unleashed", by Fabio Pereira, does make use to this function in many of the tested examples, and I have never had a problem with CW generating the appropriate code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do not know what you specifically mean bt a "side effect", but might have thought that the used of the parameter within a for loop, empty or otherwise, would represent use of the parameter, certainly sufficient to prevent a compiler warning message about an unused parameter.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In terms of the need to declare a function parameter as "volatile", this is not a topic that I have ever seen covered by a general C text reference.&amp;nbsp; Perhaps you may be able to enlighten.&amp;nbsp;&amp;nbsp;Maybe it is a C++ thing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Juls,&lt;/P&gt;&lt;P&gt;I&amp;nbsp;think that creating a timer interrupt at 1us or 10us intervals would be a&amp;nbsp;bad idea.&amp;nbsp; With a maximum bus frequency of 10MHz, the number of bus cycles between interrupts would be 10 or 100 cycles&amp;nbsp;maximum.&amp;nbsp; Since the minimum overhead for an ISR entry and exit will be about 25 cycles (not including the ISR code), this will give insufficient time to process the ISR, and do any other useful work.&amp;nbsp; I would suggest that the periodic tick interval should be 100us absolute minimum -&amp;nbsp; &amp;gt;= 1ms would be better.&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Feb 2011 21:08:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Is-there-a-delay/m-p/175068#M5613</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2011-02-21T21:08:22Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a delay()?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Is-there-a-delay/m-p/175069#M5614</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Oh I know that CW won't optimize it away. But I wrote the &lt;EM&gt;compiler&lt;/EM&gt;, as in any compiler. Assuming that you wish to keep the code portable, so that you can reuse it in other projects in the future.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As the result of "val" is not used anywhere in the code, the compiler can optimize it away. Some compilers may just optimize away the whole loop and replace it with val=0;. And then, as val isn't used anywhere, it optimizes away that assignment as well. Whether or not such optimizations conform to the C standard may be argued, but many compilers do it. By declaring val as volatile, you enforce the compiler to perform each iteration of the loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Because accessing a volatile variable is a "side effect", which is C language gibberish for something that is changing the value of a variable. The -- operator is a side-effect too, though as the result of the -- is not used, the compiler may feel the urge to optimize the result away.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the volatile declaration should be there to be on the safe side against certain compilers.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Feb 2011 16:00:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Is-there-a-delay/m-p/175069#M5614</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2011-02-22T16:00:10Z</dc:date>
    </item>
  </channel>
</rss>

