Esp32 HAL - Dynamic ADC attenuation#14623
Merged
thinkyhead merged 4 commits intoMarlinFirmware:bugfix-2.0.xfrom Jul 15, 2019
Merged
Esp32 HAL - Dynamic ADC attenuation#14623thinkyhead merged 4 commits intoMarlinFirmware:bugfix-2.0.xfrom
thinkyhead merged 4 commits intoMarlinFirmware:bugfix-2.0.xfrom
Conversation
362d3a2 to
adafc94
Compare
Contributor
|
@simon-jouet |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The ESP32 ADC operates in the range of 0V to ~1.1V (1.0V -- 1.2V). In order for this ADC to work with the full range input of 3.3V the attenuation must be configured to attenuate the input voltage below 1.1V.
In the current implementation of the HAL the ADC attenuation is always the maximum of 11dB allowing the full 3.3V range input (well almost but that's for another discussion). Using the full 111dB attenuation works but also decreases precision when the voltage is lower.
In this patch I use the ADC calibration characteristics to get the operating voltage range of each attenuation level. Using the last ADC reading the attenuation level can be changed to the nearest operating range. This allows much higher precision, which is especially relevant for higher temperatures (close to 0V).
In this code the attenuation is switched when the reading is 100mV below the nominal characteristics and 50mV above the previous attenuation. This range is used to compensate for inaccuracies when shifting range. (e.g when you change to a higher attenuation the value might be less precise and therefore change back to a higher attenuation, repeating multiple times and oscillating around two attenuations).
The 100mV and 50mV values have not been picked for any specific reason and some (better) values might be more suitable, but with this the attenuation do shift properly without oscillations.