I am using a K66 and the documentation says writing any value to the COUNT register sets it to zero.
I have tried that and cannot see it reset in the debugger. Is there something else I have to do to cause a reset?
By disabling the clocks with this statement TPM_HAL_SetClockMode(TPM1, kTpmClockSourceNoneClk), the timers would not reset. Instead, I leave them running.
This is all that is required at this point.
TPM_HAL_ClearCounter(TPM1);
TPM_HAL_ClearCounter(TPM2);
Hello Calvin,
There is a reset function you can use :
Have a great day,
Alice Yang
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
I was thinking I could use the software trigger mode and reload to zero on trigger. But I don't see how to cause a software trigger.
I found this:
43.5.3.3 Counter Reset
Any write to CNT resets the TPM counter and the channel outputs to their initial values
(except for channels in output compare mode).
TPM2 is in the capture mode so that shouldn't be an issue.
Before TPM_HAL_ClearCounter(TPM2);
After.
43.4.2 Counter (TPMx_CNT)
The CNT register contains the TPM counter value.
Reset clears the CNT register. Writing any value to COUNT also clears the counter.
When debug is active, the TPM counter does not increment unless configured otherwise.
Reading the CNT register adds two wait states to the register access due to
synchronization delays.
Hi Calvin,
Can you show me a dump of the TPM module registers? Did you see CMOD bits set for TPMx_SC register?
Hao
// turn off low power timer
LPTMR_BWR_CSR_TEN(LPTMR0, (uint8_t)false);
// clear interrupts
TPM_WR_STATUS(TPM2, 1 << TPM_STATUS_TOF_SHIFT);
TPM_WR_STATUS(TPM2, 1 << TPM_STATUS_CH0F_SHIFT);
// turn off tpm clocks
TPM_HAL_SetClockMode(TPM1, kTpmClockSourceNoneClk);
TPM_HAL_SetClockMode(TPM2, kTpmClockSourceNoneClk);
TPM_HAL_ClearCounter(TPM1);
TPM_HAL_ClearCounter(TPM2);
// restart this timer when lptmr overflows
TPM_HAL_SetTriggerMode(TPM1, true);
TPM_HAL_SetTriggerMode(TPM2, true);
TPM_HAL_SetClockMode(TPM1, kTpmClockSourceModuleClk);
TPM_HAL_SetClockMode(TPM2, kTpmClockSourceModuleClk);
// reset counters
lptmrCnt = 0;
ppsTotal1 = 0;
ppsTotal2 = 0;
// reenable lptmr to overflow in 10 msec
LPTMR_BWR_CSR_TEN(LPTMR0, (uint8_t)true);
Hello Calvin,
From your code , have you turn on the clock of LPTMRO ?
And do you want operate the LPTMR0, if yes , i have not find about your this words
"writing any value to the COUNT register sets it to zero" of LPTMR0 .
Alice
Hello Calvin,
Could you please attach your project, that we can check it and help you sooner.
BR
Alice