I don't fully understand the idea behind that PR. It doesn't expose the PCNT API but instead implements two specific kinds of counters. Why not exposing the PCNT API and subclass the specific counters from that? The MP internal parts would be smaller and simpler, it would leave room for different PCNT usage and the custom parts would be python and thus easier to understand or modify for end users.Roberthh wrote: ↑Fri Jan 21, 2022 12:25 pmThere is a PR open and ready to merge since a while at https://github.com/micropython/micropython/pull/6639. This PR shares the API with a counter/Encoder class for the MIMXRT port and the pure Python implementations for e.g. rp2.
Pulse counter support
-
- Posts: 50
- Joined: Sun Nov 29, 2020 8:17 pm
Re: Pulse counter support
Re: Pulse counter support
That was an implementation discussed a while ago, and not used in favor of a simple API at MicroPython firmware level, which then can be shared by various ports.
-
- Posts: 50
- Joined: Sun Nov 29, 2020 8:17 pm
Re: Pulse counter support
But the simple API does not exist yet? I see in the discussions here that some people prefer a software solution as they are afraid that the hardware version will miscount. I don't see how that should happen, especially with the PCNT filters being used. And the PCNT has the huge advantage of giving you Mhz rates at no CPU cost.
Re: Pulse counter support
The Encoder/Counter class for ESP32 uses the ESP32 PCNT API, counting up to MHz, implementing the same simple basic API which is also provided by Software modules for platforms, which do not have a Hardware Pulse Counter or Encoder.
-
- Posts: 50
- Joined: Sun Nov 29, 2020 8:17 pm
Re: Pulse counter support
But it does that by using PCNT directly. I don't understand why it's desirable to hide that PCNT API and do the Encoder/Counter in C instead of implementing the PCNT API as a module and do Encoder and Counter on top of that in Python. I simply don't see the benefit if that. Actually I only see disadvantages. So I'd like to understand what the advantages are.
-
- Posts: 50
- Joined: Sun Nov 29, 2020 8:17 pm
Re: Pulse counter support
There are now several implementations for this.
I have started myself this some time ago:
https://github.com/harbaum/micropython/ ... ine_pcnt.c
And recently this has been implemented:
https://github.com/micropython/micropyt ... ne_counter
I have started myself this some time ago:
https://github.com/harbaum/micropython/ ... ine_pcnt.c
And recently this has been implemented:
https://github.com/micropython/micropyt ... ne_counter
Re: Pulse counter support
I've seen it. If I count right, there are now 4 implementations for ESP32 plus the generic GPIO based version. That does not improve the situation.
-
- Posts: 50
- Joined: Sun Nov 29, 2020 8:17 pm
Re: Pulse counter support
What's the problem with that? Improvements IMHO are great.
The older versions didn't look very pleasing to me and weren'r working properly. I'd actually prefer the latest version from Jonathan if he fixes the race condiction.