AnsweredAssumed Answered

FRDM-K64  FTM measure pulse width

Question asked by yuanhan chen on Jul 15, 2016
Latest reply on Jul 22, 2016 by yuanhan chen

I am trying to measure the percentage of a PWM signal on a FRDM-K64 board. I am using the FTM2 FlexTimer in dual edge capture mode on channels 0-1. I'm getting the interrupts both for the rising and falling edge of the pulses.But after entering the interrupt function, simply enter a rising edge of a subroutine, but there is no falling entered a subroutine, why is there such a situation



#include "board.h" #include "fsl_debug_console.h" #include "pin_mux.h" #include "clock_config.h" #include "fsl_ftm.h" /*******************************************************************************  * Definitions  ******************************************************************************/ /* The Flextimer instance/channel used for board */ #define DEMO_FTM_BASEADDR FTM2   /* FTM channel pair used for the dual-edge capture, channel pair 0 uses channels 0 and 1 */ #define BOARD_FTM_INPUT_CAPTURE_CHANNEL_PAIR kFTM_Chnl_0   /* Interrupt number and interrupt handler for the FTM instance used */ #define FTM_INTERRUPT_NUMBER FTM2_IRQn #define FTM_INPUT_CAPTURE_HANDLER FTM2_IRQHandler   /* Interrupt to enable and flag to read; depends on the FTM channel used for dual-edge capture */ #define FTM_CHANNEL0_INTERRUPT_ENABLE kFTM_Chnl0InterruptEnable   #define FTM_CHANNEL1_INTERRUPT_ENABLE kFTM_Chnl1InterruptEnable   #define FTM_CHANNEL0_FLAG kFTM_Chnl0Flag #define FTM_CHANNEL1_FLAG kFTM_Chnl1Flag   /* Get source clock for FTM driver */ #define FTM_SOURCE_CLOCK CLOCK_GetFreq(kCLOCK_BusClk)   /*******************************************************************************  * Prototypes  ******************************************************************************/   /*******************************************************************************  * Variables  ******************************************************************************/ volatile bool ftmIsrFlag = false; /*******************************************************************************  * Code  ******************************************************************************/ void FTM_INPUT_CAPTURE_HANDLER(void) {     if ((FTM_GetStatusFlags(DEMO_FTM_BASEADDR) & FTM_CHANNEL0_FLAG) == FTM_CHANNEL0_FLAG)     {     PRINTF("\r\n/**********************rasing interrupt****************************\n");         FTM_ClearStatusFlags(DEMO_FTM_BASEADDR, FTM_CHANNEL0_FLAG);     }     if ((FTM_GetStatusFlags(DEMO_FTM_BASEADDR) & FTM_CHANNEL1_FLAG) == FTM_CHANNEL1_FLAG)   {   PRINTF("\r\n/**********************falling interrupt****************************\n");   FTM_ClearStatusFlags(DEMO_FTM_BASEADDR, FTM_CHANNEL1_FLAG);   } }   /*!  * @brief Main function  */ int main(void) {     ftm_config_t ftmInfo;     ftm_dual_edge_capture_param_t edgeParam;     /* Board pin, clock, debug console init */     BOARD_InitPins();     BOARD_BootClockRUN();     BOARD_InitDebugConsole();       /* Print a note to terminal */     PRINTF("\r\nFTM dual-edge capture example\r\n");     PRINTF("\r\nSYSTEM Clock:%d\r\n",CLOCK_GetFreq(kCLOCK_CoreSysClk));     PRINTF("\r\nBUS Clock:%d\r\n",CLOCK_GetFreq(kCLOCK_BusClk));       FTM_GetDefaultConfig(&ftmInfo);     ftmInfo.prescale = kFTM_Prescale_Divide_128;     /* Initialize FTM module */     FTM_Init(DEMO_FTM_BASEADDR, &ftmInfo);       edgeParam.mode = kFTM_Continuous;     //Set capture edges to calculate the pulse width of input signal     edgeParam.currChanEdgeMode = kFTM_RisingEdge;     edgeParam.nextChanEdgeMode = kFTM_FallingEdge;       /* Setup dual-edge capture on a FTM channel pair */     FTM_SetupDualEdgeCapture(DEMO_FTM_BASEADDR, BOARD_FTM_INPUT_CAPTURE_CHANNEL_PAIR, &edgeParam, 0);       /* Set the timer to be in free-running mode */     DEMO_FTM_BASEADDR->MOD = 0xffff;     /* Enable channel interrupt when the second edge is detected */     FTM_EnableInterrupts(DEMO_FTM_BASEADDR, FTM_CHANNEL0_INTERRUPT_ENABLE);     FTM_EnableInterrupts(DEMO_FTM_BASEADDR, FTM_CHANNEL1_INTERRUPT_ENABLE);     /* Enable at the NVIC */     EnableIRQ(FTM_INTERRUPT_NUMBER);       FTM_StartTimer(DEMO_FTM_BASEADDR, kFTM_SystemClock);       while (1)     {     ;     } }

Original Attachment has been moved to: