KE02Z SetCallback IAR tools not working

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

KE02Z SetCallback IAR tools not working

529 Views
davetelling
Contributor I

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.

Tags (3)
0 Kudos
Reply
1 Reply

433 Views
Rick_Li
NXP Employee
NXP Employee

Hi Dave Telling,

I would suggest referring demos comes with FRDM-K20Z, the demos are available at:

Freescale Freedom Development Platform for Ki|Freescale

please click "Get started with the FRDM-KE02Z40M and IAR EWARM" on the right bottom of the above page.

After extract the package, you will see there is an FTM-DEMO. it should helps on your issue.

0 Kudos
Reply