Discovering LPTMR frequency

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

Discovering LPTMR frequency

771 Views
robertpoor
Senior Contributor I

On my KL27Z, I have configured LPTMR0 to source its clock from kLPTMR_PrescalerClock_0 (which is MCGIRCLK, right?) like this:

  lptmr_config_t lptmrConfig;

  LPTMR_GetDefaultConfig(&lptmrConfig);

  lptmrConfig.prescalerClockSource = kLPTMR_PrescalerClock_0;  // MCGIRCLK?

  LPTMR_Init(LPTMR0, &lptmrConfig);

What is the correct way to find its frequency?  I could do something like this:

uint64_t clock_freq_in_hz = CLOCK_GetFreq(kCLOCK_McgInternalRefClk);

... but I'm not sure that kCLOCK_McgInternalRefClk is the right constant (though empirically it appears to be correct).  Is there a more dependable way to get the LPTMR's clock frequency, perhaps one that uses the actual state of its configuration registers?

Tags (2)
0 Kudos
Reply
2 Replies

565 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

This is the LPTME clock source from the 5.7.5 LPTMR clocking in RM of Kl27:

pastedImage_1.pngHope it can help you

void LPTMR_Init(LPTMR_Type *base, const lptmr_config_t *config)
{
    assert(config);

#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
    /* Ungate the LPTMR clock*/
    CLOCK_EnableClock(s_lptmrClocks[LPTMR_GetInstance(base)]);
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */

    /* Configure the timers operation mode and input pin setup */
    base->CSR = (LPTMR_CSR_TMS(config->timerMode) | LPTMR_CSR_TFC(config->enableFreeRunning) |
                 LPTMR_CSR_TPP(config->pinPolarity) | LPTMR_CSR_TPS(config->pinSelect));

    /* Configure the prescale value and clock source */
    base->PSR = (LPTMR_PSR_PRESCALE(config->value) | LPTMR_PSR_PBYP(config->bypassPrescaler) |
                 LPTMR_PSR_PCS(config->prescalerClockSource));
}

lptmrConfig.prescalerClockSource is used to write PCS bits in LPTMRx_PSR register.

Hope it can help you

BR

XiangJun Rong

0 Kudos
Reply

565 Views
robertpoor
Senior Contributor I

I understand the hardware that generates the clock signals.  What I don't understand is what compiler constants correspond to those signals.

For example, in figure 5-5 that you show above, which signal corresponds to kCLOCK_McgInternalRefClk?  And does kLPTMR_PrescalerClock_0 correspond to MCGIRCLK in that diagram?  (I agree that the _0 suffix suggests that it's the mux 00 input, but I'm not sure.)  Is lptmrConfig.prescalerClockSource responsible for setting the LPTMRx_PSR[PCS] source?

Etc...

The relationship between these constants and the register settings must be documented somewhere, or is that "documentation" the source code itself?

0 Kudos
Reply