Why does the Kinetis K10 Low-Power Timer only count when I try writing to LPTMR0_CNR?

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

Why does the Kinetis K10 Low-Power Timer only count when I try writing to LPTMR0_CNR?

Jump to solution
566 Views
ryan1
Contributor II

I have a project that's almost done and we're going to use the LPTMR (low-power timer) as a counter with a pulse input. When I go to read the LPTMR_CNR like so:

lptmrCounta = LPTMR0_CNR;

lptmrCountb = LPTMR0_CNR;

It does not work. All I get is a 0 no matter how many times I create a pulse. However, when I try to write to the CNR first, like so:

LPTMR0_CNR = 0;

lptmrCounta = LPTMR0_CNR;

lptmrCountb = LPTMR0_CNR;

It works every time. The documentation shows that the CNR is read only and it says nothing about writing to it before reading it. So why does it work only when I try to write to it?

0 Kudos
1 Solution
468 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Ryan Phillips

In the LPTMR chapter of the Reference Manual for kinetis K10, in the 4.5 section "LPTMR counter", they explain why you need to do this.

pastedImage_0.png

Hope this answer your question, please tell me if you have other question
Have a great day,
Jorge Alcala

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

View solution in original post

0 Kudos
2 Replies
469 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Ryan Phillips

In the LPTMR chapter of the Reference Manual for kinetis K10, in the 4.5 section "LPTMR counter", they explain why you need to do this.

pastedImage_0.png

Hope this answer your question, please tell me if you have other question
Have a great day,
Jorge Alcala

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

0 Kudos
468 Views
ryan1
Contributor II

Can you point me to where you got the new version of the reference manual? The one on the product page (ARM Cortex-M4|Kinetis K10 72 MHz 32-bit MCUs|NXP) is Rev 1.1 from December of 2012 but it says it was modified in June of last year. Rev 1.1 does not include the note about the CNR being written to before reading it. it just says 2 read accesses are recommended:

The CNR cannot be initialized, but can be read at any time. Reading the CNR at the time

it is incrementing may return invalid data due to synchronization of the read data bus. If it

is necessary for software to read the CNR, it is recommended that two read accesses are

performed and software verifies that the same data was returned for both reads.

0 Kudos