MTIM vs. TPM

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MTIM vs. TPM

Jump to solution
1,521 Views
irob
Contributor V

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
}
Labels (1)
0 Kudos
Reply
1 Solution
712 Views
irob
Contributor V

Ugg, in the time it took me to write all that, I fixed my own problem.  Based on those other links, I made an educated guess and cleared the TOF inside my ISR:

 

 

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}

 

This works great.  Still not too sure on the fine differences between MTIM and TPM modules.  I guess Freescale is just giving us more options.

 

View solution in original post

0 Kudos
Reply
3 Replies
713 Views
irob
Contributor V

Ugg, in the time it took me to write all that, I fixed my own problem.  Based on those other links, I made an educated guess and cleared the TOF inside my ISR:

 

 

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}

 

This works great.  Still not too sure on the fine differences between MTIM and TPM modules.  I guess Freescale is just giving us more options.

 

0 Kudos
Reply
712 Views
bigmac
Specialist III

Hello irob,

 

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.

 

MTIMSC_TOF = 0;    // This is actually a read-modify-write operation

 

I think that I am correct in saying that the MTIM module is provided within those devices that contain only a single TPM module.  I guess the issue is that, if PWM operation is required at a reasonably high, and maybe variable output frequency, this may cause much inconvenience in using the TPM overflow interrupt for other timing purposes, since the overflow period may be too short.  If a device has a second TPM module, there would be less need for the MTIM module.

 

I presume that you are considering the use of the MTIM module for your state maching timing, as outlined in another recent thread.

 

Regards,

Mac

 

0 Kudos
Reply
712 Views
irob
Contributor V

 


bigmac wrote:

 

MTIMSC_TOF = 0;    // This is actually a read-modify-write operation

 


Oh, I didn't realize this.  I don't need to do that extra read, huh?

 

 


I presume that you are considering the use of the MTIM module for your state maching timing, as outlined in another recent thread.

You are correct, sir!  Works nicely, thanks.

 

 

0 Kudos
Reply