<?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 Is it possible to create a delay in program only using TCNT timer in S12 / MagniV Microcontrollers</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Is-it-possible-to-create-a-delay-in-program-only-using-TCNT/m-p/133145#M1827</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi all!!&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I have tried to use the TCNT timer to create a delay in my program.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;MCU : 9S12XDP512&lt;/DIV&gt;&lt;DIV&gt;Osc.Clock: 8MHz&lt;/DIV&gt;&lt;DIV&gt;Bus Clock : 40MHz&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I called the below function to make a delay by adding the required delay value "ms" to the present&amp;nbsp;TCNT and then compare the TCNT value until it reaches "tCNT".&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The code works fine. But how can i know that the required delay has been achieved?&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;void Delay(UINT ms)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;tCNT = TCNT;&lt;BR /&gt;&amp;nbsp;tCNT += ms;&lt;BR /&gt;&amp;nbsp;while (tCNT != TCNT)&lt;BR /&gt;&amp;nbsp;;&lt;BR /&gt;}&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;I could not see the free running TCNT register getting incremented in the True time simulator.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Any suggestions?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;embedlov&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 09 May 2007 13:43:29 GMT</pubDate>
    <dc:creator>embedlov</dc:creator>
    <dc:date>2007-05-09T13:43:29Z</dc:date>
    <item>
      <title>Is it possible to create a delay in program only using TCNT timer</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Is-it-possible-to-create-a-delay-in-program-only-using-TCNT/m-p/133145#M1827</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi all!!&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I have tried to use the TCNT timer to create a delay in my program.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;MCU : 9S12XDP512&lt;/DIV&gt;&lt;DIV&gt;Osc.Clock: 8MHz&lt;/DIV&gt;&lt;DIV&gt;Bus Clock : 40MHz&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I called the below function to make a delay by adding the required delay value "ms" to the present&amp;nbsp;TCNT and then compare the TCNT value until it reaches "tCNT".&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The code works fine. But how can i know that the required delay has been achieved?&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;void Delay(UINT ms)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;tCNT = TCNT;&lt;BR /&gt;&amp;nbsp;tCNT += ms;&lt;BR /&gt;&amp;nbsp;while (tCNT != TCNT)&lt;BR /&gt;&amp;nbsp;;&lt;BR /&gt;}&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;I could not see the free running TCNT register getting incremented in the True time simulator.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Any suggestions?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;embedlov&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2007 13:43:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Is-it-possible-to-create-a-delay-in-program-only-using-TCNT/m-p/133145#M1827</guid>
      <dc:creator>embedlov</dc:creator>
      <dc:date>2007-05-09T13:43:29Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to create a delay in program only using TCNT timer</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Is-it-possible-to-create-a-delay-in-program-only-using-TCNT/m-p/133146#M1828</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;It's a bad idea to wait for exact match tCNT==TCNT. Even at max possible prescaler single timer tick takes just 128 bus cycles. Do some&amp;nbsp;math or serve some longer interrupt and TCNT will become &amp;gt; tCNT.&lt;/DIV&gt;&lt;DIV&gt;Also "&amp;nbsp;while (tCNT != TCNT)" takes more than 1 bus cycle so it won't work properly with timer prescaler =1 even if interrupts are disabled.&lt;/DIV&gt;&lt;DIV&gt;You can use something like this:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;void Delay(UINT dly)&lt;BR /&gt;{&lt;BR /&gt;short&amp;nbsp;tCNT = TCNT + dly;&lt;BR /&gt;&amp;nbsp;while (&amp;nbsp;&amp;nbsp;(signed short)(TCNT-tCNT)&amp;nbsp; &amp;lt; 0);&lt;BR /&gt;}&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Limitation of this code is that dly should be less than 2^15.&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2007 14:26:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Is-it-possible-to-create-a-delay-in-program-only-using-TCNT/m-p/133146#M1828</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2007-05-09T14:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to create a delay in program only using TCNT timer</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Is-it-possible-to-create-a-delay-in-program-only-using-TCNT/m-p/133147#M1829</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;Well... lets say that TCNT is 65535 and dly is 1. tCNT will then become 0 and the expression will be evaluated as&lt;BR /&gt;&lt;BR /&gt;while( (signed short)(65535 - 0) &amp;lt; 0);&lt;BR /&gt;&lt;BR /&gt;So the loop will break even though no time has passed.&lt;BR /&gt;&lt;BR /&gt;The serious solution is to use one of the TC channels, which will save you the headache of integer overflows as well.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2007 14:45:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Is-it-possible-to-create-a-delay-in-program-only-using-TCNT/m-p/133147#M1829</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2007-05-10T14:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to create a delay in program only using TCNT timer</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Is-it-possible-to-create-a-delay-in-program-only-using-TCNT/m-p/133148#M1830</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;(signed short)65535 is negative, it's -1 and is less than 0. So loop will continue.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2007 15:13:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Is-it-possible-to-create-a-delay-in-program-only-using-TCNT/m-p/133148#M1830</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2007-05-10T15:13:14Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to create a delay in program only using TCNT timer</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Is-it-possible-to-create-a-delay-in-program-only-using-TCNT/m-p/133149#M1831</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Oops, you are correct, I forgot the typecast.&lt;BR /&gt;&lt;BR /&gt;But still, the timer channels is a better solution since they won't keep the CPU busy doing comparisons.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2007 16:17:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Is-it-possible-to-create-a-delay-in-program-only-using-TCNT/m-p/133149#M1831</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2007-05-10T16:17:58Z</dc:date>
    </item>
  </channel>
</rss>

