K60 Input Capture

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

K60 Input Capture

1,173 Views
FeiYang
Contributor I

Hi! All:


I am using one of the K60 Flex Timer (FTM) modules to act as Input Capture,and the only setup for the FTM I do is:

void FTM_InputCapture_init( void )
{   
     SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK;
     PORTA_PCR4 |= PORT_PCR_MUX(0x3);  //引脚PTA4设置为 FTM0_CH1功能
      FTM0_C1SC &= ~FTM_CnSC_CHF_MASK;
      FTM0_C1SC |= FTM_CnSC_CHIE_MASK;
      FTM0_C1SC &= ~FTM_CnSC_MSB_MASK;          
      FTM0_C1SC &= ~FTM_CnSC_MSA_MASK;   
      FTM0_C1SC |= FTM_CnSC_ELSB_MASK;   //下降沿触发
      FTM0_C1SC &= ~FTM_CnSC_ELSA_MASK;
      FTM0_SC |=FTM_SC_CLKS(0x01);
      FTM0_SC |=FTM_SC_PS(2);
       
      FTM0_MODE &= ~FTM_MODE_FTMEN_MASK;  
      
      FTM0_COMBINE=0;      //DECAPEN=0,双边沿捕捉禁止,COMBINE=0,不级联
      FTM0_C1SC &= ~FTM_CnSC_CHIE_MASK;

      enable_irq (62);
}

However,it doesn't work;it is unable to enter the interrupt program.What am I doing wrong?

0 Kudos
4 Replies

477 Views
konrada
Contributor IV

After a quick look,

  1. FTM needs running FTM clock for almost everything, esp. before you can write channel registers, so move FTM0_SC accesses to the front.
  2. Have you set the SIM_SCGC bit for FTM0 somewhere? You'll get a fault if not.
  3. Try setting related bits of the same register at once, otherwise, the FTM will spend short timespans between your lines in funny configurations.
  4. You seem to be disabling the channel interrupt in the last line before enable_irq.
0 Kudos

477 Views
markz
Contributor I

Hellou guys,

i have problem with input capture.i have same MCU.

Interrupt work fine, but i cant rest FTM_CnV register to 0. In every interrupt in debug mode value in CnV register increase value by "10" .. e.g. 3423, 3433, 3443 etc. Input to PTA pin is stable 1kHz signal. Please where is wrong?

0 Kudos

477 Views
adriansc
Contributor IV

Hi Mark,

Are you having the same problem when is not in debug mode? I mean, maybe when an interrupt appears is because a rising or falling edge, and this edge will be lost when you read CnV register in debug mode.

Regards.

0 Kudos

477 Views
Futte
Contributor II

Wish register are the value comming out to, i can not geth it?

0 Kudos