pcnt_counter_clear works fine ?
Posted: Tue Sep 05, 2017 4:02 pm
Hi,
I'm playing with Pulse counter and timers to be able develop frequency counter. Unfortunatelly, calling "pcnt_counter_clear" function doesn't clear the pulse counter value...
I know, that in the https://github.com/espressif/esp-idf/issues/638 was reported by Igor, that it was fixed, but I'm not sure...
My code is counting 1 second (calling onTimer() function with 1 second period using Timer0) pulses entering to PCNT_UNIT_O. See code. PCNT_UNIT_ counter after "pcnt_counter_clear" continues from pause value...
I'm I using the clear function correctly ?
Thanks,
Ondrej
I'm playing with Pulse counter and timers to be able develop frequency counter. Unfortunatelly, calling "pcnt_counter_clear" function doesn't clear the pulse counter value...
I know, that in the https://github.com/espressif/esp-idf/issues/638 was reported by Igor, that it was fixed, but I'm not sure...
My code is counting 1 second (calling onTimer() function with 1 second period using Timer0) pulses entering to PCNT_UNIT_O. See code. PCNT_UNIT_ counter after "pcnt_counter_clear" continues from pause value...
I'm I using the clear function correctly ?
Thanks,
Ondrej
Code: Select all
/* obluha alarmu timeru */
void IRAM_ATTR onTimer(){
portENTER_CRITICAL_ISR(&timerMux);
switch (state_tmr) {
case 0 :
/* spusíme počítání pulsů */
pcnt_counter_resume(PCNT_TEST_UNIT);
digitalWrite(ledPin, HIGH);
value_ready = 0;
state_tmr = 1;
break;
case 1 :
/* ukončíme počítání pulsů */
pcnt_counter_pause(PCNT_TEST_UNIT);
pcnt_get_counter_value(PCNT_TEST_UNIT, &flow0Counter);
pcnt_counter_clear(PCNT_TEST_UNIT);
Pulses = flow0Counter;
flow0Counter = 0;
digitalWrite(ledPin, LOW);
value_ready = 1;
state_tmr = 2;
break;
case 2 :
/* počkáme vteřinu - vynecháme jedno volání timeru */
state_tmr = 0;
break;
default:
break;
}
portEXIT_CRITICAL_ISR(&timerMux);
}