-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
docs\machine: Add Counter and Encoder classes. #8072
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
base: master
Are you sure you want to change the base?
docs\machine: Add Counter and Encoder classes. #8072
Conversation
Moved to docs\machine: Add Counter and Encoder classes. micropython#8072 micropython#8072
Thank you for the documentation of the minimal API of the Encoder/Counter class. A few notes:
|
I saw that you names the Counter() input pin as 'input'. But I think that there are many inputs and 'pulse' represents this input signal more accurately/definitely, like phase_a and phase_b better then input_a and input_b for Encoder(). |
I do not like pulse. How about "signal"? |
About Counter() input. For example Electronic Impulse Counter |
Thoughts:
I'd just say that individual ports may differ on what form of quadrature decoding they do, or may allow this to be configured, but x4 is the preferred default. Don't think pseudo-code is needed for the I tried to find comparisons for naming of the counter pin argument and the closest I could find is the Also, I think this should probably be There's a few spelling and wording things that need fixing, but those can wait for a final pass. |
On a side note: another reason I disagree with adding It's best to step away from a half-solution and leave the user to understand their particular use-case and code appropriately for it. |
@jonathanhogg filter_ns is a good suggestion. About the name of the Pin for the counter, I still miss a real catching word for that. I had chosen 'input' as a device view of the interface, @IhorNehrutsa has chosen 'pulse' as a signal type view, but none of that is as obvious as phase_a and phase_b for the Encoder. |
How curious! Does the i.MX RT provide a way to invert the logic of an input that would be equivalent? Otherwise, the question is whether
Yeah, I don't think there are any options that I find fully satisfying. I do think that talking about the "source" or "input" of a counter makes more sense than using Looking through the MicroPython code, equivalent arguments are normally just called |
There is no simple invert bit on the GPIO input section. There is a so-called AIO-Logic module, which can And/Or/Invert several internal signals of the device, which are routed through the crossbar matrix. This crossbar is actually use to route the pad signals to the encoder module. But I'm not sure whether that could be used. The first step would be to tell, which egde is the active one at the moment. |
Further keyword arguments is still incomprehensible to me. |
The Encoder constructor should probably be: Encoder(id, /, phase_a=-1, phase_b=-1, *, filter_ns=0) However, MicroPython does not support the Encoder(id, phase_a=-1, phase_b=-1, *, filter_ns=0) I'm not sure it's even necessary to make a distinction and refer to "keyword arguments" – one only needs to refer to them by name and explain what they do. As noted before, it's not even necessary for a port to require the |
[Personally I'd prefer: Encoder(id, *, phase_a, phase_b, filter_ns)
Encoder.init(*, phase_a, phase_b, filter_ns) and make everything other than |
This phase_a=-1 looks more than confusing, especially since it is not a valid setting. It does not explain anything to me. Using phase_a=Pin(x) is much more intuitive, or phase_a=pin_spec. |
Unfortunately,
The docs honestly become simpler if you just call them keyword-only arguments as you can just name them and then explain what each should be below. Something like the documentation of the recently-added |
In terms of "validity" of a particular value one should consider that a port may want to support something other than a Pin object – such as a pin number, name or some constant specifying one from a limited range of hardware-allowed options. There's a fair bit of relaxed usage here across the different ports currently. |
For instance the MIMXRT port allows to use a number at places, where Pin is expected. |
I wouldn't even say that they are required, since a port may not necessarily require them. Given this is just the documentation of the minimal API, it'd be safe to say that they are keyword arguments that should at least accept a Pin object but may support other things for a particular port or may be optional if they can be inferred from the hardware unit. You could then make these arguments positional and required in your implementation without breaking the API, providing they can still be specified by keyword. |
That's how it is implemented for the MIMXRT port. They have to be given at least in the constructor, as keyword parameter or positional. |
I don't like Counter() input again. Counter() object has two inputs. I don't see any logic. :(( phase_a and phase_b also inputs and sources. Why not input_a or src_a? EDITED: I withdraw the claim |
Please review. |
Did you switch to "input" for the counter input Pin?
What I usually do is use at least the spell check of a word processor. That fixes at least some of the error. |
I added suspend() and resume() to the MIMXRT port as well, and switched back to "input", like documented here. Suspend() and Resume() may not be needed often, but implementing them was simple and short, and creates not further trouble, like spurious counts. |
Thanks. I switched back as well. |
Still liking |
It's running in circles. I had changed 'input' to 'src', just to notice that @IhorNehrutsa had changed 'pulse' to 'input'. So I changed back 'src' to 'input', just to see that 'input' was changed to 'pulse' again. So I'll wait for a while now. |
That's why we should be agreeing on the naming here in this documentation PR first. I think maybe I'd lean towards |
Well, suspend saves the state, and resume picks it up at that point. |
This is the MIMXRT specific version, compliant to the documentation of PR micropython#8072 in the basic methods. Signed-off-by: robert-hh <robert@hammelrath.com>
Add thin Python shims around `esp32.PCNT` to implement the `machine.Counter` and `machine.Encoder` classes (as per micropython#8072 API).
Add documentation for the core Counter/Encoder API as currently implemented by the esp32 port. This documentation is a simplification of that in PR micropython#8072.
e33e5c6
to
129cac2
Compare
Add thin Python shims around `esp32.PCNT` to implement the `machine.Counter` and `machine.Encoder` classes (as per micropython#8072 API).
Add documentation for the core Counter/Encoder API as currently implemented by the esp32 port. This documentation is a simplification of that in PR micropython#8072.
Add thin Python shims around `esp32.PCNT` to implement the `machine.Counter` and `machine.Encoder` classes (as per micropython#8072 API).
Add documentation for the core Counter/Encoder API as currently implemented by the esp32 port. This documentation is a simplification of that in PR micropython#8072.
This is the MIMXRT specific version, compliant to the documentation of PR micropython#8072 in the basic methods. Signed-off-by: robert-hh <robert@hammelrath.com>
129cac2
to
fe9d0e3
Compare
This is the MIMXRT specific version, compliant to the documentation of PR micropython#8072 in the basic methods. Signed-off-by: robert-hh <robert@hammelrath.com>
This is the MIMXRT specific version, compliant to the documentation of PR micropython#8072 in the basic methods. Signed-off-by: robert-hh <robert@hammelrath.com>
This is the MIMXRT specific version, compliant to the documentation of PR micropython#8072 in the basic methods. Signed-off-by: robert-hh <robert@hammelrath.com>
This is the MIMXRT specific version, compliant to the documentation of PR micropython#8072 in the basic methods. Signed-off-by: robert-hh <robert@hammelrath.com>
This is the MIMXRT specific version, compliant to the documentation of PR micropython#8072 in the basic methods. Signed-off-by: robert-hh <robert@hammelrath.com>
This is the MIMXRT specific version, compliant to the documentation of PR micropython#8072 in the basic methods. Signed-off-by: robert-hh <robert@hammelrath.com>
Add thin Python shims around `esp32.PCNT` to implement the `machine.Counter` and `machine.Encoder` classes (as per micropython#8072 API).
Add documentation for the core Counter/Encoder API as currently implemented by the esp32 port. This documentation is a simplification of that in PR micropython#8072.
Add thin Python shims around `esp32.PCNT` to implement the `machine.Counter` and `machine.Encoder` classes (as per micropython#8072 API).
Add documentation for the core Counter/Encoder API as currently implemented by the esp32 port. This documentation is a simplification of that in PR micropython#8072.
5bfa656
to
e70bc39
Compare
Signed-off-by: IhorNehrutsa <Ihor.Nehrutsa@gmail.com>
e70bc39
to
d4ea6cf
Compare
Add thin Python shims around `esp32.PCNT` to implement the `machine.Counter` and `machine.Encoder` classes (as per micropython#8072 API).
Add documentation for the core Counter/Encoder API as currently implemented by the esp32 port. This documentation is a simplification of that in PR micropython#8072.
This PR is based on the discussion in #6639.
It describes the common hardware APIs for Counter and Encoder classes.
Link
:ref:
ESP32 <esp32_machine.Counter>
is located in
ESP32: New hardware PCNT Counter() and Encoder(). #6639
Link
:ref:
MIMXRT <mimxrt_machine.Counter>
is located in
mimxrt: Initial documentation for the mimxrt port. #7494