FTM timing interrupt - Period No Change

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

FTM timing interrupt - Period No Change

631 Views
luchaolong
Contributor II

How to simply get a predicable timing interrupt by using FTM?

But no matter how I adjusted the C0V value, the period what I could get was ~10us.

Could you please help check the following classic code and advice what else to change?

    /* Enable Clock for FTM1 */
    SIM_SCGC |= SIM_SCGC_FTM1_MASK;
    /* Select Timer Prescale equal to 128, 16MHz/128 = 125kHz */
    FTM1_SC |= FTM_SC_PS(7);   
    /* Enable Channel 0 */
    /* Enable channel 0 interrupt */
    FTM1_C0SC |= FTM_CnSC_CHIE_MASK;
    /* Channel as Output compare mode */
    FTM1_C0SC |= FTM_CnSC_MSA_MASK;
    /* Interrupt every 8us * 30 = 240us ? */
   FTM1_C0V = FTM_CnV_VAL(30);
    /* FTM1 use system clock */
    FTM1_SC |= FTM_SC_CLKS(1);

    /* Set the ICPR and ISER registers accordingly */
    NVIC_ICPR |= 1 << ((INT_FTM1-16)%32);
    NVIC_ISER |= 1 << ((INT_FTM1-16)%32);

Tags (2)
0 Kudos
2 Replies

506 Views
luchaolong
Contributor II

But interesting, another module FTM0 (same channel) works well.

FTM0's configurations are the same as FTM0's, except the name difference.

0 Kudos

506 Views
luchaolong
Contributor II

Well, so embarrassed that I forgot to fresh the counter.

It's done.

The case can be closed.

(void)FTM1_C0SC;                  /* Read to clear flag */
    FTM1_C0SC ^= FTM_CnSC_CHF_MASK;     /* Clear flag */
    FTM1_C0V = FTM1_C0V + 30 ;      /* Refresh interrupt period */

0 Kudos