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!
Does enabling the pulse counter turn on the GPIO pull-up?
Re: Does enabling the pulse counter turn on the GPIO pull-up?
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
to and see if it helps.
Code: Select all
gpio_set_pull_mode(pulse_io, GPIO_PULLUP_ONLY);
to
Code: Select all
gpio_set_pull_mode(pulse_io, GPIO_FLOATING);
Re: Does enabling the pulse counter turn on the GPIO pull-up?
Thanks - that looks feasible - I will check later (or, more likely, tomorrow)....
Martin
Martin
Re: Does enabling the pulse counter turn on the GPIO pull-up?
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?
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?
Re: Does enabling the pulse counter turn on the GPIO pull-up?
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.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?
Re: Does enabling the pulse counter turn on the GPIO pull-up?
Probably better to undo the pull-up after pcnt_unit_config if possible instead of modifying the driver
Re: Does enabling the pulse counter turn on the GPIO pull-up?
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.WiFive wrote:Probably better to undo the pull-up after pcnt_unit_config if possible instead of modifying the driver
Who is online
Users browsing this forum: Google [Bot] and 70 guests