<?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: TPM1 and TPM2 counters run at different rates in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/TPM1-and-TPM2-counters-run-at-different-rates/m-p/137757#M4749</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi Esther,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;This is all to do with the fact that you have two timers running almost in synchronise and the TPM1 interrupt vector has a higher priority than the TPM2. When both TOF flags are set TPM1 ISR is always executed first even if TPM2 was set first and while in an ISR all other interrupts are masked.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;If you set a breakpoint in each ISR you will be able to see this happening. TPM1 ISR will be running while both timers continue in the background, TOF[2] is set.&amp;nbsp;Before it exists TOF[1] is set again so the ISR[1] runs.&amp;nbsp;This is how your counters are getting out of sync.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Hope this explanation makes sense :smileywink:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Pingu&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 23 Nov 2006 19:35:01 GMT</pubDate>
    <dc:creator>Pingu</dc:creator>
    <dc:date>2006-11-23T19:35:01Z</dc:date>
    <item>
      <title>TPM1 and TPM2 counters run at different rates</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/TPM1-and-TPM2-counters-run-at-different-rates/m-p/137756#M4748</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;MC9S08DZ60.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;TPM1 and TPM2 both set to bus rate clock, prescale=1.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;TPM1MODH:L and TPM2MODH:L both set to the same values.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;TPM1 and TPM2 both set to generate interrupts on overflow.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;ISR's for each have a counter.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;But the counters run at different rates !&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I thought the counter values should be indentical.&amp;nbsp; What am I missing here?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Nov 2006 14:26:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/TPM1-and-TPM2-counters-run-at-different-rates/m-p/137756#M4748</guid>
      <dc:creator>EtherJones</dc:creator>
      <dc:date>2006-11-23T14:26:43Z</dc:date>
    </item>
    <item>
      <title>Re: TPM1 and TPM2 counters run at different rates</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/TPM1-and-TPM2-counters-run-at-different-rates/m-p/137757#M4749</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi Esther,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;This is all to do with the fact that you have two timers running almost in synchronise and the TPM1 interrupt vector has a higher priority than the TPM2. When both TOF flags are set TPM1 ISR is always executed first even if TPM2 was set first and while in an ISR all other interrupts are masked.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;If you set a breakpoint in each ISR you will be able to see this happening. TPM1 ISR will be running while both timers continue in the background, TOF[2] is set.&amp;nbsp;Before it exists TOF[1] is set again so the ISR[1] runs.&amp;nbsp;This is how your counters are getting out of sync.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Hope this explanation makes sense :smileywink:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Pingu&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Nov 2006 19:35:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/TPM1-and-TPM2-counters-run-at-different-rates/m-p/137757#M4749</guid>
      <dc:creator>Pingu</dc:creator>
      <dc:date>2006-11-23T19:35:01Z</dc:date>
    </item>
    <item>
      <title>Re: TPM1 and TPM2 counters run at different rates</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/TPM1-and-TPM2-counters-run-at-different-rates/m-p/137758#M4750</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Hello Ester,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;With Pingu's explanation, there should never be more than a difference of one between the two counter values.&amp;nbsp; Is this what you observe?&amp;nbsp; The count rate should be the same for both,&amp;nbsp;however both counter values cannot &lt;U&gt;simultaneously&lt;/U&gt; increment.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Note that the PWM output signals associated with each TPM module should&amp;nbsp;remain synchronous within a few bus cycles, since these are determined by the timer hardware within the MCU.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;It probably does not apply to your simple sample code, but there would need to be a further&amp;nbsp;consideration for the more general case.&amp;nbsp; Since you have set the timer modulo value to give an overflow period of 201 cycles for each module, this would require that the two timer overflow ISRs, plus any other ISR that may possibly occur, must all&amp;nbsp;be able to execute in&amp;nbsp;somewhat less than 201 cycles in total.&amp;nbsp; Otherwise, this would lead to erratic operation of the software counters.&amp;nbsp; In many instances, meeting this limit would not be possible.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Regards,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Mac&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Nov 2006 21:01:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/TPM1-and-TPM2-counters-run-at-different-rates/m-p/137758#M4750</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2006-11-23T21:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: TPM1 and TPM2 counters run at different rates</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/TPM1-and-TPM2-counters-run-at-different-rates/m-p/137759#M4751</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;EM&gt;With Pingu's explanation, there should never be more than a difference of one between the two counter values.&amp;nbsp; Is this what you observe?&lt;/EM&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;STRONG&gt;No.&amp;nbsp;&amp;nbsp; The timers are running at different &lt;EM&gt;rates&lt;/EM&gt;.&amp;nbsp;&amp;nbsp; The TPM1 timer is running 15% faster than TPM2.&amp;nbsp;&amp;nbsp;&amp;nbsp; The ratio between the two timer counters is about 1.15 to 1.&amp;nbsp;&amp;nbsp;&amp;nbsp; So the longer I let it run, the greater the numerical difference between the two counters.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;What could cause this?&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Nov 2006 00:28:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/TPM1-and-TPM2-counters-run-at-different-rates/m-p/137759#M4751</guid>
      <dc:creator>EtherJones</dc:creator>
      <dc:date>2006-11-24T00:28:23Z</dc:date>
    </item>
    <item>
      <title>Re: TPM1 and TPM2 counters run at different rates</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/TPM1-and-TPM2-counters-run-at-different-rates/m-p/137760#M4752</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;As Mac said your TOTAL interrupt service time is most likely longer than the rate at which the interrupts are coming in, this is a no-no. Then Pingu's obsevation comes in... TIM1 does have priority, and if interrupt requests are stacked it will get more frequent attention.&lt;BR /&gt;&lt;BR /&gt;Experiment a bit... increase your TIMx modulo values... by a lot more than 15%. :smileyhappy: The problems just may vanish.&lt;BR /&gt;&lt;BR /&gt;Al&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Nov 2006 00:37:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/TPM1-and-TPM2-counters-run-at-different-rates/m-p/137760#M4752</guid>
      <dc:creator>Geezer</dc:creator>
      <dc:date>2006-11-24T00:37:26Z</dc:date>
    </item>
  </channel>
</rss>

