Manual of KL26 says the following:
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).
However, I am unable to reset the counter doing that, my code is simple:
tpm_config_t tpmConfig;
CLOCK_SetTpmClock(1);
CLOCK_EnableClock(kCLOCK_Tpm2);
TPM_GetDefaultConfig(&tpmConfig);
TPM_Init(TPM2, &tpmConfig);
TPM_StartTimer(TPM2, kTPM_SystemClock);
for (uint8_t i = 0; i < 255; i++); /* Give time to increment counter */
TPM_StopTimer(TPM2);
TPM2->CNT = 0; /* Does nothing, CNT register maintains its previous value */
Do I need to configure anything else? I have the same problem in KL26 and KL27 MCUs.
Thank you in advance
Hello @Alf0,
Writing TPM_StopTime(TPM2) before the Counter Reset is disabling the TPM2 Counter.
So, for the Counter Reset to work out, you should do the reset of CNT register first, as follows:
Or simply comment or erase the TPM_StopTimer() if you don't need it for your application.
Regards, Raul.