Discovering LPTMR frequency

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

Discovering LPTMR frequency

860 次查看
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?

标记 (2)
0 项奖励
回复
2 回复数

654 次查看
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 项奖励
回复

654 次查看
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 项奖励
回复