I am currently developing PWM capture based on the S32K SDK in order to get the duty cycle and frequency of the PWM wave. The component of ic_pal is currently used for calculation, but the effective duty cycle cannot be calculated. There are a few questions about this:
1. With the callbacck function of ic set, can you distinguish between rising and falling edges? How to distinguish between rising edge and falling edge?
2. How to calculate the duty cycle and frequency by count?(FunctioninputCaptureMeas = IC_GetMeasurement(...);) I used an external crystal oscillator 8M, prescaler 8
Solved! Go to Solution.
Hi,
1) no, you have no direct info which edge causes an event, assuming operation mode "detect both edges" is selected. You can try to read channel input state (CHIS bit) and determine based on this. But this could not be valid info, depends when read.
2) IC_GetMeasurement returns captured value of FTM counter at the time edge happens, if edge detect mode is selected ( rising, falling or both edges) or difference of 2 captured value if signal measurement mode is selected (period between 2 rising/falling edges or duty cycle ON/OFF).
Thus could be easy to use one of signal measurement mode or better 2 of them to get period and duty cycle.
To measure period:
- select mode "period between 2 rising (or falling) edges"
- get the FTM frequency to calculate the frequency of the measured signal.
ftm_frequency = FTM_DRV_GetFrequency
- get captured period_count = IC_GetMeasurement
- then signal frequency = ftm_frequency / period_count
To measure duty:
- select mode "duty cycle ON (OFF)"
- get captured duty_count = IC_GetMeasurement
- then signal duty = duty_count / period_count * 100
BR, Petr
Hi,
1) no, you have no direct info which edge causes an event, assuming operation mode "detect both edges" is selected. You can try to read channel input state (CHIS bit) and determine based on this. But this could not be valid info, depends when read.
2) IC_GetMeasurement returns captured value of FTM counter at the time edge happens, if edge detect mode is selected ( rising, falling or both edges) or difference of 2 captured value if signal measurement mode is selected (period between 2 rising/falling edges or duty cycle ON/OFF).
Thus could be easy to use one of signal measurement mode or better 2 of them to get period and duty cycle.
To measure period:
- select mode "period between 2 rising (or falling) edges"
- get the FTM frequency to calculate the frequency of the measured signal.
ftm_frequency = FTM_DRV_GetFrequency
- get captured period_count = IC_GetMeasurement
- then signal frequency = ftm_frequency / period_count
To measure duty:
- select mode "duty cycle ON (OFF)"
- get captured duty_count = IC_GetMeasurement
- then signal duty = duty_count / period_count * 100
BR, Petr
Hello community
To measure period:
- select mode "period between 2 rising (or falling) edges"
- get the FTM frequency to calculate the frequency of the measured signal.
ftm_frequency = FTM_DRV_GetFrequency
- get captured period_count = IC_GetMeasurement
- then signal frequency = ftm_frequency / period_count
To measure duty:
- select mode "duty cycle ON (OFF)"
- get captured duty_count = IC_GetMeasurement
- then signal duty = duty_count / period_count * 100
Is the red font the same variable?
Why does the same function return different values?
period_count = IC_GetMeasurement
duty_count = IC_GetMeasurement
I also want a way to calculate the duty cycle, which I don't understand very well.