I'm using a CTIMER0 in counter mode to count external pulses. Do I need to worry about the count changing while I'm reading the counter register? Is there a way to use a shadow register? I'm using an LPC54606 and don't see any mention of this in the user manual.
Hello Klaus Renner,
You don't need to worry, you won't have any problem while reading this register.
The shadow register is for a completely different purpose. The Match Shadow registers contain the values that the corresponding Match Registers are (optionally) reloaded with at the start of each new counter cycle.
Hope it helps!
Victor.
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Thanks, but just to be clear, let me restate my question.
Is there protection in hardware that prevents the counter register from
changing while the firmware reads its value?
Since my external counter clock is varying and not related to any clock on
chip I worry about occasionally getting bad readings.
I currently ensure that this can't happen by using a capture register. I
trigger the capture by changing the state of a port pin when my firmware
needs the counter value. That port pin is externally wired to the capture
input in order to force the capture, then my firmware reads the capture
register, not the counter register. This should be safe, and it works, but
it ties up two port pins and adds some extra code. If it's not necessary
I'd rather not do it, but I do need to be sure that the counter reading is
never garbled, and it would take some time to prove...
*Klaus Renner | Cooper Perkins, Inc. | **10 Maguire Road, Bldg. 4 |
Lexington, MA 02421*
desk: 781-761-4807 | http://www.cooperperkins.com
This email message contains confidential information.
On Wed, Jul 11, 2018 at 3:17 PM, victorjimenez <admin@community.nxp.com>
Hello Klaus Renner,
Is there protection in hardware that prevents the counter register from changing while the firmware reads its value?
No, there isn't a hardware protection that prevents this, but you don't need one. You can read the value of the counter anytime without getting wrong values, doesn't matter if the timer is running or on hold.
If the timer is still running when you want to read the value of the counter then you will read the last value stored in the buffer of the timer. So, even if the value changes while you are reading it you won't get an incorrect value. Why do you think you may get bad readings occasionally?
Hope it helps!
Victor.
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------