TPM count set to zero

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

TPM count set to zero

2,329 次查看
calvinday
Contributor III

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?

0 项奖励
回复
10 回复数

1,955 次查看
calvinday
Contributor III

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);

0 项奖励
回复

1,955 次查看
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Calvin,

There is a reset function you can use :

pastedImage_0.png


Have a great day,
Alice Yang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复

1,955 次查看
calvinday
Contributor III

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.

0 项奖励
回复

1,955 次查看
calvinday
Contributor III

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.

0 项奖励
回复

1,955 次查看
calvinday
Contributor III

Before TPM_HAL_ClearCounter(TPM2);

pastedImage_0.png

After.

pastedImage_1.png

0 项奖励
回复

1,955 次查看
calvinday
Contributor III

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.

0 项奖励
回复

1,955 次查看
cutworth
NXP Employee
NXP Employee

Hi Calvin,

Can you show me a dump of the TPM module registers? Did you see CMOD bits set for TPMx_SC register?

Hao

0 项奖励
回复

1,955 次查看
calvinday
Contributor III

// 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);

0 项奖励
回复

1,955 次查看
Alice_Yang
NXP TechSupport
NXP TechSupport

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

0 项奖励
回复

1,955 次查看
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Calvin,

Could you please attach your project, that we can check it and help you sooner.

BR

Alice

0 项奖励
回复