K64F Edge Aligned PWM with FTM: How to change Duty Cycle?

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

K64F Edge Aligned PWM with FTM: How to change Duty Cycle?

Jump to solution
1,886 Views
geeksanon
Contributor I

Hello,

I've poured through App Notes and the User Guide to try and figure out how to change the Duty Cycle on Edge Aligned PWM using an FTM.

Specifically, I'm trying to use FTM2 with the following PE configuration (non KSDK). A PWM signal with the original CnV values is created.

FTM2_1.PNG

FTM2_2.PNG

Like I said, everything works until I try to change the CnV values.

In a loop that fires every 100ms, I have the following:

  int temp = 0;

  temp = FTM2_C0V;

  if(temp < 0x4000){

  FTM2_C0V = temp + 1;

  } else {

  FTM2_C0V = 1;

  }

Using the debugger, FTM2_C0V never changes.

From what I have gathered in app notes, PWM Synchronization can only be used in combine mode. This is not what I want. I want CH0 and CH1 to be independent PWM pins.

How do I get CnV to update?

Any and all thoughts are appreciated.

1 Solution
951 Views
marek_neuzil
NXP Employee
NXP Employee

Hello,

The FTM device allows to work in a simple mode (TPM device compatible mode) that allows "legacy" synchronization of CnV and other registers. The synchronization of the FTM device is described in the chapter 40.4.11 PWM synchronization in the K64 Sub-Family Reference Manual, Rev. 2, January 2014 or in application note AN3729 - Using FlexTimer in ACIM/PMSM Motor Control Applications.

In your case it is important to set the bit FTMEN = 0 (set the FTM mode property to Disabled) and SYNCMODE = 0.

I have verified this case in a simple demo application on the FRDM-K64F, see the attachment. You can check the signal on the connector J1, pins 1 and 3.

If you need the FTM mode enabled (FTMEN = 1) you must use the synchronization, e.g. sw trigger:

- Enable the Software triggering and CnV registers synchronization (SYNCMODE = 1 and SWWRBUF = 1 in FTM2_SYNCONF register).

- Enable Synchronization of Channels 0 and 1 (SYNCEN0 in FTM2_COMBINE).

- Select the loading point - Minimum or Maximum (set the CNTMIN or CNTMAX bit in FTM2_SYNC).

- When you write into any/all CnV register you must set the SWSYNC bit in FTM2_SYNC register (enable trigger).

pastedImage_3.png

I have also created a simple demo application, see the attachment.

Best Regards,

Marek Neuzil

View solution in original post

3 Replies
952 Views
marek_neuzil
NXP Employee
NXP Employee

Hello,

The FTM device allows to work in a simple mode (TPM device compatible mode) that allows "legacy" synchronization of CnV and other registers. The synchronization of the FTM device is described in the chapter 40.4.11 PWM synchronization in the K64 Sub-Family Reference Manual, Rev. 2, January 2014 or in application note AN3729 - Using FlexTimer in ACIM/PMSM Motor Control Applications.

In your case it is important to set the bit FTMEN = 0 (set the FTM mode property to Disabled) and SYNCMODE = 0.

I have verified this case in a simple demo application on the FRDM-K64F, see the attachment. You can check the signal on the connector J1, pins 1 and 3.

If you need the FTM mode enabled (FTMEN = 1) you must use the synchronization, e.g. sw trigger:

- Enable the Software triggering and CnV registers synchronization (SYNCMODE = 1 and SWWRBUF = 1 in FTM2_SYNCONF register).

- Enable Synchronization of Channels 0 and 1 (SYNCEN0 in FTM2_COMBINE).

- Select the loading point - Minimum or Maximum (set the CNTMIN or CNTMAX bit in FTM2_SYNC).

- When you write into any/all CnV register you must set the SWSYNC bit in FTM2_SYNC register (enable trigger).

pastedImage_3.png

I have also created a simple demo application, see the attachment.

Best Regards,

Marek Neuzil

951 Views
geeksanon
Contributor I

Beautiful! Thank you so much. Never in my wildest dreams would I have suspected you had to FTMEN=0 to get it to work without a software trigger. Absolutely excellent write-up and thank you for the sample projects.

0 Kudos
951 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello anon,

You can change the duty at the pwm interrupt function .

And about the PWM configure on PE,  you can refer to here :

Tutorial: PWM with Processor Expert | MCU on Eclipse

And i don't know where you put your this change duty code , please pay attention

pastedImage_1.png

Hope it helps

Alice

0 Kudos