Hello,
I'm trying to configure the LPTMR module of S32K148 on our custom board to measure time between function calls StartTimeMeasurement and StopTimeMeasurement.
This is my configuration so far:
// Deactivates module clock before modification.
PCC->PCCn[PCC_LPTMR0_INDEX] &= PCC_PCCn_CGC_MASK;
// Sets SOSCDIV2_CLK as module clock source (we are using 8MHz crystal).
PCC->PCCn[PCC_LPTMR0_INDEX] &= PCC_PCCn_PCS_MASK;
PCC->PCCn[PCC_LPTMR0_INDEX] |= PCC_PCCn_PCS(1U);
// FRAC and PCD = 0. This should result in module input clock 8MHz.
PCC->PCCn[PCC_LPTMR0_INDEX] &= ~(PCC_PCCn_FRAC_MASK | PCC_PCCn_PCD_MASK);
// Reactivates module clock.
PCC->PCCn[PCC_LPTMR0_INDEX] |= PCC_PCCn_CGC(1U);
// Deactivates module before initialization.
LPTMR0->CSR &= ~LPTMR_CSR_TEN_MASK;
// Prescale Bypass - module clock source directly feeds the counter register. Set PCC_CLK as module source clock.
LPTMR0->PSR = LPTMR_PSR_PBYP(1U) | LPTMR_PSR_PCS(3U);
// Counter register counts to the highest possible value before generating interrupt.
LPTMR0->CMR = 0xFFFF;
// Sets module to function in the timer counter mode, counter register to clear when TCF is set and activates interrupt.
LPTMR0->CSR = LPTMR_CSR_TCF(1U) | LPTMR_CSR_TIE(1U) | LPTMR_CSR_TFC(0U) | LPTMR_CSR_TMS(0U);
// Activates module.
LPTMR0->CSR |= LPTMR_CSR_TEN(1U);
I see all the registers setup in the debugger, however the timer counter register value does not increment.
Thank you for any advice!