Use PWM_PAL to generate PWM on FTM0 channels 1, 3, 7 and manually initialize input capture rising edge callback FTM0 channels 2 and 6.
It's clear that from the SDK configuration is not possible to use/configure IC_PAL and PWM_PAL using the same FTM0 peripheral. So, I would like to take the path of configuring the PWM channels using PWM_PAL and manually initialize input capture to detect the rising edge on FTM0 channels 2 and 6.
Please help me know whether it is possible and status = PWM_Init(&pwm_pal_1_instance, &pwm_pal_1_configs); only affects the channels that are configured as PWM (1, 3, and 7) and still, other channels (2 and 6) of FTM0 can be configured as input capture (rising/falling/rising & falling) edge input.
We need these settings based on our project requirements.
Solved! Go to Solution.
You are right, you can not set the ICRST bit, and then you use other timers to record the time of the trigger event. You are free to set it up however you want, but this is not a recommended usage and we have no such routine for you to refer to.
No, this can't be done,
You have to use two different FTM instance for PWM and IC respectively.
I understand its cannot be done directly from SDK configuration.
1. PWM PAL I will configure using the SDK
2. For IC I will create below Init function and I will not add any configuration using SDK GUI:
void FTM0_Ch2_risingedge_cb()
{
/* Rising edge detected for channel 2 */
}
IC_InitFTM0_Channel2(void)
{
uint8_t chnlPairNum = 0U;
chnlPairNum = (uint8_t)(2 >> 1); //for channel 2
/* Disable the dual edge mode */
FTM_DRV_SetDualEdgeCaptureCmd(FTM0, chnlPairNum, false);
/* Set input capture mode */
FTM_DRV_SetChnMSnBAMode(FTM0, 2, 0U);
/* Set the event which will generate the interrupt */
FTM_DRV_SetChnEdgeLevel(FTM0, 2,0x01); //rising edge interrupt
/* Enable interrupt request for the current channel */
FTM_DRV_EnableChnInt(FTM0, 2);
INT_SYS_InstallHandler(FTM0_Ch0_7_IRQn, FTM0_Ch2_risingedge_cb, (isr_t *)0);
INT_SYS_EnableIRQ(FTM0_Ch0_7_IRQn);
}
No , you still can't achieve it,
Is there an alternative way to do this. May be initializing both PWM and IC manually using just C code. Is there any example to do this?
There is not only related to SDK, but also FTM features.
My suggestion is that you need to use two FTM modules to implement the PWM output and Input capture features respectively.
For Input Capture, when a capture event is detected, it will resets the counter, which affects the PWM output.
So it means on every input capture event FTM0_COUNT is reset to 0 which is used commonly by FTM0.
There is a register CnSC which is used by each channel and setting ICRST = 0 should not reset the FTM0_COUNT values. And this should allow usage of input capture using same FTM0 instance.
For input capture we will only need a interrupt call on rising/falling edge and I am calculating frequency using LPTMR by measuring the count between two rising edge.
I need a solution to measure input frequency from FTM0 Channel 2 while having PWM output on FTM0 1, 3 and 7.
Please refer this section
which tells that FTM counter reset can be avoided if ICRST = 0. This will limit IC not to measure period between pulses but still can be used for raising/falling/rising & falling edge detection purpose.
You are right, you can not set the ICRST bit, and then you use other timers to record the time of the trigger event. You are free to set it up however you want, but this is not a recommended usage and we have no such routine for you to refer to.