-
Notifications
You must be signed in to change notification settings - Fork 8
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
Extended code, bug-fixes and adjusted default values in setShunt()
#11
Conversation
* Added missing modes in enum `INA228_MeasurementMode`
adc_range
, set/getTemperatureConversionTime()
setShunt()
Is there something I can do or help with to expedite this merge? Best regards, Dennis. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added missing modes in enum INA228_MeasurementMode
Looks good. Can you add doc strings for the new ones. The terse verbiage from the datasheet is OK.
Added methods set/getTemperatureConversionTime()
Looks good.
Added optional adc_range parameter in method setShunt()
Instead, use setADCRange()
, see next comment.
Added method getADCRange()
It'd be good to also add a setter setADCRange()
. That's how
one would set ADC range instead of a parameter to setShunt()
.
Also, the _adc_range
member does not seem necessary, instead
can call getADCRange()
directly, ex:
if (getADCRange()) {
scale = 4;
}
Default parameter values in setShunt() follow spec sheet now
Leave these as unchanged in this PR. There may be some reason
they are what they are. If not, can update those in a separate PR.
Fixed wrong bits retrieved by getMode()
thanks!
Added method reset_accumulators()
Rename this resetAccumulators
just to be camel case style consistent.
Fixed doxygen report by adding missing docstrings
thanks!
@caternuson All requested changes are met, except for your note on setting the ADC range. It is not as straight forward as you write. Here is the case: Notice lines 139-145: Scenario 1 (current PR): Scenario 2:
Subsequently, |
It depends on There's no need for any additional member variables. The only change is refactoring the manual query of ADC range: bool adcrange = (Config->read() >> 4) & 1; into a getter function that is then called: if (getADCRange()) { (this also gets rid of the And then also adding a setter for ADC range, However - a new member variable to hold the current ADC range could be added if desired. It would get set in void setADCRange(uint8_t adc_range) {
/*
* add code here to actually set ADC RANGE bit in register
*/
// and save locally
_adc_range = adc_range and then used in if (_adc_range) { Setting ADC range via a call to |
The ADC range is now set through method `setADCRange(). This required adding method `_updateShuntCalRegister()` and member `_shunt_res`.
Alright, I follow scenario 2 with your suggestions incorporated. But you should realize there is no escaping adding at least one extra private member. True, |
Can It's also OK to add a new member |
Oh, wait, nevermind. I see why you're doing this now. Otherwise the shunt value would somehow have to be specified again in the call to |
OK, suggest moving Also - have you tested this code? |
I am glad you see the issue now :) |
Yes, all changes of this PR are tested and stable. It is used in a project for a university practicum. |
Thanks! LGTM. Going to merge. |
Code extended, see list below. The only code break is that the default values in method
setShunt()
now follow the spec sheet, i.e. shunt_res = 0.015 and max_current = 10. That is the last commit in this list, which I could remove from the PR if needed. The rest of the requested commits are not breaking. Tested.INA228_MeasurementMode
set/getTemperatureConversionTime()
adc_range
parameter in methodsetShunt()
getADCRange()
setShunt()
follow spec sheet nowKeep up the good work :)
Followed up:
getMode()
reset_accumulators()