How to reset counter in TPM (Kinetis)

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

How to reset counter in TPM (Kinetis)

1,173 次查看
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

标签 (1)
0 项奖励
回复
1 回复

1,122 次查看
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 项奖励
回复