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?
解決済! 解決策の投稿を見る。
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.
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!
-----------------------------------------------------------------------------------------------------------------------
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.
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!
-----------------------------------------------------------------------------------------------------------------------
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.