Delay calculations in FRDM KL25Z!

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Delay calculations in FRDM KL25Z!

1,901 次查看
suma_success
Contributor II

Kindly requesting assistance in writing a delay subroutine to generate a 1 sec delay in FRDMKL25Z ( clock is 48MHz) ?

0 项奖励
回复
1 回复

1,814 次查看
diego_charles
NXP TechSupport
NXP TechSupport

Hi Suma,

 

For generate a delay there are two general paths, 

1   write a subroutine using a for loop and nop operations.

2 Use a Timer /counter. 

 

I would choose the timer because provides interrupts and that enables you to perform blocking as non-blocking delays and  it is easier to generate more accurate delays.

 

You could refer to FRDM-KL52Z SDK PIT example (SDK installation instructions here).  This example demonstrates the implementation of the Periodic interrupt timer  or PIT  for toggle an LED each second.

 

I believe that you could use the example as reference for your application.  Please look at the SDK documentation to get more details on the PIT timer driver.  For example, if you wish to stop the timer you could call PIT_StopTimer(...) function.

 

Another, detail is that PIT timer period it is calculated upon your clock frequency, so you can relax a bit with this topic:

#define PIT_SOURCE_CLOCK CLOCK_GetFreq(kCLOCK_BusClk)

 PIT_SetTimerPeriod(PIT, kPIT_Chnl_0, USEC_TO_COUNT(1000000U, PIT_SOURCE_CLOCK));

I hope this helps!

Yours,

Diego

0 项奖励
回复