Hi,
I am trying to measure frequency using FTM without triggering interrupt for each rising edge. I am measuring 2 signals on PTD0 and PTE4 using FTM0 CH2 and FTM2 CH2 respectively.
Should I mux PTD0 and PTE4 to clk of FTM0 and FTM2 respectively? or to the channels?
I have above configuration for pins and ftm.
I am using ftm3 for polling the ftm0 and ftm2.
I am not getting correct values for pulse_count in the handler.
For testing I am supplying PTD0 with 1khz, 3vpp and 1.5v offset signal.
I doubt gpio is not mapped correctly.
#define INST_FTM_MEASURE_IN1 0U
#define INST_FTM_MEASURE_IN2 2U
#define INST_TIMER_TICK 3U
static pin_settings_config_t g_gpio_mux_config[] = {
{
.base = PORTD,
.pinPortIdx = 0,
.pullConfig = PORT_INTERNAL_PULL_NOT_ENABLED,
.driveSelect = PORT_LOW_DRIVE_STRENGTH,
.passiveFilter = false,
.mux = PORT_MUX_ALT2,
.pinLock = false,
.intConfig = PORT_DMA_INT_DISABLED,
.clearIntFlag = false,
.gpioBase = NULL,
.digitalFilter = false,
},
{
.base = PTE,
.pinPortIdx = 4,
.pullConfig = PORT_INTERNAL_PULL_NOT_ENABLED,
.driveSelect = PORT_LOW_DRIVE_STRENGTH,
.passiveFilter = false,
.mux = PORT_MUX_ALT4,
.pinLock = false,
.intConfig = PORT_DMA_INT_DISABLED,
.clearIntFlag = false,
.gpioBase = NULL,
.digitalFilter = false,
},
}
static ftm_user_config_t ftmICConfig = {
.syncMethod = {
},
.ftmMode =FTM_MODE_INPUT_CAPTURE, /* Mode of operation for FTM */
.ftmPrescaler =FTM_CLOCK_DIVID_BY_64, /* FTM clock prescaler */
.ftmClockSource =FTM_CLOCK_SOURCE_EXTERNALCLK, /* FTM clock source */
.BDMMode =FTM_BDM_MODE_01, /* FTM debug mode */
.isTofIsrEnabled =false, /* Interrupt state */
.enableInitializationTrigger =true /* Initialization trigger */
};
static ftm_input_ch_param_t ftmICChannelConfig_IN = {
2, /* Channel id */
FTM_EDGE_DETECT, /* Input capture operation mode */
FTM_RISING_EDGE, /* Edge alignment mode */
FTM_NO_MEASUREMENT, /* Signal measurement operation type */
3U, /* Filter value */
true, /* Filter state (enabled/disabled) */
false, /* Continuous measurement state */
NULL, /* Vector of callbacks parameters for channels events */
NULL /* Vector of callbacks for channels events */
};
static ftm_input_param_t ftmICParamConfig = {
1U, /* Number of channel configurations */
0xFFFF, /* Maximum count value */
&ftmICChannelConfig_IN /* Channels configuration*/
};
static ftm_user_config_t ftmTickConfig = {
.syncMethod = {
.softwareSync = true, /* Software trigger state */
.hardwareSync0 = false, /* Hardware trigger 1 state */
.hardwareSync1 = false, /* Hardware trigger 2 state */
.hardwareSync2 = false,
.maxLoadingPoint = false,
.minLoadingPoint = false,
.inverterSync = FTM_SYSTEM_CLOCK,
.outRegSync = FTM_SYSTEM_CLOCK,
.maskRegSync = FTM_SYSTEM_CLOCK,
.initCounterSync = FTM_SYSTEM_CLOCK,
.autoClearTrigger = false,
.syncPoint = FTM_UPDATE_NOW /* Synchronization point */
},
.ftmMode = FTM_MODE_UP_TIMER, /* Mode of operation for FTM */
.ftmPrescaler = FTM_CLOCK_DIVID_BY_128, /* FTM clock prescaler */
.ftmClockSource = FTM_CLOCK_SOURCE_EXTERNALCLK,
.BDMMode = FTM_BDM_MODE_00,
.isTofIsrEnabled = true,
.enableInitializationTrigger = false
};
/* Timer mode configuration for flexTimer_mc_1 TimerConfig 0 */
static ftm_timer_param_t ftmTimerModeConfig = {
FTM_MODE_UP_TIMER, /* Counter mode */
0, /* Initial counter value */
37500 /* Final counter value */
};
int main()
{
SystemClockInit();
FTM_DRV_Init(3, &ftmTickConfig, &ftmStateTick);
FTM_DRV_Init(INST_FTM_MEASURE_IN1, &ftmICConfig, &state_ess);
FTM_DRV_Init(INST_FTM_MEASURE_IN2, &ftmICConfig, &state_isens);
FTM_DRV_InitInputCapture(INST_FTM_MEASURE_IN1, &ftmICParamConfig_ESS);
FTM_DRV_InitInputCapture(INST_FTM_MEASURE_IN2, &ftmICParamConfig_ISENS);
FTM_DRV_InitCounter(INST_TIMER_TICK, &ftmTimerModeConfig);
FTM_DRV_CounterStart(INST_TIMER_TICK);
while(1)
{
}
}
void FTM3_Ovf_Reload_IRQHandler(void)
{
in1_pulse_count = FTM_DRV_GetCounter(FTM0);
in1_pulse_count = FTM_DRV_GetCounter(FTM2);
FTM_DRV_SetCounter(FTM0, 0);
FTM_DRV_SetCounter(FTM2, 0);
FTM_DRV_ClearStatusFlags(INST_TIMER_TICK, (uint32_t)FTM_TIME_OVER_FLOW_FLAG);
}