FTM PWM - no output

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

FTM PWM - no output

Jump to solution
1,710 Views
tomášpilný
Contributor I

Hello everone,

I'am using MK60N512VMD100 on custom board, with CW v10.6.

I'm having problems with FTM PWM output. At this stage I'm just trying to figure out what will work for me and how to set everything properly. With the code given below I'm not getting any output on expected pin. I've just hooked it up to LED with resistor just to see if it outputs ANYTHING - and it doesn't. At this moment I'm in school measuring the output and it seems to be the same for any combination of MOD, CnV and PS:

MODCnVPSperiodpulse width
FFFFFFFF020 ms10 ms
FFFFF020 ms10 ms
FFFFF720 ms10 ms

And so on. My conclusion is that the PWM signal is not getting through. Can you see where the problem might be ? What have I forgot ? :smileygrin:

Thanks

Tom

SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK; // enable clock for PTA
SIM_SCGC6 |= SIM_SCGC6_FTM0_MASK; // enable clock for FTM0
      
//Edit registers when no clock is fed to timer so the MOD value, gets pushed in immediately
FTM0_SC = 0; // Make sure its Off!
      
PORTA_PCR6 |= PORT_PCR_MUX(3); // FTM0 CH3 minerva 25
GPIOA_PDDR |= (1 << 6); // set as output

FTM0_MODE |= FTM_MODE_WPDIS_MASK; // disable write protection
FTM0_MODE |= FTM_MODE_FTMEN_MASK; // FTM0 enable
          
FTM0_CNT = 0; // counter initialization
FTM0_MOD = FTM_MOD_MOD(0xFFFF);
FTM0_CNTIN = 0;

   

FTM0_C3SC = 0x20; // edge aligned PWM MSB = 1

   

FTM0_C3V = 0xFFFF; // when the CNT reaches this value -> FTM does what CnSC tells (clear)

   

FTM0_CONF |= FTM_CONF_BDMMODE(3); // run in debug mode

   

FTM0_SC |= FTM_SC_CLKS(0x01); // Select the system clock => turn on the FTM
Labels (1)
0 Kudos
1 Solution
933 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, I think your code has something wrong, anyway, the FTM0_C3V register value should be less than the FTM0_MOD so that PWM can output a low-high interleaved signal, unfortunately, you set both FTM0_C3V and FTM0_MOD as 0xFFFF; that is why you get the constant logic on the FTM channel.

Pls update the code as:

FTM0_C3SC = 0x28; //MSB:MSA=10, ESB:ESA=10,high low

    FTM0_MOD = FTM_MOD_MOD(0xFFFF);

FTM0_C3V = 0x7FFF; // when the CNT reaches this value -> FTM does what CnSC tells (clear)

pls have a try.

BR

XiangJun Rong

View solution in original post

0 Kudos
2 Replies
934 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, I think your code has something wrong, anyway, the FTM0_C3V register value should be less than the FTM0_MOD so that PWM can output a low-high interleaved signal, unfortunately, you set both FTM0_C3V and FTM0_MOD as 0xFFFF; that is why you get the constant logic on the FTM channel.

Pls update the code as:

FTM0_C3SC = 0x28; //MSB:MSA=10, ESB:ESA=10,high low

    FTM0_MOD = FTM_MOD_MOD(0xFFFF);

FTM0_C3V = 0x7FFF; // when the CNT reaches this value -> FTM does what CnSC tells (clear)

pls have a try.

BR

XiangJun Rong

0 Kudos
933 Views
mjbcswitzerland
Specialist V

Tom

Below is code showing how to set up a PWM signal on the output that you are interested in.

This is API code:

PWM_INTERRUPT_SETUP pwm_setup;

pwm_setup.int_type = PWM_INTERRUPT;

pwm_setup.pwm_mode = (PWM_SYS_CLK | PWM_PRESCALER_16); // clock PWM timer from the system clock with /16 pre-scaler

pwm_setup.pwm_reference = (_TIMER_0 | 3); // timer module 0, channel 3

pwm_setup.pwm_frequency = PWM_TIMER_US_DELAY(TIMER_FREQUENCY_VALUE(1000), 16);// generate 1000Hz on PWM output

pwm_setup.pwm_value   = _PWM_PERCENT(20, pwm_setup.pwm_frequency); // 20% PWM (high/low)

fnConfigureInterrupt((void *)&pwm_setup); // enter configuration for PWM test

and this is the low level code that performs the actual work (I have also noted the HEX values that are actually written to the FTM registers)

POWER_UP(6, SIM_SCGC6_FTM0); // ensure that the FlexTimer module is powered up

_CONFIG_PERIPHERAL(A, 6, (PA_6_FTM0_CH3 | PORT_SRE_FAST | PORT_DSE_HIGH)); // FTM0_CH3 on PA.6 (alt. function 3)

ptrFlexTimer->FTM_channel[ucChannel].FTM_CSC = FTM_CSC_MS_ELS_PWM_HIGH_TRUE_PULSES; // FTM0_C3SC = 0x28

ptrFlexTimer->FTM_CNTIN = 0;

ptrFlexTimer->FTM_MOD = (ptrPWM_settings->pwm_frequency - 1); // set the PWM period - valid for all channels [0xc34]

ptrFlexTimer->FTM_channel[ucChannel].FTM_CV = ptrPWM_settings->pwm_value; // set the duty cycle for the particular channel [0x271]

ptrFlexTimer->FTM_SC = (ptrPWM_settings->pwm_mode & PWM_MODE_SETTINGS_MASK); // note that the mode is shared by all channels in the flex timer [0x0c]

Finally here is screen shot of the FTM registers after the configuration so that you can compare with yours and seen if there is something missing or different:

pastedImage_2.png

Regards

Mark

Kinetis: µTasker Kinetis support

K60: µTasker Kinetis TWR-K60N512 support / µTasker Kinetis TWR-K60D100M support / µTasker Kinetis TWR-K60F120M support

PWM: http://www.utasker.com/docs/uTasker/uTaskerHWTimers.PDF

For the complete "out-of-the-box" Kinetis experience and faster time to market

0 Kudos