AnsweredAssumed Answered

KV10Z32 FTM doesn't work

Question asked by Zhi Qu on Sep 25, 2014
Latest reply on Jan 26, 2015 by jeremyzhou

Hi,

 

I'm trying work with Keil uVision 5 on the KV10Z32 board. However, the FTM won't work properly and performs really weird.

 

With the following code, I'm trying to configure TPM0 Ch0 to output a PWM signal on PTE24 and generate interrupt every switching period. However, the FTM would start working and count to some arbitrary value and stop working. I also found that when I enabled ADC and constantly sample with the ADC will enable the FTM counter to work. Besides, even when the FTM0 is counting, I can't even reset the overflow bit in FTM0->SC because that would lead to hard fault handler.

 

I've attached the code. Calling the Init_PWM() in main function doesn't start the FTM counter while calling Init_PWM(), Init_ADC() and then starting ADC with ADC0->SC1[0] = 0x49 will enable the FTM counter.

 

I'm desperate for help with this as I've got stuck on this for whole week.

 

Thanks a lot.

 

void Init_PWM(void)

{

  SIM->SCGC6 |= SIM_SCGC6_FTM0_MASK;

  SIM->SCGC5 |= (SIM_SCGC5_PORTA_MASK

                      | SIM_SCGC5_PORTB_MASK

                      | SIM_SCGC5_PORTC_MASK

                      | SIM_SCGC5_PORTD_MASK

                      | SIM_SCGC5_PORTE_MASK );

  PORTE->PCR[24] = PORT_PCR_MUX(3);

  FTM0->MOD=0xffff;

  FTM0->CONTROLS[0].CnV  = 100;

  FTM0->SC |= FTM_SC_PS(0) | FTM_SC_CLKS(1) | FTM_SC_TOIE_MASK;

  FTM0->CONTROLS[0].CnSC = FTM_CnSC_MSB_MASK | FTM_CnSC_ELSB_MASK;

  NVIC_EnableIRQ(FTM0_IRQn);

}

 

void Init_ADC(void)

{

  SIM->SCGC6 |= (1UL << SIM_SCGC6_ADC0_SHIFT);

  ADC0->CFG1 = 0x8C; // Select 16 bit resolution

  ADC0->SC2 = 0;

  NVIC_EnableIRQ (ADC0_IRQn);

}

 

void FTM0_IRQHandler(){

  NVIC_ClearPendingIRQ(FTM0_IRQn);

  FTM0->SC &= ~FTM_SC_TOF_MASK;

}

 

void ADC0_IRQHandler()

{

  int q;

  NVIC_ClearPendingIRQ(ADC0_IRQn);

  q=ADC0->R[0];

  ADC0->SC1[0] = 0x49;

}

Outcomes