Does enabling the pulse counter turn on the GPIO pull-up?

martinB
Posts: 15
Joined: Mon Aug 07, 2017 2:45 pm

Does enabling the pulse counter turn on the GPIO pull-up?

Postby martinB » Sun Jul 08, 2018 11:18 am

Hi all,

I'm developing an IoT application that responds to pulses coming in from an external sensor. I've had it working fine with the sensor wired directly to a GPIO pin with an interrupt handler configured but I thought that I would try moving to the pulse counter instead. My application needs to count pulses over a period of one or two minutes, then report the result up to a central server - the pulse counter seems to be the perfect solution.

When I modified the code and fired it up, nothing happened - no pulses detected at all. After spending a good couple of hours reading my code and the Espressif hardware documentation, I decided to check the hardware - I hooked an oscilloscope up to the GPIO input pin and discovered that it was being held high all the time. I disconnected the sensor, hooked it up to the scope and it was working fine - plenty of pulses coming in and showing on the scope screen. I left the hardware the same and reverted to my old code and it worked fine - the GPIO pin was no longer held high and the code saw the pulses.

I then tried an old sensor that I had been using earlier successfully. Even with the pulse counter enabled, this worked! I think that the difference is that the old sensor is very basic technology and can source or sink a significant current. The new sensor is ultra low power and when the pulse counter in the ESP32 is enabled, it seems that the GPIO pin is getting some pull-up turned on which is too strong for the new sensor.

Does this make any sense? I've looked through the documentation for the pulse counter and can see no mention of pull-up. My code explicitly turns off both the pull-up and pull-down on the input pin and it works fine provided I don't enable the pulse counter but as soon as I add the line of code to turn on the counter, the input pin flips up to 3v and stays there!

michprev
Posts: 92
Joined: Fri Aug 04, 2017 8:57 pm

Re: Does enabling the pulse counter turn on the GPIO pull-up?

Postby michprev » Sun Jul 08, 2018 2:53 pm

Are you using ESP-IDF? If so then look at this line https://github.com/espressif/esp-idf/bl ... cnt.c#L117. You can change

Code: Select all

gpio_set_pull_mode(pulse_io, GPIO_PULLUP_ONLY);

to

Code: Select all

gpio_set_pull_mode(pulse_io, GPIO_FLOATING);
and see if it helps.

martinB
Posts: 15
Joined: Mon Aug 07, 2017 2:45 pm

Re: Does enabling the pulse counter turn on the GPIO pull-up?

Postby martinB » Sun Jul 08, 2018 3:58 pm

Thanks - that looks feasible - I will check later (or, more likely, tomorrow)....

Martin

martinB
Posts: 15
Joined: Mon Aug 07, 2017 2:45 pm

Re: Does enabling the pulse counter turn on the GPIO pull-up?

Postby martinB » Sun Jul 08, 2018 4:38 pm

Follow up : I got impatient and tested it - and your solution works fine! Actually it seems that I need to enable the pull-down for my circuit - with the pin floating I got a lot of spurious triggers. It now works very well - thanks.

Perhaps this should be a configuration option? I'm now running on a non-standard kernel - I can't be the only person that will get caught out by this, surely?

michprev
Posts: 92
Joined: Fri Aug 04, 2017 8:57 pm

Re: Does enabling the pulse counter turn on the GPIO pull-up?

Postby michprev » Sun Jul 08, 2018 5:13 pm

martinB wrote: Perhaps this should be a configuration option? I'm now running on a non-standard kernel - I can't be the only person that will get caught out by this, surely?
In my opinion ESP-IDF comes with too many assumptions (like this one). I am making lower level SDK but it is still in an early beggining. From my experience with other platforms it is the best to separate GPIO api from peripherals api.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Does enabling the pulse counter turn on the GPIO pull-up?

Postby WiFive » Sun Jul 08, 2018 5:36 pm

Probably better to undo the pull-up after pcnt_unit_config if possible instead of modifying the driver

martinB
Posts: 15
Joined: Mon Aug 07, 2017 2:45 pm

Re: Does enabling the pulse counter turn on the GPIO pull-up?

Postby martinB » Mon Jul 09, 2018 8:48 am

WiFive wrote:Probably better to undo the pull-up after pcnt_unit_config if possible instead of modifying the driver
I tried that, but it didn't seem to work. I was in a hurry at the time and could not trace through - I may try again later.

Who is online

Users browsing this forum: CatNoir and 113 guests