AnsweredAssumed Answered

MTIM vs. TPM

Question asked by ROB LUND on Jul 28, 2010
Latest reply on Jul 29, 2010 by ROB LUND

Hey, everyone.  I've gotten myself thoroughly confused (again)!

 

I started writing a new https://community.freescale.com/message/67982#67982, using the MTIM module as my timer.  I'm writing this on a JS16 (but I've found that QG8 seems nearly identical for MTIM purposes).  In hardware degugging, I find that my code gets stuck in ISR.  The datasheet isn't very clear about any sort of interrupt flag clearing, or any such procedure.

 

The other threads here that were helpful are:

 

https://community.freescale.com/message/38101#38101

https://community.freescale.com/message/14035#14035

 

These got me to ask myself, 'what is the difference between the MTIM and the TPM modules?'  TPM seems to be able to run in free-running mode and with modulus!  So why need a separate modulo timer module?  Also, the TPM module has much more explicit procedures for clearing interrupt flags.

 

At any rate, my MTIM code is as such:

 

  MTIMCLK_CLKS = 0b00;    // select BUSCLK
  MTIMCLK_PS = 0b0111;    // MTIM clock source divided by 128 = 46.875KHz
  MTIMMOD = 0x7F;
  MTIMSC_TOIE = 1;        // enable overflow interrupts


  SPARE1 = 0;           // PTA2
  MTIMSC_TRST = 1;      // clear the counter
  MTIMSC_TSTP = 0;      // start the timer counter

  EnableInterrupts;

  for(;;)
  {
    if (overflow_flag)
    {
      overflow_flag = 0;  // reset flag
      // do something else here
    }
  }

interrupt VectorNumber_Vmtim void IntMtim(void)
{
  SPARE1 = !SPARE1;
  overflow_flag = 1;
  __RESET_WATCHDOG();       // feed the dog
}

Outcomes