Can I have the setting to configure Low Power Timer (LPTMR0) to generate and intterupt for every 1ms.Tried all combination just does not enter the irq if I change the sample code settings.
Hi Vishal Roy,
Please try to modify the lptmr_periodic_interrupt_s32k116 example.
Best Regards,
Robin
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Robin,
I'm new to the community. Where can I find the example you mention: "lptmr_periodic_interrupt_s32k116"
Regards,
Anshul
I started off with this example.So just want to know if this example has any settings which is done differently.Tried modifying the value "LPTMR0->CMR = 499; " .Theoretically if CMR equals CNT an interrupt is triggered correct.
The example select 1KHz LPO as the clock source of LPTMR.
The vaule of CMR will be too small when you want to generate 1ms interrupt.
You can refer the configuration of my example. Using a higher clock source.
Best Regards,
Robin
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
My usecase for the timer was to do some profiling of the code.As suggested i have made the modifications as below.
void LPTMR0_init(void)
{
PCC->PCCn[PCC_LPTMR0_INDEX] = PCC_PCCn_CGC_MASK;
// PCC->PCCn[PCC_LPTMR0_INDEX] = 0x0;
// LPTMR0->PSR = 0; /* Enable LPTMR Clock */
// LPTMR0->PSR |= LPTMR_PSR_PCS(0b01) /* LPTMR clk src: 1KHz LPO */
// | LPTMR_PSR_PBYP_MASK;
LPTMR0->PSR |= 0x4 ; /* Bypass Prescaler */
LPTMR0->CMR = 0x7;
/* 500 ms interrupt */
LPTMR0->CSR |= LPTMR_CSR_TCF_MASK; /* Clear TCF flag by writting a logic one */
LPTMR0->CSR |= LPTMR_CSR_TIE_MASK; /* Timer interrupt enabled */
LPTMR0->CSR |= LPTMR_CSR_TEN_MASK; /* Enable Timer */
NVIC_init_LPTMR0_IRQs();
}
void LPTMR0_IRQHandler (void)
{
if (0 != (LPTMR0->CSR & LPTMR_CSR_TCF_MASK)) //0x80u 1000 0000
{
/* Check if TCF flag is set */
LPTMR0->CSR |= LPTMR_CSR_TCF_MASK; /* Clear TCF flag by writting a logic one */
// 0x80u 1000 0000
counter_time++;
}
}
I have done the profiling but for some reason the timer does not start on power cycle.But if I connect the Jlink and give the command "rnh" to reset MCU the timer behave as expected.Any thought as to why?
Hi Vishal Roy,
I try to test the S32K116_Project_LPTMR example.
Only modify the LPTMR_init and LPTMR0_IRQHandler function.
When debug it on S32K116EVB with S32 Design Studio, it was able to works.
I did not put NVIC_init_LPTMR0_IRQs(); into LPTMR_init .
Best Regards,
Robin
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
If you load the program and do power-cycle and print the counter value in main in loop is it still changing?
Sorry!
I input the wrong compare value, 1ms should input 1000.
LPTMR0->CMR = 0x1F3F;
The last compare value may too small(1us), the interrupt will enter too frequency.
This example does not contain printf function.
I try to toggle Blue LED every enter LPTMR0_IRQHandler 1000 times.
Best Regards,
Robin
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------