FTM interrupt using API

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

FTM interrupt using API

Jump to solution
2,558 Views
superaga
Contributor III

Hi all,

I'm trying to configure FTM interrupt on the MK64FN1M0xxx12 device using the SDK_2.x_FRDM-K64F API.

I started importing and testing from the SDK the example frdmk64_ftm_output_compare, which works as expected.

I then updated the code adding the following functions to the main file (ftm_output_compare.c):

void FTM0_IRQHandler(void){
uint32_t flags = FTM_GetStatusFlags(BOARD_FTM_BASEADDR);
FTM_ClearStatusFlags(BOARD_FTM_BASEADDR, flags);
}

/*!
* @brief Main function
*/
int main(void)
{
...
...

/* Set the timer to be in free-running mode */
BOARD_FTM_BASEADDR->MOD = 0xFFFF;

/* enable interrupt */
FTM_EnableInterrupts(BOARD_FTM_BASEADDR, kFTM_Chnl0InterruptEnable);

/* Update the buffered registers */
FTM_SetSoftwareTrigger(BOARD_FTM_BASEADDR, true);

FTM_StartTimer(BOARD_FTM_BASEADDR, kFTM_SystemClock);
while (1)
{
};
}

I think that this should be enough to trigger the interrupt, but obviously it doesn't since that doesn't work.

Looking to the available peripheral API, I can't find other eventual functions necessary to be called, to enable the desired behavior that is: fire an interrupt every time the timer counter matches the channel value.

I really look forward to read some answers.

 

Kind regards,

AGA

Labels (1)
0 Kudos
Reply
1 Solution
2,546 Views
mjbcswitzerland
Specialist V

Hi

For FTM interrupt operation the required interrupt source must be enabled in the timer (or its specific channel, depending on which one is required) and it needs to be enabled in the NVIC.

To make learning and solving the problem easier run the uTasker K64 simulator - free at https://github.com/uTasker/uTasker-Kinetis which gives you a simple interface to use the FTM overflow and channel interrupts or DMA triggering according to its interface described tin https://www.utasker.com/docs/uTasker/uTaskerHWTimers.pdf

It allows you to build and run the code on a simulated K64 (where also peripherals are emulated) in order to easily investigate the internal operation and fix any coding errors before final HW verification.

The project can be used to generate compete projects quickly (with TCP/IP, USB, File systems, various peripherals and more) or as a general learning aid. For professionals requiring a future path to the i.MX RT parts projects built with it can run on these with virtually no addition porting effort if and when increased performance is needed..

Regards

Mark
[uTasker project developer for Kinetis and i.MX RT]
Contact me by personal message or on the uTasker web site to discuss professional training, solutions to problems or rapid product development requirements

For professionals searching for faster, problem-free Kinetis and i.MX RT 10xx developments the uTasker project holds the key: https://www.utasker.com/kinetis/FRDM-K64F.html

View solution in original post

0 Kudos
Reply
3 Replies
2,521 Views
superaga
Contributor III

Just to complete the solution, here the missing code to enable the NVIC

 

    /* enable interrupt */
FTM_EnableInterrupts(BOARD_FTM_BASEADDR, kFTM_Chnl0InterruptEnable);

// enable FTM peripheral IRQ through the NVIC
EnableIRQ(FTM0_IRQn);

 

Kind regards,

AGA

0 Kudos
Reply
2,533 Views
superaga
Contributor III

Hi @mjbcswitzerland,

Many thanks for your clear answer.

Yes reading your post I realized that I completely forgot to init the NVIC.

I didn't know about this simulator, looks an amazing tool to run my code, I'll definitely give it a try.

 

Kind regards,

AGA

0 Kudos
Reply
2,547 Views
mjbcswitzerland
Specialist V

Hi

For FTM interrupt operation the required interrupt source must be enabled in the timer (or its specific channel, depending on which one is required) and it needs to be enabled in the NVIC.

To make learning and solving the problem easier run the uTasker K64 simulator - free at https://github.com/uTasker/uTasker-Kinetis which gives you a simple interface to use the FTM overflow and channel interrupts or DMA triggering according to its interface described tin https://www.utasker.com/docs/uTasker/uTaskerHWTimers.pdf

It allows you to build and run the code on a simulated K64 (where also peripherals are emulated) in order to easily investigate the internal operation and fix any coding errors before final HW verification.

The project can be used to generate compete projects quickly (with TCP/IP, USB, File systems, various peripherals and more) or as a general learning aid. For professionals requiring a future path to the i.MX RT parts projects built with it can run on these with virtually no addition porting effort if and when increased performance is needed..

Regards

Mark
[uTasker project developer for Kinetis and i.MX RT]
Contact me by personal message or on the uTasker web site to discuss professional training, solutions to problems or rapid product development requirements

For professionals searching for faster, problem-free Kinetis and i.MX RT 10xx developments the uTasker project holds the key: https://www.utasker.com/kinetis/FRDM-K64F.html

0 Kudos
Reply