On S32K148 I was trying to use an LPTMR as a one-shot timer using different combinations of PEX calls.
I tried Init()/Deinit() and also StartCounter()/StopCounter(), but it seems to continue counting despite attempts to stop the timer.
I did see some info about how you can't modify the timer registers once running, but I assume these calls would stop the running.
if(condition1){
if(timer_flag){
lockout = true;
timer_flag = false; // clear the ISR flag
//LPTMR_DRV_StopCounter(INST_LPTMR1);
//LPTMR_DRV_Deinit(INST_LPTMR1);
}
else if(!(LPTMR_DRV_IsRunning(INST_LPTMR1))){
timer_flag = false;
LPTMR_DRV_Init(INST_LPTMR1, &lpTmr1_config0, true);
}
}
void LPTMR_ISR(void){
LPTMR_DRV_Deinit(INST_LPTMR1);
timer_flag = true;
/* Clear compare flag */
LPTMR_DRV_ClearCompareFlag(INST_LPTMR1);
}
Solved! Go to Solution.
Sorry I may not understand your question, please correct me if I understand it wrong.
void LPTMR_ISR(void){
timer_flag = true;
/* Clear compare flag */
LPTMR_DRV_ClearCompareFlag(INST_LPTMR1);
}
Since you configured CSR[TFC]=0, CNR is reset whenever TCF is set.
I think after entering LPTMR_ISR, the CNR has actually been reset and will no longer increase.
LPTMR_DRV_GetCounterValueByCount can be used to check whether the CNR is still increasing.
Best Regards,
Robin
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
With your insight I was able to determine where I had a logic error. The timer was getting restarted when it was not desired to restart.
In my ISR now I do:
1) set a flag for program code
2) LPTMR_DRV_StopCounter()
3) LPTMRM_DRV_ClearCompareFlag()
then in the program code when I want to start the counter all I need to do is call LPTRM_DRV_Init(inst, config, TRUE).
This works swimmingly as a one-shot. Documenting here because the only examples I found were for periodic timing.
Thanks Robin!
Sorry I may not understand your question, please correct me if I understand it wrong.
void LPTMR_ISR(void){
timer_flag = true;
/* Clear compare flag */
LPTMR_DRV_ClearCompareFlag(INST_LPTMR1);
}
Since you configured CSR[TFC]=0, CNR is reset whenever TCF is set.
I think after entering LPTMR_ISR, the CNR has actually been reset and will no longer increase.
LPTMR_DRV_GetCounterValueByCount can be used to check whether the CNR is still increasing.
Best Regards,
Robin
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------