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
Range Extension of the Pulse Counter (PCNT)
Re: Range Extension of the Pulse Counter (PCNT)
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()
bigTick * 30000 + pcnt.currentCounterValue()
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: Range Extension of the Pulse Counter (PCNT)
@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
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)
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.
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)
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
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
Who is online
Users browsing this forum: No registered users and 74 guests