How to reset counter in TPM (Kinetis)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to reset counter in TPM (Kinetis)

1,172 Views
Alf0
Contributor I

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

Labels (1)
0 Kudos
Reply
1 Reply

1,121 Views
RaRo
NXP TechSupport
NXP TechSupport

Hello @Alf0,

Writing TPM_StopTime(TPM2) before the Counter Reset is disabling the TPM2 Counter.

RaulRomero_0-1668006455102.png

So, for the Counter Reset to work out, you should do the reset of CNT register first, as follows:

RaulRomero_1-1668006510770.png

Or simply comment or erase the TPM_StopTimer() if you don't need it for your application.

Regards, Raul.

0 Kudos
Reply