Dao Yan Lim

K60 Flextimer Interrupt

Discussion created by Dao Yan Lim on Jul 7, 2016
Latest reply on Jul 8, 2016 by Charles Asquith

Hi,

 

I am using TWR-K60N512, with PK60DN512Z VMD10 chip. I'm trying to use the interrupt to update FTM0_C0V value when the FTM0 timer overflows but my program keeps getting suspended.

 

I have enabled the interrupt vector for FTM0, by adding this line "enable_irq(62);" in the main code. The interrupt vector assignment was found from Chapter 3 in the K60P144M100SF2RM reference manual. I have also enabled timer over flow interrupt 'FTM0_SC |= FTM_SC_TOIE_MASK;' .

 

This is what my ISR.h looks like:

 

#ifndef __ISR_H

#define __ISR_H 1

 

#undef  VECTOR_78

#define VECTOR_78 FTM0_isr

 

// ISR(s) are defined in your project directory.

extern void FTM0_isr(void);

 

#endif  //__ISR_H

 

 

This is what my interrupt function looks like, it is in the main source code. I have declared the function prototype in the main code too:

 

void FTM0_isr(void)

{

  static unsigned short brightness = 0;

  static bool increase = true;

  if (FTM0_SC & 0x80) // if FTM counter exceeds MOD count.

  {

  if (brightness == 60000)

   {

   increase = false;

   }

   else if (brightness == 0)

   {

   increase = true;

   }

  

   if(increase)

   {

   brightness++;

   }

   else

   {

   brightness--;

   }

  FTM0_SC &= 0x7F; // clear TOF flag

  FTM0_C0V = brightness;

  FTM0_PWMLOAD |= FTM_PWMLOAD_LDOK_MASK;

  }

}

 

My program was suspended whenever I run it and points to the following function in 'kinetis_sysinti.c' :

void isr_default(void)

{

  __asm("bkpt");

  /* Write your interrupt code here ... */

}

 

Any idea how to troubleshoot this?

 

Thanks.

Outcomes