-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
ESP32 Pulse Counter Driver #5216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I want to implement this. Is there an API I should copy? |
I don't know that any other devices have a "Pulse counter" in any sense, other than using just a hardware counter driven by a pin. I also have not seen a Python implementation for one. Other than a constructor that takes a Pin object, and a function that gets the counts, everything else might be device specific. Since this issue is ESP32 specific, perhaps go with something that is a close mapping to https://docs.espressif.com/projects/esp-idf/en/v3.3/api-reference/peripherals/pcnt.html in the same way that the RMT implementation closely matches the ESP IDF implementation. For now, I'd say, implement it under the It's generally understood by the community that I've interfaced with that classes under the device specific namespaces are far more likely to change than something under Thanks for offering your time to improve MicroPython ❤️ 🐍 |
Thanks for the comment. Please see #5496 |
Seems it is already implemented: See: Sources seem to be here: But have no idea how to upstream this to micropython 1.12. Any ideas? Best regards, Peter |
Use #5496? |
I'm not shure about it, may be it's related to (see above):
Already made some efforts, could integrate the code into lv-micropython V1.12. --> Test run OK. Must verify it on real hardware. But quadrature - decoder interface including counter based on ESP32 hardware seems to be already done. I'll notice when finished. best regards |
I believe this is best implemented as dynamically loadable driver. This way it's easy to change things around. I did that: https://github.com/tve/mpy-lib/tree/master/esp32-counter. Of course that relies on #5711 but perhaps that gets reviewed someday and maybe even merged if the stars align... |
I have need of the pulse counter in a current ESP32 project and, not seeing any maintained implementations, have gone ahead and rolled another. Sorry. Since there doesn't seem to be much movement on the idea of exposing the IDF functions through dynamic linking, I've just added it as a straight-C extension of the So I have gone for this in the simple case: from machine import Counter, Pin
counter = Counter(0, pin=Pin(12, Pin.IN), rising=Counter.INCREMENT)
counter.start()
count = counter.value() This looks like it ought to work OK as an API for other ports. However, using from machine import Counter, Pin
pin_a = Pin(12, Pin.IN, pull=Pin.PULL_UP)
pin_b = Pin(14, Pin.IN, pull=Pin.PULL_UP)
counter = Counter(0, pin=pin_a, rising=Counter.DECREMENT, falling=Counter.INCREMENT,
mode_pin=pin_b, mode_high=Counter.NORMAL, mode_low=Counter.HOLD)
counter.start()
count = counter.value() Or use It also supports I've not written any documentation for it yet I'm afraid. It's sitting in draft PR #7582 if anyone is interested in looking at it. Like I say, my primary reason for doing this is that I need it more than that I'm interested in seeing it through to mainline. I don't have any hardware for the other MicroPython architectures to work on an implementation of |
Add a driver for ESP32 Pulse Counter Hardware.
Related to: #5214
The text was updated successfully, but these errors were encountered: