How to calculate the duty cycle and frequency of PWM wave based on SDK

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How to calculate the duty cycle and frequency of PWM wave based on SDK

ソリューションへジャンプ
3,870件の閲覧回数
1090097669
Contributor III

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

 

タグ(2)
0 件の賞賛
返信
1 解決策
3,855件の閲覧回数
PetrS
NXP TechSupport
NXP TechSupport

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

元の投稿で解決策を見る

0 件の賞賛
返信
2 返答(返信)
3,856件の閲覧回数
PetrS
NXP TechSupport
NXP TechSupport

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

0 件の賞賛
返信
3,680件の閲覧回数
linglei_meng
Contributor II

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.

 

 

0 件の賞賛
返信