FTM Channel Flag: Set only when interrupts are enabled?

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

FTM Channel Flag: Set only when interrupts are enabled?

1,019 Views
aberger
Contributor V

I am using an ISR to handle both timer overflow events and rising edge captures for an FTM module. Therefore, inside the ISR, I need to check the FTM flags to identify the source of the interrupt. That is, the first thing I do inside the ISR is:

bool overflow = (FTM_GetStatusFlags(FTM0) & kFTM_TimeOverflowFlag) == kFTM_TimeOverflowFlag;
bool caughtEdge = (FTM_GetStatusFlags(FTM0) & kFTM_Chnl0Flag) == kFTM_Chnl0Flag;

My question: is the channel flag set even when interrupts for that channel are disabled? In other words, in instances when I only have the overflow interrupt enabled, will the channel flag still be set if an edge is detected on that channel? If so, this means that the ISR will be handling both overflows and channel edge detects, even though I have the edge detect interrupts disabled.

Labels (1)
0 Kudos
5 Replies

694 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Andy,

   If you enable the CHIE in the FTMX_CnSC, it will allow the channel interrupt.

  If you enable the TOIE in FTMx_SC, it will allow the FTM overflow interrupts.

 Otherwise, if you just enable FTMx_SC[TOIE], and didn't enable the CHIE, your CHF, channel interrupt flag won't set.

Wish it helps you!

  Next time, when you post the question, please also tell us what the chip part number you are using, it will be useful to our question checking.


Have a great day,
Kerry

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

0 Kudos

694 Views
aberger
Contributor V

Hi Kerry,

Thanks for the reply. I am using a K64.

What you've described is not consistent with my experience. I do not have the CHIE enabled, and yet the CHF interrupt flag is being set by a rising edge on the channel pin. Why would that be?

0 Kudos

694 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Andy,

    If you don't enable the CHIE, your interrupt is not caused by the Channel match interrupt, this interrupt should caused by the FTM counter overflow. CHF will be set when an event occurs on the channel, even you don't enable the interrupt, this bit also can be set. When you enter the interrupt, you also can check TOF, whether it is set or not?


Have a great day,
Kerry

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

0 Kudos

694 Views
aberger
Contributor V

Yes, I am also checking the TOF, as you can see from the first line of code in my original question. However, there are instances in which the interrupt service routine needs to handle both an overflow event and a channel event, so it's not necessarily true that if an overflow occurred, a channel event did not. I need to check both flags. 

However, there are other instances when I don't care about the channel events. So it seems that when checking for channel events in the ISR, I need to check both:

1. is the CHF set?

2. is CHIE enabled?

0 Kudos

694 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Andy,

    If you want the channel match interrupt, you need to enable CHIE, because this will also caused the interrupt event when the interrupt happens.

  In the ISR you can write:

void FTM_ISR(void)

{

     if(TOF)

    {

       //clear TOF, and do the overflow things

   }

   if(CHF)

  {

     // clear CHF, and do the channel match things.

  }

}

But if you don't want to enable CHF, I think you even don't need to check it directly in the interrupt, because the interrupt won't caused by the CHF, you can check it directly in the main while.

From your description, you said you need to check both the overflow event and a channel event, I highly suggest you also enable the CHIE.

Wish it helps you!


Have a great day,
Kerry

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

0 Kudos