Hi, Deepak,
In the end, I know you want to know the delay time, if it is the case, you can use either the system tick timer(SysTick) module or the TPM to finish it.
I think you can use the following code to get the delay based on TPM0 module. The delayTimerTick is the delay tick number , the tick is the frequency of FLL output clock.
BR
XiangJun Rong
static int i = 0;
void delay(void);
void TPM_Init(void);
uint16_t getTPMCounter(void);
void ResetTPM(void);
int main(void)
{
uint16_t delayTimerTick;
/* Write your code here */
/* This for loop should be replaced. By default this loop allows a single stepping. */
TPM_Init();
ResetTPM();
delay();
delayTimerTick=getTPMCounter();
__asm("nop"); //set a break point here
for (;;) {
i++;
}
/* Never leave main */
return 0;
}
void TPM_Init(void)
{
SIM_SCGC6|=0x03000000; //enable FTM0 and FTM0 module clock
SIM_SCGC5|=0x3E00;
SIM_SOPT2|=0x1000000; //select TPMSRC clock source as MCGIRCLK clock
TPM0_CONF=0x00; //set up BDM in 11
TPM0_MOD=0xFFFF;
TPM0_C0SC=0x14; //FTM output signal toggle when the FTM counter matches with //C0V registrer
TPM0_C0V=500;
TPM0_SC=0x08; // system clock driving, dividing by 1
}
void ResetTPM(void)
{
TPM0_CNT=0x00;
}
uint16_t getTPMCounter(void)
{
uint16_t temp;
temp=TPM0_CNT;
return temp;
}
void delay(void)
{
uint16_t delayCounter;
for(delayCounter=0; delayCounter<1000; delayCounter++)
{
__asm("nop");
__asm("nop");
}
}