Using FlexTimer to create microsecond delay

cancel
Showing results for 
Search instead for 
Did you mean: 

Using FlexTimer to create microsecond delay

88 Views
keyboardcowboy
Contributor I

I am trying to use one of the FlexTimer modules to create a microsecond delay function using Kinetis Design Studio (KDS SDK) and K64 MCU. My initialization code

 

FTM_DRV_Init(FSL_FLEXTIMER1,&DelayTimer_InitConfig);
FTM_DRV_SetClock(FSL_FLEXTIMER1, kClock_source_FTM_SystemClk, kFtmDividedBy1);
FTM_DRV_SetTimeOverflowIntCmd(FSL_FLEXTIMER1,false);
FTM_DRV_SetFaultIntCmd(FSL_FLEXTIMER1,false);

 

 

And the actual delay function looks like

 

void delay_us(uint16_t au16_us)
{
	FTM_Type *ftmBase = g_ftmBase[FSL_FLEXTIMER1];
	FTM_DRV_CounterStart(FSL_FLEXTIMER1, kCounting_FTM_UP, 0x0,0xFFFF, false);
    while (FTM_HAL_GetCounter(ftmBase) < (au16_us*11)){};
    FTM_DRV_CounterStop(FSL_FLEXTIMER1);
    FTM_HAL_SetCounter(ftmBase, 0);
}

 

 

I am not able to get any delays when I call the function like 

 

delay_us(500);

 

My system clock is 20Mhz

What am I doing wrong?. Can anyone help me out?

Tags (1)
0 Kudos
2 Replies

61 Views
keyboardcowboy
Contributor I

Hi @danielchen 

Thank you. Is it not possible to do this without interrupt?. I don't want to use interrupts for this delay routine. Just want execution to stop for the amount of delay specified in microseconds

0 Kudos

67 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi @keyboardcowboy 

 

There is FTM timer demo in SDK. It demonstrates how to use the FTM driver. It sets up the FTM hardware block to trigger an interrupt every 1 millisecond.

SDK_2.9.0_FRDM-K64F\boards\frdmk64f\driver_examples\ftm\timer

 

You can download the SDK from below link

https://mcuxpresso.nxp.com/en/welcome

 

Regards

Daniel

0 Kudos