Setting up FlexTimer on MK20DX256VMD10

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

Setting up FlexTimer on MK20DX256VMD10

Jump to solution
1,462 Views
derekdrost
Contributor III

Hello,

     I am trying to set up PWM on the above processor using the FlexTimer.

     I've attempted to use the code from this thread:

          K60 FlexTimer (PWM) Example Code?

   

     With this code I get 3 outputs turning on.

Thank you,

Derek

Tags (4)
0 Kudos
1 Solution
823 Views
soledad
NXP Employee
NXP Employee

Hi Derek

The FlexTimer (FTM) on Kinetis MCU is built upon a very simple timer, HCS08 Timer PWM Module (TPM), used for many years on Freescale 8-bit microcontrollers. The FTM extends the functionality of TPM to meet demands of motor control applications. A simple PWM code can be as simple as shown below:

/*Using FTM2_CH0 FTM2_CH1 output PWM with 90% high, 10% low wave*/

void FTM_EPWM(void)

{

PORTA_PCR10 = (0|PORT_PCR_MUX(3)); /* FTM2_CH0 enable on PTA10 */

PORTB_PCR18 = (0|PORT_PCR_MUX(3)); /* FTM2_CH0 enable on PTB18 */

PORTA_PCR11 = (0|PORT_PCR_MUX(3)); /* FTM2_CH1 enable on PTA11 */

PORTB_PCR19 = (0|PORT_PCR_MUX(3)); /* FTM2_CH1 enable on PTB19 */

FTM2_MOD = 0x0063;  /* 0x0063 / 25MHz = 4uS PWM period */

      /* Configure timers for edge aligned PWM High True Pulses */

      printf("FTM2_ Edge_Aligned Test 1\r\n");

      printf("Please check the waveform, 90% Hign Ture EPWM\r\n");

      FTM2_C0SC = 0x28;   /* No Interrupts; High True pulses on Edge Aligned PWM */

      FTM2_C1SC = 0x28; 

      FTM2_C0V = 0x005A;  /* 90% pulse width */

      FTM2_C1V = 0x005A; 

      FTM2_SC = 0x08;     /* Edge Aligned PWM running from BUSCLK / 1 */

}

Are you using MQX???


Have a great day,
Sol

--------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
6 Replies
824 Views
soledad
NXP Employee
NXP Employee

Hi Derek

The FlexTimer (FTM) on Kinetis MCU is built upon a very simple timer, HCS08 Timer PWM Module (TPM), used for many years on Freescale 8-bit microcontrollers. The FTM extends the functionality of TPM to meet demands of motor control applications. A simple PWM code can be as simple as shown below:

/*Using FTM2_CH0 FTM2_CH1 output PWM with 90% high, 10% low wave*/

void FTM_EPWM(void)

{

PORTA_PCR10 = (0|PORT_PCR_MUX(3)); /* FTM2_CH0 enable on PTA10 */

PORTB_PCR18 = (0|PORT_PCR_MUX(3)); /* FTM2_CH0 enable on PTB18 */

PORTA_PCR11 = (0|PORT_PCR_MUX(3)); /* FTM2_CH1 enable on PTA11 */

PORTB_PCR19 = (0|PORT_PCR_MUX(3)); /* FTM2_CH1 enable on PTB19 */

FTM2_MOD = 0x0063;  /* 0x0063 / 25MHz = 4uS PWM period */

      /* Configure timers for edge aligned PWM High True Pulses */

      printf("FTM2_ Edge_Aligned Test 1\r\n");

      printf("Please check the waveform, 90% Hign Ture EPWM\r\n");

      FTM2_C0SC = 0x28;   /* No Interrupts; High True pulses on Edge Aligned PWM */

      FTM2_C1SC = 0x28; 

      FTM2_C0V = 0x005A;  /* 90% pulse width */

      FTM2_C1V = 0x005A; 

      FTM2_SC = 0x08;     /* Edge Aligned PWM running from BUSCLK / 1 */

}

Are you using MQX???


Have a great day,
Sol

--------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
------------------------------------------------------------------------------------------------------------------

0 Kudos
823 Views
derekdrost
Contributor III

Thank you for the reply,

     Yes I am using MQX 4.0.

     I used your code, replacing your pins with the correct ones in my case.

     However, I get directed to the kernel interrupt handler with the following line:

     FTM2_MOD = 0x0063;  /* 0x0063 / 25MHz = 4uS PWM period */

Any thoughts?

0 Kudos
823 Views
soledad
NXP Employee
NXP Employee

hi,

If you are using MQX then it is necessary to be careful in case interrupts are needed for FTM application. There are two ways to add user interrupts into an MQX system - kernel_isr or MQX managed isr.

Kernel_isr is fast but it bypasses MQX, thus, no MQX API function can be called from such a kernel_isr.

MQX managed isr is slower, as it runs dispatcher in case a higher priority task becomes ready during isr.

Attached you can find an example using interrupts, you can use this, in order to develop your own application


Have a great day,
Sol

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
823 Views
derekdrost
Contributor III

Soledad,

     I guess I'm more interested in why this line doesn't work. Curious, why do you use FTM2, when in most of the examples I see around the internet use FTM0?

Cheers,

Derek

0 Kudos
823 Views
derekdrost
Contributor III

Never mind, got it working =) thank you for the help!

0 Kudos
823 Views
davidtietz
Contributor III

Derek,

What did you do to get this working? I am having a similar issue.

Thanks!

0 Kudos