-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
esp32/machine_adc: Add new ADCBlock-based API. #7788
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
Conversation
dc526c2 to
93583fb
Compare
|
@dpgeorge: this is a version of the ADCBlock API for ESP32. I've not done docs yet as I've diverged a bit from #4213 and wanted to check some notes with you first. I've got:
and for compatibility:
This seemed like the base functionality to match what we have now. I'm minded to add:
I'm not sure:
For good measure, I've finally included support for the ADC2 unit. |
073e040 to
f4dcc9e
Compare
f4dcc9e to
33de5d8
Compare
33de5d8 to
eff8650
Compare
|
@dpgeorge: I've added some notes on this API to the ESP32 quick ref and am marking this as ready for review. It seems to me that the new calibrated (*) I've not done anything about the |
|
For reference: I'm using this new calibrated voltage API in the field now with 20 microcontrollers running a pair of large-scale light artworks, sampling supply voltages and case temperatures. Consistency across the different packages is very good – way better than I've ever seen just dumbly adjusting the raw values with a fixed multiplier. |
|
Thanks for this, it looks great! Do you think it's worth having an explicit calibration method, like |
I guess the question is what does it do? If it's non-port-specific then we'd have to bake-in a simple, common algorithm for converting ADC raw values to voltages and this method would get/set the parameters for that. Then presumably that would take precedence over any built-in calibration API/parameters. If it's to be port-specific then on the ESP32 port it could get/set the 5 calibration parameters stored in eFuse, but I'm not sure that you'd want to do that unless you really knew what you were doing and then you could just as easily use a fuse tool to set these. Presumably you'd have to go to the effort of setting up a calibration rig and code to come up with better versions of these values? |
|
Wait! Scratch that. The eFuse on ESP32 is, of course, one time programmable, so you'll not be updating it… Do you think it's useful to have a common ADC calibration API in MicroPython? |
Maybe esp32 does not need it, it seems the calibration is predefined? But on stm32 there are two types of calibration:
In the second case there, the calibration takes time and depending on the application you may want to do it before every reading, or every 10 seconds, or only once at the start, etc. For these two cases I would propose that a) the calibration is done automatically on creation of the first ADC/ADCBlock instance; and b) the calibration can be redone by the user by a call to |
Yes, the packages are calibrated during manufacture and the parameters (interval Vref voltage and raw ADC values at 150mV and 850mV for each block) are burned into the eFuse.
Sounds port-specific to me then. I don't think there's anything comparable that a |
806cd06 to
82e1fe3
Compare
For For Ideally one would simplify specify |
82e1fe3 to
cae9537
Compare
|
Marking this as a draft again temporarily as I've made the latest changes without any hardware to test them on. I'm away until after xmas now, so I'll test properly on my return before marking it as ready for review again. |
04d7d59 to
76c57bb
Compare
|
Have re-tested on actual hardware and I'm happy that this works still. |
Document read_u16(), read_uv() and ADCBlock(). Mark old read(), atten() and width() methods as legacy.
Rework the ADC implementation to use the micropython#4213 API (mostly) adding support for calibrated voltage readings and the ADC2 block. Resolves
Add new machine_adcblock.c file containing the ADCBlock class implementation, with new helper functions to connect with ADCBlock.
76c57bb to
cb3b142
Compare
|
Ace news! One fewer patch for me to maintain 😊 Yes, I'll take a look at the docs again and check it all still makes sense. |
fetch-submodules fallback; add remove-submodules
Rework the ADC implementation to use the #4213 API (mostly) adding support for calibrated voltage readings and the ADC2 block. Resolves #6219. Part-resolves #3943.