In my reading about the FTM it seems that most application notes, articles, websites, and community post discussions are using the FTM for one of a few applications to include motor control, power conversion, and some generic pulse measurement or generation applications. AN4381, AN5083, and AN5142 are among me recently read application notes. I have a use case that is a little different from those in that it needs to tie some of that functionality together, and I thought I would start a discussion having not found an example already shared. Maybe some will noodle out what I'm doing, but I will keep it generic in case there are other similar applications that could benefit from this discussion besides my use case.
This is a basic functional description of my project. First I need to read an input channel that should, under normal conditions, give me a fixed number of pulses within a cycle of the system with a pause in the signal that is 2x the normal pulse period which signals the end of one system cycle and the beginning of the next system cycle. Then the same number of pulses will be input again in a repetitive fashion for each cycle. The period between pulses within a cycle will change. The period of the whole cycle will change within a predictable range. These changes are from physical changes in both acceleration and speed of the system within cycles and from cycle to cycle. For outputs I need to trigger a fixed number of pulses as outputs with variable timing and duty cycle that is synchronized with the the input signals. For example, output pulse 1 needs to end 23% between input pulse 5 and 6. The timing of the output pulses within the cycle will change from cycle to cycle based on software logic. The pulse width of each output pulse will change cycle to cycle based upon software logic. Oh, and output pulse 2 ( on another pin) might need to start before output pulse 1 ends, but only some of the time determined by software logic.
I know how these functional requirements are met using an eTPU found in other devices such as the MPC5674F, but those are quite frankly overkill for my application and the up front investment of both time and money just doesn't make sense for some applications. I think some of the Kinetis devices can fill a need for systems just below those devices.
For this project I'm currently using a TWR-KE18F as the target device. I'm emulating the input signal I described with a FRDM-K64F. The Kinetis Design Studio project for the input signal emulation is attached and uses Processor Expert to get it done quickly. So far I am able to accurately and reliably read in the input signal into the TWR-KE18F without much loading up of the core. The values I'm seeing in debug match what I'm measuring on my scope and what the emulation is supposed to be outputting. I'm using FTM2 Channel 5 on pin 8 of the FLEXIO Header of the TWR-KE18F board. This is working great so far. I think I also have a firm handle on how to generate a PWM type output with the FTM based on the application notes and reference manuals available. The driver examples in the KSDK 2.0 package are also quite helpful.
Where I'm still a little bit fuzzy is figuring out the best way to synchronize a frequently changing PWM output with the somewhat unpredictable input without loading up the core with continuous polling of input values. I could do this through software and tie up the core by frequently polling the FMT counter value, but then there are not enough processor cycles left over to figure out what needs to change in the next cycle. I'm wondering if there is a way to let the FTM handle the synchronization piece with just a cycle to cycle register update rather than a pulse by pulse software polling method. I've read the reference manuals, but I'm looking for examples of cause and effect for some of the perhaps less common register settings to clear up ambiguity. I'm actually using the KSDK 2.0 for this project, but the functions it provides do not quite fit the need. It would be nice if examples were somewhat compatible with KSDK 2.0.
Any help from the community would be appreciated and if I figure out this synchronization piece I will post it here.
Original Attachment has been moved to: K64_CPS_EMULATOR.zip