-
Notifications
You must be signed in to change notification settings - Fork 1.3k
ADC Multi-sampling #9315
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
ADC Multi-sampling #9315
Conversation
sample
keyword and persistent pin init.samples
keyword and persistent pin init.
We can fix this by by making the |
Is there any desire to see this completed? It makes sampling a lot faster. |
I might have done this for #8690. If you want to complete it to check AnalogIn off in that issue, that would be great. Look for how finalizers are done in, say, #9165. Note that |
Implemented finalisers. Now I just need to implement the sampling logic on all ports. |
samples
keyword and persistent pin init.samples
keyword, only initialize once on espressif
, add finalisers to AnalogIn
objects
Updated the title an opening comment.
Do you maybe want me to also include |
That probably uses a an ADC.
No, I am not prepared to turn off the second core yet. I would rather debug the underlying problem. |
Note, the actions on 39d26d6 should not have succeeded. It didn't build any boards. |
While I'm at it, should I maybe add a property for configuring sample size after the object has been created? As is, the sample size can only be set during object creation like a so: I kinda think like adding a |
This PR is pretty much ready, it just need testing. I will test on |
samples
keyword, only initialize once on espressif
, add finalisers to AnalogIn
objects
Forgot this existed, tested on samd51. Now I have tested every port I have. There is nothing else to be done from my side. |
Fixed merge conflicts, please validate against RP2350 too. adc.sample_size = 65535
adc.value |
I cannot get that one samd board to fit. I don't know what to do from here. |
The only thing I see that could possibly be disabled is |
Honestly, I'm not sure I want to add sample number configuration as an API. I'd be ok if the ESP did multiple samples internally but adding an API impacts all ports (as you see) and all ADC drivers. It is backwards compatible but any code that starts using it won't work elsewhere that hasn't added it. Multiple samples can be taken from Python too if you really want to too. |
Sure, it's new api, but something that arguably should have been there from the start.
Yea, but how often is an application developed and it's expected for it to work on earlier version of CircuitPython?
This is why I followed standard procedure and created a task list. |
It is simple but likely to not be used. (We've gone 7 years without it.) Furthermore, it has the code size issue on SAMD. Newer APIs like
I'm more concerned about other places that implement this API like drivers and Blinka.
hasattr can't check for a kwarg. I'd prefer not to change the AnalogIn API at all. Instead, I'd be ok adding internal multisampling for ESP. |
It's an arg and an attribute, it can be set during creation or after. In either case, i'll close the PR. It could probably be optimized to fit, but if |
This PR introduces a way to read multiple ADC samples in one go and additionally moves ADC object initiation and calibration outside of
get_value
for Espressif. This vastly improves ADC performance on Espressif.A new
AnalogIn
property has been added,sample_size
which can be both read and written to setting the number of samples taken on every.value
read.Alongside the property, there is also the
samples
keyword that can be used to setsample_size
during theAnalogIn
object construction.The default sample size is set to 2 on all ports. As it was, only espressif did take 2 samples, with all the rest of the ports taking one.
Task checklist:
espressif
.espressif
.raspberrypi
.raspberrypi
.atmel-samd
.atmel-samd
.cxd56
.cxd56
.mimxrt10xx
.mimxrt10xx
.nordic
.nordic
.silabs
.silabs
.stm
.stm
.As a note, I cannot test
stm
,silabs
,mimxrt10xx
,cxd56
.Those will have to be tested by someone else.