How is PWM Frequency being calculated in S32K1xx MCU

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How is PWM Frequency being calculated in S32K1xx MCU

Jump to solution
454 Views
gkunalupta
Contributor III

What is the formula for Calculation of Frequency when using FTM peripheral in EPWM mode using S32K144.

I have configured by FTM Peripheral via System clock and after dividing it by prescaler 8. My FTM peripheral input clock is of: 1Mhz.

gkunalupta_0-1724664374512.png

 

Now what is the formula for calculation of Frequency?

Like in Datasheet, it is mentioned, as shown in below figure.

gkunalupta_2-1724665220537.png

 

What is the units of EPWM period is it secs or us??

Also if I am using EPWM mode, in which I have set counter period (ticks)= 2: Which is MOD register value and duty cycle(ticks) = 1: which is CnV register value.

gkunalupta_1-1724664778229.png   

 

On checking the signals on Logic Analyzer, frequency which comes out is of : 3Mhz. How is this calculated??? Duty cycle is fine. 50 percent am expecting. But how is 3Mhz frequency calculated.

gkunalupta_3-1724665658053.png

 

 

0 Kudos
Reply
1 Solution
382 Views
gkunalupta
Contributor III

Okay, got the issue solved. My FTM Clock source was selected system clock and i was doing calculations with FTM Input clock

View solution in original post

0 Kudos
Reply
3 Replies
383 Views
gkunalupta
Contributor III

Okay, got the issue solved. My FTM Clock source was selected system clock and i was doing calculations with FTM Input clock

0 Kudos
Reply
423 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @gkunalupta,

You can refer to both AN5413: S32K1xx Series Cookbook and AN5303: Features and Operation Modes of FlexTimer Module on S32K application notes. The cookbook configures the Edge-Aligned Pulse Width Modulation (EPWM): 1 Hz, low 25%, high 75%, with the input clock source to 8 MHz.

The edge-align PWM period is determined by the clock source. For example, prescale clock source by 128 (8 MHz / 128 = 62500 Hz), counter count up value is 62500 = 1 second period.

You can also measure the value for the PWM period, as shown in this community post: Solved: How to calculate the duty cycle and frequency of PWM wave based on SDK - NXP Community.

Best regards,
Julián

 

0 Kudos
Reply
409 Views
gkunalupta
Contributor III

I read the above application notes that u mentioned. What I can get from those notes, is that

FTM Period for EPWM mode is = ((MOD - CNTIN) +0x1) counter ticks.

 

I tried the same configurations as well that are mentioned in application note:

FTM clock after prescaler: 8Mhz/128= 62500Hz

 

gkunalupta_0-1724729548658.png

 

Meaning:

1 FTM Counter tick = 1/FTM Clock after prescale = 1/62500Hz = 16us.

That is each increment of counter will take 16us.

 

Now setting the, MOD values as stated in application notes

MOD= 62499 and CNTIN =0.

 

gkunalupta_1-1724729548662.png

So FTM Period = ((MOD - CNTIN) +0x1) = 62500 counter ticks

 

        Meaning, FTM Period = 62500*16 us = 1 sec

                          & FTM Frequency = 1hertz

 

This is what is stated in application note also.

 

But when I run my code and see it on logic analyzer, the Frequency I am getting is of 6 hertz.

gkunalupta_2-1724729548663.png

 

Why is it so??

Is there some formula error or what??

I tried various values as per the calculations/formulas stated in application notes and reference manual. But when i do on S32K144, the signals are observed of different values that are expected.

What i want to achieve is to generate different frequencies from 200Khz to 10 Mhz. For that i want to understand this EPWM frequency calculation part

 

 

 

 

 

 

FTM clock after prescale: 8Mhz/128= 62500Hz

1 Counter tick = 1/FTM Clock after prescale = 1/62500Hz = 16us

 

MOD= 62499 and CNTIN =0 Hz

       So FTM Period = ((MOD - CNTIN) +0x1) = 62500 counter ticks

        Meaning, FTM Period = 62500*16 us = 1 sec

 

 

 

FTM clock after prescale: 8Mhz/1 = 8Mhz

1 Counter tick = 1/8Mhz = 0.125us

 

MOD= 62499 and CNTIN =0 Hz

       So FTM Period = ((MOD - CNTIN) +0x1) = 62500 counter ticks

        Meaning, FTM Period = 62500*.125 us = 7812.5 us

 

 

0 Kudos
Reply