Accurate waveform of FTM

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

Accurate waveform of FTM

727 Views
kiyoshimatsuzak
Contributor III

Hi, everyone

 

I made custom boards with K64.

I connected stepper motors to FTM0, 1 ,2.

I use FTM driver in Kinetis Platform Library.

I set 500Hz to 10000Hz to each FTM.

 

I need accurate waveform from FTMs.

I checked the waveform by my Oscilloscope, and waveform was not accurate.

 

For example, I measured pulses of waveform during a second.

I set 10000Hz to FTM > I got 9948 pulses.

I set 3500Hz to FTM > I got 3500 pulses. It was OK.

I set 2000Hz to FTM > I got 4021 pulses.

 

These are not enough for me.

How can I get more accurate waveform?

 

 

Some parts of my test code are below.

(FTM0,1,2 use same parameters)

 

-----------------------------------------------------------------------------------------------------------

 

// parameters

ftm_pwm_param_t ftm0param =

{

    .mode                   = kFtmEdgeAlignedPWM,

    .edgeMode               = kFtmLowTrue,

    .uFrequencyHZ           = 10000,

    .uDutyCyclePercent      = 50,

    .uFirstEdgeDelayPercent = 0,

};

 

// Clock setting

g_xtal0ClkFreq = 50000000U;

g_xtalRtcClkFreq = 32768U;

BOARD_ClockInit();

 

// FTM setting

FTM_DRV_SetClock(FTM0, kClock_source_FTM_SystemClk, kFtmDividedBy128);

FTM_DRV_SetClock(FTM1, kClock_source_FTM_SystemClk, kFtmDividedBy128);

FTM_DRV_SetClock(FTM2, kClock_source_FTM_SystemClk, kFtmDividedBy128);

 

// Clock start

FTM_DRV_PwmStart(FTM0, &ftm0param, CH0);

FTM_DRV_SetTimeOverflowIntCmd(FTM0, 1);

 

-----------------------------------------------------------------------------------------------------------

 

If somebody have information, please let me know.

 

Regards,

 

Kiyoshi Matsuzaki

Labels (1)
0 Kudos
Reply
1 Reply

485 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Kiyoshi,

As you know that the K64 system clock can be from the 32KHz internal reference clock(IRC) plus FLL or external crystal plus PLL, I suppose that you use 32KHz IRC and use FLL to multiply the clock to 20Mhz in default configuration, I do not know your function BOARD_ClockInit();.The internal 32KHz is not accurate and the FLL may have jitter, so it is possible there is some difference for the actual PWM output signal frequency and the expected PWM signal frequency, for example 10Khz PWM signal becomes 9948Hz, but it can not have so large difference for example 2Khz PWM signal becomes 4.021KHz.. Not in some case, the oscilloscope is inaccurate if you do not calibrate it for a long time, in the case, I suggest you use frequency meter.

For the  code which can output 2KHz PWM signal(you output 4KHz PWM signal actually as you said), pls check the FTM_SC and FTM_MOD registers, as you know that the FTM is only a divider. the PWM output signal frequency=(FTM clock source frequency)/[PS*FTM_MOD] for edge-alignment PWM signals. For center-alignment PWM output, the PWM output signal frequency=(FTM clock source frequency)/[2*PS*FTM_MOD]. The FTM clock source frequency is the clock source specified in CLKS bit in FTM_SC, the PS is prescaler  specified in the PS bits in FTM_SC, the FTM_MOD is the value in the FTM_MOD. The CPWMS in FTM_SC determines the edge-alignment PWM signal or center-alignment PWM signals.

You can check the FTM_SC and FTM_MOD value in debugger of tools you are using for Kinetis.

If you want accurate PWM signal,  I suggest you use external crystal/external clock source and use PLL multiplying the clock frequency as system/core clock. You can connect external clock source to the FTM_CLKINx pin as FTM clock source directly.

Hope it can help you.

BR

XiangJun Rong

0 Kudos
Reply