AnsweredAssumed Answered

FTM settings on KEA

Question asked by Hani Samara on Feb 16, 2017
Latest reply on Feb 20, 2017 by Hani Samara

Hello all,

i am trying to setup the FTM modul to generate 50us interrupt. The FTM works with 48MHz and i select a prescaler of 64. that means the timer has a period of 1.3333us. So to have 50us i shoul set the channel counter (FTMx_CxV) to 37. But what i measure is an 25us interrupt?? it looks like the FTM clock source is 24MHz and not 48MHz! here ist hte Clock setting and the FTM init code:

 

void clk_init(void){   
    ICS_C2 |=ICS_C2_BDIV(1);    /* default BDIV=2 */                                                           
    SIM_CLKDIV = (SIM_CLKDIV_OUTDIV1(0x00) | SIM_CLKDIV_OUTDIV2_MASK); /* core clk 48MHz, Bus clk 24MHz,    Timer clk 48MHz */
    ICS_C1 |=ICS_C1_IRCLKEN_MASK; /* Enable the internal reference clock */                                                            
    ICS_C1 |=ICS_C1_IREFS_MASK;    /* select internal clock as source for FLL */
    ICS_C1 |= ICS_C1_CLKS(0);    /* select FLL output as source for Bus frequency */
  

    ICS_C2 |= ICS_C2_BDIV(0);  /* BDIV = 1 */
    ICS_C2 &= ~(uint8_t)ICS_C2_LP_MASK;
   
    OSC_CR = 0x00U; /* disable OSC Module */
    while((ICS_S & ICS_S_IREFST_MASK) != 0x10U) { /* Check that the source of the FLL reference clock is the internal         reference clock. */
    }
    while((ICS_S & 0x0CU) != 0x00U) {    /* Wait until output of the FLL is selected */
    }
}

 

void FTM2_Init(void){

    SIM_SCGC |= SIM_SCGC_FTM2_MASK;    /* enable clock for FTM0 _Freescale_*/
    FTM2_SC |= FTM_SC_PS(6);    /* select prescaler -> 64 _Freescale: Value adjusted_*/
    FTM2_C0SC |= FTM_CnSC_CHIE_MASK; /* enable channel 0 interrupt _Freescale_*/
    FTM2_C0SC |= FTM_CnSC_MSA_MASK; /* channel works in output compare mode _Freescale_*/
    FTM2_C0V = 37;    /* every 50µs */    
    FTM2_SC  |= FTM_SC_CLKS(1);    /* FTM0 uses system clock _Freescale_*/
}

 

what could be the problem? if i assume that the Timer clk is 24MHz every thing works fine.

thank you for helping.

Hani

Outcomes