Range Extension of the Pulse Counter (PCNT)

HarryFord
Posts: 4
Joined: Fri May 18, 2018 1:47 pm

Range Extension of the Pulse Counter (PCNT)

Postby HarryFord » Thu Jun 07, 2018 3:21 pm

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

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Range Extension of the Pulse Counter (PCNT)

Postby kolban » Sun Aug 12, 2018 4:30 am

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()
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

HarryFord
Posts: 4
Joined: Fri May 18, 2018 1:47 pm

Re: Range Extension of the Pulse Counter (PCNT)

Postby HarryFord » Tue Aug 14, 2018 1:55 pm

@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

Deouss
Posts: 425
Joined: Tue Mar 20, 2018 11:36 am

Re: Range Extension of the Pulse Counter (PCNT)

Postby Deouss » Tue Aug 14, 2018 3:33 pm

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.

paulhun
Posts: 12
Joined: Wed Jun 06, 2018 11:48 am

Re: Range Extension of the Pulse Counter (PCNT)

Postby paulhun » Sun Sep 23, 2018 5:16 pm

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

Who is online

Users browsing this forum: Google [Bot] and 142 guests