K60 Flextimer Interrupt

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

K60 Flextimer Interrupt

937 Views
broccolee
Contributor III

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.

0 Kudos
3 Replies

350 Views
charlesasquith
NXP Employee
NXP Employee

Hey Dao,

What I believe may be happening here is that the MCU is going to a predefined "default" ISR function. You'll need to overwrite this default function by naming your ISR function the same thing. It should then recognize your function as the new "default" ISR.

For example, if I were using the flextimer on the K21F120MA, and want interrupts on faults, overflows, and channel interrupts, then I would look in the "startup_MK21FA12.s" for the IRQ handler.

After some looking, I've found FTMx_IRQHandler, which means that if I make a function with the same name, then it should override the default ISR function.

Hope this helps,
Charles

0 Kudos

350 Views
broccolee
Contributor III

Thanks Charles, it works now! I looked at the 'kinetis_sysinit.c' and nothing has been specified at all in the interrupt vector table. For instance, the vectors are all named: UASSIGNED_ISR. So I replaced the appropriate vector with my FTM_isr function.

0 Kudos

350 Views
charlesasquith
NXP Employee
NXP Employee

Great! Glad I could help.

Charles

0 Kudos