Add ADC resolution options #63
Open
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.
This PR is in response to the issue I raised here: #62
It adds two new functions setShuntADCResolution and setBusADCResolution which use the already defined values for setting the ADC resolution and averaging options, such as INA219_CONFIG_SADCRES_12BIT_128S_69MS
It has been tested on an Adafruit ESP32-S3-TFT Feather connected to an Adafruit INA219 breakout board.
By running a test calling getCurrent_mA 1000 times over 350mS (the fastest speed available by setting the I2C bus speed to 400000) while reading the current of a motor, I was able to prove that the different settings worked. The INA219 chip always gives you the last reading, even if there isn't a new value ready yet.
For example, when running with the default option (INA219_CONFIG_SADCRES_12BIT_1S_532US), you can see every value was different (motors are noisy!). However, when the setting was changed to INA219_CONFIG_SADCRES_12BIT_128S_69MS, you can see it takes nearly 200 readings until the value changes. 350mS / 1000 samples = 0.35ms per reading. 0.35ms x 197 samples = 68.95ms. In addition, the values were obviously "averegaed".