Delay calculations in FRDM KL25Z!

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

Delay calculations in FRDM KL25Z!

1,701 Views
suma_success
Contributor II

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

0 Kudos
1 Reply

1,614 Views
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 Kudos