- Home
- :
- Product Forums
- :
- S32K
- :
- Re: How to calculate the duty cycle and frequency ...

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

SOLVED

11-25-2020
07:53 PM

221 Views

1090097669

Contributor IV

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

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.

1 Solution

11-27-2020
03:26 AM

206 Views

PetrS

NXP TechSupport

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

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

2 Replies

11-27-2020
03:26 AM

207 Views

PetrS

NXP TechSupport

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

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

Sunday

31 Views

linglei_meng

Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

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.