PCNT api and missing pulses

Posts: 9
Joined: Mon Aug 29, 2016 8:26 pm

PCNT api and missing pulses

Postby jas39_ » Tue Mar 24, 2020 7:21 pm

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?

Who is online

Users browsing this forum: No registered users and 32 guests