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);
pcnt_counter_clear(PCNT_UNIT);
}
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?