Is it possible to use an FTM interrupt on an FTM configured for PWM?

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

Is it possible to use an FTM interrupt on an FTM configured for PWM?

826 Views
dave408
Senior Contributor II

I am using a MK22FN128VLL10 that has 3 FTMs.  2 are currently used for QD, and the other one is used for multiple PWM channels at 20kHz.

I also have a timing requirement related to Modbus RTU, where I have to be able to accurately detect the 3.5 character delay that defines a complete packet (or clearing buffers in the event of transmission errors).

I am currently reading the FTM section of the reference manual and am going to work on the implementation to see if it works.  However, I was hoping that others here with experience trying such a thing would be able to tell me if I'm wasting my time.  My specific question is, using FTM0 that is already configured for PWM, is there a way to configure an ISR to trigger on every overflow, then count the number of overflows that would correspond to 3.5 characters?

The overall idea is to keep my Modbus data in a global buffer, and any time the 3.5 character quiet time has elapsed, signal my Modbus listener task to process the data.  The overflow counter would be reset, as well as FTMx_CNT if that's a valid thing to do (without screwing up the PWM).

Labels (1)
Tags (5)
0 Kudos
2 Replies

582 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

I think your solution is feasible. The FTM0 module can function as both PWM signal  generator and equivalent free-running clock. As you know, the FTM0 can generate the overflow interrupt if you set the TOIE bit in FTM0_SC register when the FTM0 functions as PWM generator , because the FTM0 has only one interrupt vector for all the FTM0 interrupt sources for example, overflow interrupt, capture interrupt, PWM fault interrupt..., in the ISR of FTM0, you can check the interrupt source, if the TOF bit is set in the FTM0_SC register, it is overflow interrupt, you can increase a global variable for example modval by 1. After you receive the first 3 characters, you read the modval as for example modVAL1 and the FTM0_CNT as cntVAL1. When you receive the second 3 characters, you read the modval as for example modVAL2 and the FTM0_CNT as cntVAL2, you can get the delay with the following formula in tick number:

delay=(modVAL2*FTM0_MOD+cntVAL2)-(modVAL1*FTM0_MOD+cntVAL1).

You can read the modval and FTM0_CNT anytime.

Hope it can help you. If I misunderstand you, i am sorry.

BR

XiangJun Rong

582 Views
dave408
Senior Contributor II

Hi XiangJun, thank you for your response.  I'm glad that what I was considering sounds possible.  I was running into some trouble getting the PWM to work in the general case (actually toggling an LED) by setting it up through PEx.


I have a non-timer solution that so far seems promising as an alternative, but I'd like to revisit the FTM implementation soon to see how well it works.  If I keep hitting roadblocks with PWM, I'll post a new question.  Otherwise, I'll report my findings and results here when I have some!

0 Kudos