Page 1 of 1

PCNT api and missing pulses

Posted: Tue Mar 24, 2020 7:21 pm
by jas39_
Is there a proper way to use the PCNT api to count and read pulses without missing an occasional pulse?

What if a pulse is happening in between the two calls below:

Code: Select all

function read_and_clear(int count) {
	pcnt_get_counter_value(PCNT_UNIT, &count);
It looks like a pulse could be lost, especially since there's some slight overhead in both calls for error checking.

Would it be better to have pcnt_counter_clear() return the current counter value or pcnt_get_counter_value() to have a parameter to clear counter after read? Will that minimize the window of risk to one op-instruction? Or completely?

The counter limit function seems to have the posibility to trigger at a limit and clear in one atomic operation. A combination of reading, keeping the delta and reseting when a limit is reached might do the trick but is there an easier way?