AnsweredAssumed Answered

FTM Issue

Question asked by DSPIC MIC on Sep 22, 2017
Latest reply on Sep 25, 2017 by Razvan-nicolae Tilimpea

Hi ,

I am working on FTM module for S32K148 controller. I have initialize the module as Free running counter .as below.

Init_FTM0()
{
  PCC->PCCn[PCC_FLEXTMR0_INDEX] &= 0xFFFFFFFF ^ PCC_PCCn_CGC_MASK;
  PCC->PCCn[PCC_FLEXTMR0_INDEX] |= PCC_PCCn_PCS(6); 
  PCC->PCCn[PCC_FLEXTMR0_INDEX] |= PCC_PCCn_CGC_MASK;
  FTM0->MODE |= FTM_MODE_FTMEN_MASK;                 
  FTM0->MOD = 40000;                                
  FTM0->CNTIN = 0x00;
  FTM0->SC |= FTM_SC_TOIE_MASK   | FTM_SC_PS(0)  FTM_SC_CLKS(3); 
  /* Enable IRQ for FTM0 Over Flow Interrupt */
  NVIC->ISER[(104/32)] = (1 << (104 % 32));   
}

In handler i am just clearing the TOF flag and then toggling the LED as below:

Table of contents

//!Handler For FTM0
void FTM0_IRQHandler (void)
{
    if( FTM0->SC & FTM_SC_TOF_MASK )
    {
        /* Clear TOF flag */
        FTM0->SC &= 0xFFFFFFFF ^ FTM_SC_TOF_MASK; 
        /* Toggle LED */
         PTD->PTOR |= 1<<0;
    }
}

In the above case each time counter over flow the 40000 , interrupt will trigger and control will come to FTM0_IRQHandler () .

now , i want that after the first time when interrupt trigger and FTM0_IRQHandler execute,My FTM0 module got stop after serving the ISR. And Never trigger again. Means not only IRQ but alos FTM0 become disable  .So i modified the IRQHandler as below :

//!Handler For FTM0
void FTM0_IRQHandler (void)
{
    if( FTM0->SC & FTM_SC_TOF_MASK )
    {
        /* Clear TOF flag */
        FTM0->SC &= 0xFFFFFFFF ^ FTM_SC_TOF_MASK; 
        /* Toggle LED */
        PTD->PTOR |= 1<<0;
        FTM0->MODE  &= (~FTM_MODE_FTMEN_MASK);
     /* Disable the IRQ for OverFlow */
     NVIC_ICER[104/32] = NVIC_ICER[110/32]& (1<< (104 % 32));
    }
}

 

 

But , durring debugging i am seeing the counter is still running and FTM0->CNT still increment . I want that it stop.

Could you please , help me here. actually i am little bit confuse which bit should use to stop the FTM0 Module after serving the interrupt. 

 

 

Thanks! 

Outcomes