<?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: Need help with Real Time Interrupt in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Need-help-with-Real-Time-Interrupt/m-p/198573#M7388</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You should to mention what device are you talking about.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You want to toggle pin every 0.5ms, but are calculating required prescaler for 0.5s.&lt;/P&gt;&lt;P&gt;For long periods you could setup RTI to fire for example every 100ms and toggle pin on every 5th RTI interrupt.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 16 Apr 2011 00:18:29 GMT</pubDate>
    <dc:creator>kef</dc:creator>
    <dc:date>2011-04-16T00:18:29Z</dc:date>
    <item>
      <title>Need help with Real Time Interrupt</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Need-help-with-Real-Time-Interrupt/m-p/198572#M7387</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to use an interrurpt using RTI module in CRG. The interrupt must keep track of minute and second&lt;/P&gt;&lt;P&gt;elapsed since the start up. The port t bit 7 must set up as an output and toggled every 0.5 ms.&lt;/P&gt;&lt;P&gt;This is how i calculated the prescaler needed :&lt;/P&gt;&lt;P&gt;period = 1/oscClk*prescaler&lt;/P&gt;&lt;P&gt;prescaler = 0.5/(1/16Mhz)&amp;nbsp;&lt;/P&gt;&lt;P&gt;prescaler = 8000000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, the maximum value for the prescaler is 1048576.&lt;/P&gt;&lt;P&gt;Did i do anything wrong with the calculation?&lt;/P&gt;&lt;P&gt;Do i have to use modulus counter?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The modulus counter will be used to generate periodic interrupt every 2 seconds, so i don't think i can use the modulus&lt;/P&gt;&lt;P&gt;counter there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the function looks like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;void CRG_SetupRTI(const UINT8 prescaleRate, const UINT8 modulusCount)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Apr 2011 13:00:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Need-help-with-Real-Time-Interrupt/m-p/198572#M7387</guid>
      <dc:creator>Leinad</dc:creator>
      <dc:date>2011-04-15T13:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with Real Time Interrupt</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Need-help-with-Real-Time-Interrupt/m-p/198573#M7388</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You should to mention what device are you talking about.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You want to toggle pin every 0.5ms, but are calculating required prescaler for 0.5s.&lt;/P&gt;&lt;P&gt;For long periods you could setup RTI to fire for example every 100ms and toggle pin on every 5th RTI interrupt.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 16 Apr 2011 00:18:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Need-help-with-Real-Time-Interrupt/m-p/198573#M7388</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2011-04-16T00:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with Real Time Interrupt</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Need-help-with-Real-Time-Interrupt/m-p/198574#M7389</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;yes you have a math problem&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 / 25 * 10 results in - - - -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;while&amp;nbsp; 1 / (25 * 10) results in - - - -&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 16 Apr 2011 05:31:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Need-help-with-Real-Time-Interrupt/m-p/198574#M7389</guid>
      <dc:creator>Jim_P</dc:creator>
      <dc:date>2011-04-16T05:31:17Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with Real Time Interrupt</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Need-help-with-Real-Time-Interrupt/m-p/198575#M7390</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yep i got it... i made this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;void CRG_SetupRTI(const UINT8 prescaleRate, const UINT8 modulusCount)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PORTE_BIT4 = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DDRE_BIT4 =1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; RTICTL = prescaleRate;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //prescaleRate is 16384, period = 1.024&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CRGINT_RTIE = 1;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // enable RTI&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; counter = 0; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; // global variable showing how many intterupts were executed&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; asm cli;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // enable interrupts&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;void interrupt RTI_ISR(void)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; CRGFLG_RTIF = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if(counter == 500)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PORTE_BIT4 = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count++;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PORTE_BIT4 = 0;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I made the period 1.024 and then in the RTI_ISR function, count till 500.&lt;/P&gt;&lt;P&gt;500 x 1.024 = 512&lt;/P&gt;&lt;P&gt;Is this correct?&lt;/P&gt;&lt;P&gt;Does that make the LED toggled approximately every 0.5s?&lt;/P&gt;&lt;P&gt;If so, how do you keep track of the elapsed time?&lt;/P&gt;&lt;P&gt;I'm thinking using PORT T bit 0 and toggle the output of the Port&lt;/P&gt;&lt;P&gt;so it can update the clock?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do you use a modulus counter to provide a periodic intterupt every 2ms?&lt;/P&gt;&lt;P&gt;I know how the modulus counter works but i don't know how long the system will&lt;/P&gt;&lt;P&gt;take to count for example from 100 counts to 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using MC9s12 with 16Mhz crystal (oscillator clock)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 16 Apr 2011 09:24:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Need-help-with-Real-Time-Interrupt/m-p/198575#M7390</guid>
      <dc:creator>Leinad</dc:creator>
      <dc:date>2011-04-16T09:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with Real Time Interrupt</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Need-help-with-Real-Time-Interrupt/m-p/198576#M7391</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;MC9S12 is not enough. You should mention letters past 12, for example S12C, S12XD etc. S12XD RTI has decimal clock prescaler mode, older families don't have such mode, etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your code has few bugs:&lt;/P&gt;&lt;P&gt;1) You should reset count in ==500 case,&lt;/P&gt;&lt;P&gt;2) you are not toggling port pin, but pulsing it high for&amp;nbsp;less than microsecond.&lt;/P&gt;&lt;P&gt;3) pin pulsing period is going to&amp;nbsp;be 501 RTI periods. When count reaches 500 and you reset it, you exit ISR. But when you reenter ISR one RTI period later,&amp;nbsp;this one period is not counted. So either chnge your code&amp;nbsp;to if(count == 500-1) or maybe change the logic like this&lt;/P&gt;&lt;P&gt;isr()&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; count++;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if(count == 500)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PORTE ^= (1&amp;lt;&amp;lt;4);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;4) The ay you clear RTI flag has side effects, which certainly will bite you sooner or later. You are clearing all flags in CRGFLG register, not just RTIF.&amp;nbsp; To clear only RTIF you shoud CRGFLG = CRGFLG_RTIF_MASK;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you are going to toggle pin on port T, then why are you pulsing pin port E?&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;P&gt;Does that make the LED toggled approximately every 0.5s?&lt;/P&gt;&lt;P&gt;If so, how do you keep track of the elapsed time?&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Do you mean how to count seconds? The's number of ways to do this. You may&amp;nbsp;sum all milli- and microseconds like 1024us+1024us+ etc and convert microseconds&amp;nbsp;to seconds and minutes. You may also try to find prescaler so that integer number of RTI periods will take exactly 1s. For this at 16MHz oscilator clock 1024 and 5120 prescalers are available. 5120 presclaer gives RTI period if 320us, 320us *3125 = 1s.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;P&gt;How do you use a modulus counter to provide a periodic intterupt every 2ms?&lt;/P&gt;&lt;P&gt;I know how the modulus counter works but i don't know how long the system will&lt;/P&gt;&lt;P&gt;take to count for example from 100 counts to 0.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Do you mean you don't know what clock modulus down counter is operating at? It's bus clock (which is half of oscilator clock).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 Apr 2011 02:52:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Need-help-with-Real-Time-Interrupt/m-p/198576#M7391</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2011-04-17T02:52:43Z</dc:date>
    </item>
  </channel>
</rss>

