Phil Valentine

K60 FTM - PWM Combine - Adjust CnV whilst running...

Discussion created by Phil Valentine on Jul 3, 2017
Latest reply on Jul 10, 2017 by Hui_Ma

I am not trying to generate a PWM signal, but rather some related pulses to quite fast timings (uS / nS) and the FTM seems to be the most suitable peripheral to do it.

I am running the channels in PWM Combine mode, so (for instance) I have a pin assigned to FT0_CH0; on FTM_CNT == FT0C0V the pin is taken HIGH, and on FTM_CNT == FT0C1V the pin is taken low again.

CH2, 4, & 6 are set similarly in order to give me a set of related signals.

This works well, but after the initial pulses on CH0 and CH6 a need to generate a second pulse of a different width.

 

The required output can be visualized thus:

 

Due to the way I am using the module I do not leave it running indefinitely, rather I start it at the begin of one of the above cycles, and stop it at the end.

 

What is the best way for me to load the new C2V/C3V and C4V/C5V values into the FMT module whilst the timer is running?

 

I can get close to what I need if I interrupt on the falling edge of the C4 signal (so actually on the C5 event), stop the timer, reset CNT to zero, set new values into the timer, and restart it again, but this seems to take quite some time (comparatively speaking), in the order of a few microseconds.

Bizarrely, if use the same interrupt, stop the timer (but don't reset CNT), set up the new pulses to appropriate values (that are in excess of the current CNT value) and restart it the second set of pulses on C0 and C2 never seem to get generated, I am not sure why this is? Can the FTM only trigger one per channel (prior to an overflow?) - I don't see anything documented to this effect?

 

Thanks for any pointers in the right direction!

Outcomes