<?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: MC9S08RE16- need two timers in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC9S08RE16-need-two-timers/m-p/184593#M13749</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Hello,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;It is not clear how you have already configured the timer for your 1ms tick.&amp;nbsp; However, there would appear to be a couple of alternatives, using either one or two channels of the TPM module, in output compare mode.&amp;nbsp; In both cases, the TPM modulo setting should remain at its default, with a free-running counter.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The first alternative would be to use separate channels for each of the&amp;nbsp;intervals.&amp;nbsp; When&amp;nbsp;an interrupt occurs following each output compare event, simply add the number of increments corresponding to the required interval to the current channel value.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The second possibility would require only a single TPM channel, again using output compare mode (normally interrupt only configuration), to generate an interrupt every 62.5 microseconds.&amp;nbsp; Then within the ISR, increment a count value.&amp;nbsp; One in every 16 interrupts would then correspond with the `1ms tick.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;count++;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Every 62.5us&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;if (!(count &amp;amp; 0x0F))&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; tick = 1;&amp;nbsp; // Every 1ms&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Mac&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by bigmac on &lt;SPAN class="date_text"&gt;2008-09-10&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;01:34 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 10 Sep 2008 10:22:35 GMT</pubDate>
    <dc:creator>bigmac</dc:creator>
    <dc:date>2008-09-10T10:22:35Z</dc:date>
    <item>
      <title>MC9S08RE16- need two timers</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC9S08RE16-need-two-timers/m-p/184592#M13748</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am running a 1mS timer under interrupt as a system clock. I need to independantly determine a fixed 62.5uS timer to achieve a 16kHz speech output sample rate i.e start 62.5uS timer, output to DAC, wait for timer to time out. How can I achieve this with only the one timer module (if at all).&lt;/SPAN&gt;&lt;BR /&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Sep 2008 21:04:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC9S08RE16-need-two-timers/m-p/184592#M13748</guid>
      <dc:creator>stevec</dc:creator>
      <dc:date>2008-09-09T21:04:59Z</dc:date>
    </item>
    <item>
      <title>Re: MC9S08RE16- need two timers</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC9S08RE16-need-two-timers/m-p/184593#M13749</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Hello,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;It is not clear how you have already configured the timer for your 1ms tick.&amp;nbsp; However, there would appear to be a couple of alternatives, using either one or two channels of the TPM module, in output compare mode.&amp;nbsp; In both cases, the TPM modulo setting should remain at its default, with a free-running counter.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The first alternative would be to use separate channels for each of the&amp;nbsp;intervals.&amp;nbsp; When&amp;nbsp;an interrupt occurs following each output compare event, simply add the number of increments corresponding to the required interval to the current channel value.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The second possibility would require only a single TPM channel, again using output compare mode (normally interrupt only configuration), to generate an interrupt every 62.5 microseconds.&amp;nbsp; Then within the ISR, increment a count value.&amp;nbsp; One in every 16 interrupts would then correspond with the `1ms tick.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;count++;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Every 62.5us&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;if (!(count &amp;amp; 0x0F))&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; tick = 1;&amp;nbsp; // Every 1ms&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Mac&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by bigmac on &lt;SPAN class="date_text"&gt;2008-09-10&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;01:34 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Sep 2008 10:22:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC9S08RE16-need-two-timers/m-p/184593#M13749</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-09-10T10:22:35Z</dc:date>
    </item>
    <item>
      <title>Re: MC9S08RE16- need two timers</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC9S08RE16-need-two-timers/m-p/184594#M13750</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Thanks Bigmac,&lt;BR /&gt;&lt;BR /&gt;So I can not run two independant timers. I see that now as there is only one counter. I was trying to reduce interrupt processing time as my speech output routine takes 47 uS. I don't have much time left within the 62.5 uS sample period to do other things like switch debounce. I may have to review whether I go back to the AT89F51 I was using before (which has 2 timers). When I chose this particular HCS08 chip I was mislead by the manual into thinking that the CPU executed instructions at a higher rate (xtal freq rather than xtal freq/2) so I though I had lots of clock cycles to get things done in.&lt;BR /&gt;I will look at your suggestions however and see which has the lowest overhead.&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Sep 2008 15:12:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC9S08RE16-need-two-timers/m-p/184594#M13750</guid>
      <dc:creator>stevec</dc:creator>
      <dc:date>2008-09-10T15:12:47Z</dc:date>
    </item>
    <item>
      <title>Re: MC9S08RE16- need two timers</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC9S08RE16-need-two-timers/m-p/184595#M13751</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;DIV&gt;Hello,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;To avoid the additional complexity (and execution cycles) of handling nested interrupts, it sounds like the 1ms tick should be derived within the 62.5 us interrupt routine.&amp;nbsp; This way you will avoid the potential for the additional overhead of a second interrupt to delay the priority interrupt.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I assume you would be using the maximum bus frequency of 8MHz, with 500 bus cycles between successive interrupts.&amp;nbsp; You may need to use inline assembly code for the ISR to minimize the number cycles required.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;In pure assembly code, the minimum overhead to enter the interrupt, update the OC value, clear the interrupt flag, and exit the interrupt would amount to about 40 cycles (5 us).&amp;nbsp; Here, I assume a prescale value of 4 for the TPM.&amp;nbsp; To&amp;nbsp;further set a 1ms tick flag, for eventual processing as a background task, would need an additional 13 - 17 cycles within the ISR.&amp;nbsp; With this optimised code, the total overhead should amount to about&amp;nbsp;7.1 us.&amp;nbsp; Obviously, this would not leave many cycles&amp;nbsp;for background processing tasks.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;For the purpose of the calculation, here is the assembly code that I assumed -&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;ISR_TPMCH0:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; [11] Entry to ISR&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pshh&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; ; [2]&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ldhx&amp;nbsp;&amp;nbsp;TPMC0V&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;; [4] Update TPM channel&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; aix&amp;nbsp;&amp;nbsp;&amp;nbsp;#125&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; [2]&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sthx&amp;nbsp;&amp;nbsp;TPMC0V&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; [4]&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; inc&amp;nbsp;&amp;nbsp;&amp;nbsp;COUNT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; [5] Global variable in zero page&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lda&amp;nbsp;&amp;nbsp;&amp;nbsp;COUNT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; [3]&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and&amp;nbsp;&amp;nbsp;&amp;nbsp;#$0F&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;; [2] Mask low nybble&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bne&amp;nbsp;&amp;nbsp; BR1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; [3] Branch if not timeout&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mov&amp;nbsp;&amp;nbsp; #1,TICK&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; [4] Global variable in zero page&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;BR1:&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; Other code here&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bclr&amp;nbsp;&amp;nbsp;CH0F,TPMC0SC&amp;nbsp;; [5] Clear flag&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pulh&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; ; [3]&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rti&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;; [9]&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Could there be a possibility that your speech output routine would benefit from the use of assembly code (if you are not already doing so)?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Mac&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Sep 2008 22:26:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC9S08RE16-need-two-timers/m-p/184595#M13751</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-09-10T22:26:25Z</dc:date>
    </item>
  </channel>
</rss>

