Kinetist K64 FlexTimer Interrupt Questions

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

Kinetist K64 FlexTimer Interrupt Questions

1,546 Views
Designer11
Contributor IV

Hi All,

I'm trying to understand how to activate the FTM3 overflow Interrupt handlers on the Kinetis K64 microcontroller. I'm able to generate the waveforms for both channels 4 and 5 of the  FTM3.  Everywhere i read it keeps saying i need to add my interrupt handler function name to the "kinetis_sysinit.c" file, located in the startup folder. However, i'm unable to locate such a file anywhere. The closest files i came across that mentioned about interrupt handlers are  either vector.c or vector.h. Below is my test codes on the overflow, but it failed mto work. I'm using KDS IDE for this development.

void FTM3_IRQHandler()
{
     if (FTM3_SC & FTM_SC_TOF_MASK){
          FTM3_SC&=0x7F; //clear TOF bit
          timer_overflow = 0x01;
          pulses_cnt +=1;
     }
}
byte pulse_motor(void)
{

     static word count_pulse = 0x00;
     static pulse_motors pulse_state = INIT_PULSE_DATA;

     switch (pulse_state)
     {
     case INIT_PULSE_DATA:
#if 1
          /*-----------------------------------------------------
           * For FTM 3 channel 4, J1.7  and 5, J1.9  on Port C
           *-----------------------------------------------------*/
          SIM_SCGC3|=0x2000000; //enable FTM3 module clock
          FTM3_CONF=0xC0; //set up BDM in 11
          FTM3_FMS=0x00; //clear the WPEN so that WPDIS is set in FTM0_MODE register
          FTM3_MODE|=0x05; //enable write the FTM CnV register
          FTM3_MOD=1000;
          FTM3_C4SC=0x68; //edge-alignment, PWM initial state is High, becomes low, enable interrupt only on channel 4
          FTM3_C5SC=0x28;
          FTM3_C4V=500;
#endif
          FTM3_C5V=100;
          FTM3_CNTIN=0x00;
          FTM3_SC=0x08; //PWM edge_alignment, system clock driving, dividing by 1
          pulse_state = EXECUTE_PULSE_DATA;
          break;
     case EXECUTE_PULSE_DATA:
#if 1
          if (pulses_cnt ==500){
               pulses_cnt = 0x00;
               FTM3_C5V=100;
          }
#endif
          break;
     case PULSE_MOTOR_DONE:
          //pulses_cnt = num_pulses;
          pulse_state= INIT_PULSE_DATA;
          break;
     }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Could anyone point me to where i'm doing this wrong ?

Thanks,

Vu

Labels (1)
Tags (3)
0 Kudos
Reply
6 Replies

1,000 Views
Designer11
Contributor IV

I think i've exhausted all my options. I found this thread mentioned about startup_xxx.S for the K60 microcontrollers but not available anywhere in the K64 folders.

setup interrupts KDS 

0 Kudos
Reply

1,000 Views
egoodii
Senior Contributor III

Can you do a full text search for 'UnhandledInterrupt' and/or 'FTM3_IRQHandler' thru all files in the project and find a table full of vectors?  Per that thread you referenced, you are looking for a startup_MK64(something).S file in a 'Startup_Code' folder (under Project_Settings), and if your handler-name matches the one in that file it should indeed overload the default def_irq_handler....

I will also note that in that project set is core_cm4.h which has this NVIC function:

__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)

0 Kudos
Reply

1,000 Views
Designer11
Contributor IV

Hi Earl,

No such files exist anywhere in my project tree. I did a search on "FTM3_IRQHandler" and nothing came up. When i performed a search on "UnhandledInterrupt",  It pointed me to the Vector_Config.h and vector.c files. In the Vector_Config.h file i found the following vector definitions. I believe all i need to do is to replace the "UnhandledInterrupt" text with the my interrupt name. I will test this theory on Monday when i'm in the office and report back to you. Earl, Thank you very much for help.

pastedImage_2.png

-Project tree

pastedImage_1.png

0 Kudos
Reply

1,000 Views
egoodii
Senior Contributor III

A complete interrupt-path starts with the peripheral-int-enable, but ALSO needs to be enabled at the NVIC (with a priority?), something along the lines of "enable_irq(INT_FTM3-16);".  Your handler name FTM3_IRQHandler should over-ride the default 'dummy handler' linkage into the vector-table, which is to say that in the files I use crt0.s contains the declaration "PUBWEAK FTM3_IRQHandler", so that this potential 'dummy' address would be over-ridden by any identical 'hard' linker label.

0 Kudos
Reply

1,000 Views
Designer11
Contributor IV

Hi Earl,

Thanks you for your help. After searching around i wrote a function, enable_irq(INT_FTM3-16);,  and set the interrupt priority, NVICIP87=0x50;. Now, every time i ran the code the program kept pointing me to the below piece of code in the Vectors.c file.

PE_ISR(UnhandledInterrupt)

{
PE_DEBUGHALT();

Thanks,

Vu

0 Kudos
Reply

1,000 Views
egoodii
Senior Contributor III

Sounds like your interrupt handler label did NOT 'overload' an existing weak name (so your newly enabled interrupt falls to the dummy handler), and you are going to have to find your vector table definition code and see that your address DOES get there! Which was your original question(!), but I can't be of much help as I am not familiar with either KDS or PE.

Or of course the NVIC vector isn't what you expected.  DO make sure you have written from the right vector table definition; every Kinetis part is different.

0 Kudos
Reply