AnsweredAssumed Answered

KE02Z SetCallback IAR tools not working

Question asked by Dave Telling on Dec 4, 2014
Latest reply on Dec 4, 2014 by rickli

I'm doing a project that uses FTM2 for a variety of timing functions, and having finally worked through some noob startup issues, thought I had a good handle on using the FTM's.

However - I have set up my FTM2 for two capture channels, and one compare channel, set the clock to /4, and used the FTM_SetCallback function to tell the code where the ISR should be for FTM2

interrupts.

Unfortunately, the code keeps going to the default ISR, instead of my ISR code, and I can't figure out why. I used essentially identical code to set up the ISR on a different project, and it works just fine.

I'm not sure where to look, as I do not have the familiarity to know where to look. I can see that my code calls the SetCallback function, but cannot access whatever data are being passed.

Here's what I have:

 

FTM_InputCaptureInit(FTM2,FTM_CHANNEL_CHANNEL0,FTM_INPUTCAPTURE_RISINGEDGE);

  FTM_InputCaptureInit(FTM2,FTM_CHANNEL_CHANNEL1,FTM_INPUTCAPTURE_RISINGEDGE);

  FTM_OutputCompareInit(FTM2,FTM_CHANNEL_CHANNEL2,0); /* FTM2 CH2 is virtual tooth count */

  FTM_EnableOverflowInt(FTM2); // allow overflow interrupts

   /* set clock source and start the counter */

  FTM_ClockSet(FTM2, FTM_CLOCK_SYSTEMCLOCK, FTM_CLOCK_PS_DIV4); // 200ns period

  /* set MOD value */

  FTM_SetModValue(FTM2,0);

    /* set callback function for ISR */

  FTM_SetCallback(FTM2, FTM2_Task);

    FTM_ClrChannelFlag(FTM2, FTM_CHANNEL_CHANNEL0);

    FTM_ClrChannelFlag(FTM2, FTM_CHANNEL_CHANNEL1); 

    /* Allow FTM2 interrupts now */

    NVIC_EnableIRQ(FTM2_IRQn);

 

My ISR function is pretty long, so I've just put the first few lines:

 

/* FTM2_Task handles crank input on channel 0, cam input on channel 1,

virtual tooth count on channel 2. Overflow is last */

void FTM2_Task(void)

{

  static uint32_t perDifference;

  static uint16_t tempValue;

  static uint16_t FTM1_Value;

 

  static union tempRpm

  {

    twoInt rpmStruct;

    uint32_t rpmLong;

  }tempRpm;

 

  if (FTM_GetChannelFlag(FTM2, 0)) // if channel 0, crank int

  {

 

 

I have a series of "if" statements that look for the various interrupt flags. However, this function is never accessed, even though if I halt my code, I can see that the interrupt bits for FTM2 are correctly set. I found that all FTM2 interrupts were going instead to the default ISR handler in "vectors.c".

If there are any IAR gurus who might be able to help here, I'd appreciate it.

Outcomes