Page 1 of 1

Range Extension of the Pulse Counter (PCNT)

Posted: Thu Jun 07, 2018 3:21 pm
by HarryFord
I want to use the pulse counter (PCNT) of the ESP32 to count pulses arriving at its input. Is there a way to extend the measurement range to more than the 16 bit countable 65535 pulses, because more than 65535 pulses will arrive in one measurement pass?
I googled for the keywords »PCNT Overflow Range Extension«, but found nothing appropriate.
Regards

Re: Range Extension of the Pulse Counter (PCNT)

Posted: Sun Aug 12, 2018 4:30 am
by kolban
Unfortunately, I think the puzzle is worse than you think. The value of the counter is a signed 16bit value which means that it can count from -32767 to + 32767. That means it overflows after 15bits. If you are only counting "up" then I would suggest setting a high value of (say) 30000. When the high value is reached, an interrupt can be fired and the counter is reset to zero. Your interrupt could increment a global state variable. Thus at any time you could count total pulses as:

bigTick * 30000 + pcnt.currentCounterValue()

Re: Range Extension of the Pulse Counter (PCNT)

Posted: Tue Aug 14, 2018 1:55 pm
by HarryFord
@kolban
thank you for your help! I had already given up hope for an answer and therefore did not check regularly. As suggested, it should work.
Regards

Re: Range Extension of the Pulse Counter (PCNT)

Posted: Tue Aug 14, 2018 3:33 pm
by Deouss
I had that problem with counter value. You don't have to extend range of PCNT.
All you have to do is detect if it is decrement or increment and store value in memory variable.
Check for delta change and add it to your global value - that's it.

Re: Range Extension of the Pulse Counter (PCNT)

Posted: Sun Sep 23, 2018 5:16 pm
by paulhun
Hi Deouss, are you able to offer any example code for your suggestion?
I've gone round in circles for a few times with this but 'nothing has clicked' - I'm sure I'm not seeing the wood for the trees

thanks in advance Paul