<?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: MTIM vs. TPM in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MTIM-vs-TPM/m-p/215428#M18682</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello irob,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The flag clearing for the MTIM appears very similar to clearing the overflow flag of the TPM module, i.e. read the status and control register and write 0 to the flag bit within the register.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MTIMSC_TOF = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp; // This is actually a read-modify-write operation&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think that I am correct in saying that the MTIM module is provided within those devices that contain only&amp;nbsp;a single TPM module.&amp;nbsp; I guess the issue is that, if PWM operation is required at a reasonably high, and maybe variable output&amp;nbsp;frequency, this may&amp;nbsp;cause much&amp;nbsp;inconvenience in using&amp;nbsp;the TPM overflow interrupt for other timing purposes, since the overflow period may be&amp;nbsp;too short.&amp;nbsp; If a device has a second TPM module, there would be less need for the MTIM module.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I presume that you are considering the use of the MTIM module for your state maching timing, as outlined in another recent thread.&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>Thu, 29 Jul 2010 03:52:03 GMT</pubDate>
    <dc:creator>bigmac</dc:creator>
    <dc:date>2010-07-29T03:52:03Z</dc:date>
    <item>
      <title>MTIM vs. TPM</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MTIM-vs-TPM/m-p/215426#M18680</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey, everyone.&amp;nbsp; I've gotten myself thoroughly confused (again)!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I started writing a new &lt;A _jive_internal="true" href="https://community.nxp.com/external-link.jspa?url=https%3A%2F%2Fcommunity.freescale.com%2Fmessage%2F67982%2367982" rel="nofollow noopener noreferrer" target="_blank"&gt;https://community.freescale.com/message/67982#67982&lt;/A&gt;, using the MTIM module as my timer.&amp;nbsp; I'm writing this on a JS16 (but I've found that QG8 seems nearly identical for MTIM purposes).&amp;nbsp; In hardware degugging, I find that my code gets stuck in ISR.&amp;nbsp; The datasheet isn't very clear about any sort of interrupt flag clearing, or any such procedure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The other threads here that were helpful are:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" href="https://community.nxp.com/external-link.jspa?url=https%3A%2F%2Fcommunity.freescale.com%2Fmessage%2F38101%2338101" rel="nofollow noopener noreferrer" target="_blank"&gt;https://community.freescale.com/message/38101#38101&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" href="https://community.nxp.com/external-link.jspa?url=https%3A%2F%2Fcommunity.freescale.com%2Fmessage%2F14035%2314035" rel="nofollow noopener noreferrer" target="_blank"&gt;https://community.freescale.com/message/14035#14035&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;These got me to ask myself, 'what is the difference between the MTIM and the TPM modules?'&amp;nbsp; TPM seems to be able to run in free-running mode and with modulus!&amp;nbsp; So why need a separate modulo timer module?&amp;nbsp; Also, the TPM module has much more explicit procedures for clearing interrupt flags.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At any rate, my MTIM code is as such:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&amp;nbsp; MTIMCLK_CLKS = 0b00;&amp;nbsp;&amp;nbsp;&amp;nbsp; // select BUSCLK
&amp;nbsp; MTIMCLK_PS = 0b0111;&amp;nbsp;&amp;nbsp;&amp;nbsp; // MTIM clock source divided by 128 = 46.875KHz
&amp;nbsp; MTIMMOD = 0x7F;
&amp;nbsp; MTIMSC_TOIE = 1;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // enable overflow interrupts


&amp;nbsp; SPARE1 = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // PTA2
&amp;nbsp; MTIMSC_TRST = 1;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // clear the counter
&amp;nbsp; MTIMSC_TSTP = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // start the timer counter

&amp;nbsp; EnableInterrupts; 

&amp;nbsp; for(;;)
&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (overflow_flag)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; overflow_flag = 0;&amp;nbsp; // reset flag
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // do something else here
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp; }

interrupt VectorNumber_Vmtim void IntMtim(void)
{
&amp;nbsp; SPARE1 = !SPARE1;
&amp;nbsp; overflow_flag = 1;
&amp;nbsp; __RESET_WATCHDOG();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // feed the dog
}&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Jul 2010 23:32:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MTIM-vs-TPM/m-p/215426#M18680</guid>
      <dc:creator>irob</dc:creator>
      <dc:date>2010-07-28T23:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: MTIM vs. TPM</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MTIM-vs-TPM/m-p/215427#M18681</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ugg, in the time it took me to write all that, I fixed my own problem.&amp;nbsp; Based on those other links, I made an educated guess and cleared the TOF inside my ISR:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;interrupt VectorNumber_Vmtim void IntMtim(void){  if (MTIMSC)  {   // dummy read to clear the flag  }  MTIMSC_TOF = 0;    // reset counter flag  overflow_flag = 1;  __RESET_WATCHDOG();       // feed the dog}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works great.&amp;nbsp; Still not too sure on the fine differences between MTIM and TPM modules.&amp;nbsp; I guess Freescale is just giving us more options.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Jul 2010 23:46:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MTIM-vs-TPM/m-p/215427#M18681</guid>
      <dc:creator>irob</dc:creator>
      <dc:date>2010-07-28T23:46:21Z</dc:date>
    </item>
    <item>
      <title>Re: MTIM vs. TPM</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MTIM-vs-TPM/m-p/215428#M18682</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello irob,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The flag clearing for the MTIM appears very similar to clearing the overflow flag of the TPM module, i.e. read the status and control register and write 0 to the flag bit within the register.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MTIMSC_TOF = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp; // This is actually a read-modify-write operation&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think that I am correct in saying that the MTIM module is provided within those devices that contain only&amp;nbsp;a single TPM module.&amp;nbsp; I guess the issue is that, if PWM operation is required at a reasonably high, and maybe variable output&amp;nbsp;frequency, this may&amp;nbsp;cause much&amp;nbsp;inconvenience in using&amp;nbsp;the TPM overflow interrupt for other timing purposes, since the overflow period may be&amp;nbsp;too short.&amp;nbsp; If a device has a second TPM module, there would be less need for the MTIM module.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I presume that you are considering the use of the MTIM module for your state maching timing, as outlined in another recent thread.&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>Thu, 29 Jul 2010 03:52:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MTIM-vs-TPM/m-p/215428#M18682</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2010-07-29T03:52:03Z</dc:date>
    </item>
    <item>
      <title>Re: MTIM vs. TPM</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MTIM-vs-TPM/m-p/215429#M18683</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;bigmac wrote:&lt;BR /&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MTIMSC_TOF = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp; // This is actually a read-modify-write operation&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Oh, I didn't realize this.&amp;nbsp; I don't need to do that extra read, huh?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;I presume that you are considering the use of the MTIM module for your state maching timing, as outlined in another recent thread.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;You are correct, sir!&amp;nbsp; Works nicely, thanks.&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>Thu, 29 Jul 2010 22:36:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MTIM-vs-TPM/m-p/215429#M18683</guid>
      <dc:creator>irob</dc:creator>
      <dc:date>2010-07-29T22:36:09Z</dc:date>
    </item>
  </channel>
</rss>

