FTM Issue

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

FTM Issue

1,631 Views
yashkumar
Contributor III

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:

    //!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! 

    0 Kudos
    1 Reply

    1,001 Views
    razva_tilimpea
    NXP Employee
    NXP Employee

    Hi,

    If you want to stop the counter you should set SC->CLKS to 0.

    Best regards,

    Razvan

    0 Kudos