pcnt_counter_clear(...) function works fine ?

onpa_esp32
Posts: 8
Joined: Tue Aug 29, 2017 7:41 am

pcnt_counter_clear(...) function works fine ?

Postby onpa_esp32 » Wed Sep 06, 2017 9:47 am

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 - there is state machine there with "state_tmr" variable. PCNT_UNIT_ counter after "pcnt_counter_clear" continues from pause value...

I'm I using the clear function correctly ?

Thanks,
Ondrej

Code: Select all

/* ISR for alarm timer */
void IRAM_ATTR onTimer(){
  portENTER_CRITICAL_ISR(&timerMux);
  switch (state_tmr) {

    case 0 :
      /* start pulse counting */
      pcnt_counter_resume(PCNT_TEST_UNIT);
      digitalWrite(ledPin, HIGH);
      value_ready = 0;
      state_tmr = 1;
      break;

    case 1 :
      /* after 1 second stop pulse counting  */
      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 :
      /* wait 1 second - just for verification of state machine */
      state_tmr = 0;
      break;

    default:
      break;
  }
  portEXIT_CRITICAL_ISR(&timerMux);
}

onpa_esp32
Posts: 8
Joined: Tue Aug 29, 2017 7:41 am

Re: pcnt_counter_clear(...) function works fine ?

Postby onpa_esp32 » Wed Sep 06, 2017 2:19 pm

SOLVED - New arduinoespressif32 framework 1.2.0 was updated to another location. Now it works fine.

Ondrej

Who is online

Users browsing this forum: Majestic-12 [Bot] and 132 guests