AnsweredAssumed Answered

How do I configure FTM2_IRQHandler in K64F?

Question asked by luizfelipe on May 3, 2017
Latest reply on May 4, 2017 by luizfelipe

Hi, could anyone help me? I am having trouble to configure FTM2 interrupt. I am using the code below without success. My objective is to configure FTM2 in capture mode so I need to analyse in the interrupt function when the two rising edges occurred and when the counter overflow occurred.

 

And I have a doubt: when do I use FTM2_IRQHandler and FTM2_ISR? What's the difference?

 

 

FTM2_MODE|=0x04; //WPDIS=1    Write protection is disabled.

FTM2_C0V = 0x0000;
FTM2_C1V = 0x0000;

FTM2_SYNCONF |= 0x0280;

FTM2_QDCTRL &= 0xFFFFFFFE;

FTM2_SC &= 0xFFFFFFDF;

FTM2_CNTIN = 0x0000;

FTM2_MOD = 0xFFFF;

FTM2_CONF=0xC0; //BDMMODE=11    Functional mode, CH(n)F Bit can be set
                        //NUMTOF = 0000 The TOF bit is set for each counter overflow.
                        //GTBEEN=0    Use of an external global time base is disabled.
                        //GTBEOUT=0    A global time base signal generation is disabled.

 FTM2_MODE|=0x01;    // FTMEN = 1    All registers including the FTM-specific registers (second set of registers)
                        //are available for use with no restrictions.

 FTM2_COMBINE |= 0x04;    // DECAPEN0 = 1    Dual Edge Capture Mode Enable For n = 0
                                //The Dual Edge Capture mode in this pair of channels is enabled.
                                //Enables the Dual Edge Capture mode in the channels (n) and (n+1). This bit reconfigures the function                                 // of
                                //MSnA, ELSnB:ELSnA and ELS(n+1)B:ELS(n+1)A bits in Dual Edge Capture mode

FTM2_COMBINE |= 0x0020;

FTM2_FILTER = 0x07;

FTM2_C0SC &= 0xFFFFFFEF; // Channel (n=0) Status And Control
                                 // MSA = 0 Dual Edge Capture    One-Shot Capture mode

FTM2_C1SC &= 0xFFFFFFEF; // Channel (n=0) Status And Control
                                     // MSA = 0 Dual Edge Capture    One-Shot Capture mode
FTM2_C0SC &= 0xFFFFFFF7; //ELSB = 0 Rising edge

FTM2_C0SC |= 0x04;    //ELSA = 1 Rising edge

FTM2_C1SC &= 0xFFFFFFF7; //ELSB = 0 Rising edge

FTM2_C1SC |= 0x04;    //ELSA = 1 Rising edge

FTM2_C0SC |= 0x40;    // CHnIE (Channel Interrupt Enable) = 1 Enable channel interrupts.

FTM2_C1SC |= 0x40;    // CHnIE (Channel Interrupt Enable) = 1 Enable channel interrupts.

FTM2_SC |= 0x08;    //Status And Control
                        //TOF=0        FTM counter has not overflowed
                        //TOIE=0    Disable TOF interrupts. Use software polling.
                        //CPWMS=0    FTM counter operates in Up Counting mode.
                        //CLKS=00    No clock selected. This in effect disables the FTM counter.
                        // CLKS=01    System clock
                        //PS=111    Divide by 128

FTM2_C0SC &= 0xFFFFFF7F; //CH(n)F = 0

FTM2_C1SC &= 0xFFFFFF7F; //CH(n+1)F = 1

FTM2_SC |= 0x40; //Habilita TOIE

FTM2_COMBINE |= 0x08;    //DECAP0=1    The dual edge captures are active.
                                    //Enables the capture of the FTM counter value according to the channel (n) input event and the
                                    //configuration of the dual edge capture bits.

Outcomes