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?