-
Notifications
You must be signed in to change notification settings - Fork 12
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
Not an issue but a possible contribution ...don't know where else to put it ;-) #11
Comments
Hi Rene-Jean, this looks indeed like useful extentions. Merci beaucoup, monsieur! I will test it and most probably add it, but this might take a while since I have several things ongoing in parallel and want to avoid to get confused completely. Best wishes, Wolfgang |
Hello Wolfgang,
I found that for the bus current correction to be applied, both "setPGain"
and "setCorrectionFactor" have to be processed at the same time.
Here is the modified version to use.
Again, thank you for that GREAT library.
Regards ,
Rene-Jean
/**************************************************************************************************************************/
void FunctionProcessing::adjustINA219Gain() { // Function organize in such
a way that the gain is not continuously reprogrammed if not needed
float actualCurrent = ina219.getCurrent_mA(); // Get actual Current value
for (;;) {
if (actualCurrent >= 1600.0f) { // Between 1600 mA and 3200 mA
if (ds.variousData.INA219PresetGain != ds.INA219Gain::PG320) {
ina219.setPGain(PG_320);
if (ds.variousData.busCurrent_mACompensation > 0.0f) {
ina219.setCorrectionFactor(ds.variousData.busCurrent_mACompensation); //
Current correction factor
Serial.print("Correction to INA219 Bus Current of : "); Serial.print(ds.
variousData.busCurrent_mACompensation,3); Serial.println(" applied to the
INA219\n");
}
ds.variousData.INA219PresetGain = ds.INA219Gain::PG320; // Memorize the
actual gain setting
Serial.println("PG set to PG320");
break;
}
}
else if (actualCurrent >= 800.0f) { // Between 800 mA and <1600 mA
if (ds.variousData.INA219PresetGain != ds.INA219Gain::PG160) {
ina219.setPGain(PG_160);
if (ds.variousData.busCurrent_mACompensation > 0.0f) {
ina219.setCorrectionFactor(ds.variousData.busCurrent_mACompensation); //
Current correction factor
Serial.print("Correction to INA219 Bus Current of : "); Serial.print(ds.
variousData.busCurrent_mACompensation,3); Serial.println(" applied to the
INA219\n");
}
ds.variousData.INA219PresetGain = ds.INA219Gain::PG160; // Memorize the
actual gain setting
Serial.println("PG set to PG160");
break;
}
}
else if (actualCurrent >= 400.0f) { // Between 400 mA and <800 mA
if (ds.variousData.INA219PresetGain != ds.INA219Gain::PG80) {
ina219.setPGain(PG_80);
if (ds.variousData.busCurrent_mACompensation > 0.0f) {
ina219.setCorrectionFactor(ds.variousData.busCurrent_mACompensation); //
Current correction factor
Serial.print("Correction to INA219 Bus Current of : "); Serial.print(ds.
variousData.busCurrent_mACompensation,3); Serial.println(" applied to the
INA219\n");
}
ds.variousData.INA219PresetGain = ds.INA219Gain::PG80; // Memorize the
actual gain setting
Serial.println("PG set to PG80");
break;
}
}
else if (actualCurrent > 0.0f) { // Between >0 mA and <400 mA
if (ds.variousData.INA219PresetGain != ds.INA219Gain::PG40) {
ina219.setPGain(PG_40);
if (ds.variousData.busCurrent_mACompensation > 0.0f) {
ina219.setCorrectionFactor(ds.variousData.busCurrent_mACompensation); //
Current correction factor
Serial.print("Correction to INA219 Bus Current of : "); Serial.print(ds.
variousData.busCurrent_mACompensation,3); Serial.println(" applied to the
INA219\n");
}
ds.variousData.INA219PresetGain = ds.INA219Gain::PG40; // Memorize the
actual gain setting
Serial.println("PG set to PG40");
break;
}
}
else { // Something wrong
ina219.setPGain(PG_320); // Force highest value
ds.variousData.INA219PresetGain = ds.INA219Gain::PG320;
Serial.println("PG set to PG320"); Serial.println(F("No current detected in
the INA219 Sensor. Check VOLTAGE REGULATOR !!!"));
break;
}
break;
}
}
Le ven. 25 nov. 2022, à 13 h 28, Wolfgang (Wolle) Ewald <
***@***.***> a écrit :
… Hi Rene-Jean,
this looks indeed like useful extentions. Merci beaucoup, monsieur!
I will test it and most probably add it, but this might take a while since
I have several things ongoing in parallel and want to avoid to get confused
completely.
Best wishes, Wolfgang
—
Reply to this email directly, view it on GitHub
<#11 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGFVP375EF6ETZHV4H5BUZ3WKEAMLANCNFSM6AAAAAASK64JNE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Wolle.
Excellent library. Probably the most comprehensive that I found. Thank you very much for having written it and sharing it.
I am working on a project and I needed the system to find the shunt offset voltage and the optimal gain settings, so I developed the following (2 functions) that you might find a way to integrate to the INA219_WE library, if you so desire.
The 1st function : It simply requires that the output of the INA219 does not draw any current (open output).
The second function : Establishes the optimal "setPGain()" dynamically (...the function can be called on a regular basis by the application program) in other to take advantage of the optimal sensitivity. Here they are.
First function.
/**************************************************************************************************************************/
void Diagnostics::findINA219OffsetVoltage(){
Serial.println(F("\nFinding the MEAN of of the INA219 sensor and store the correction value"));
float shuntVoltageSmaller = 10.0f; // Make it such that a INA219 value will always be smaller
float shuntVoltageLarger = 0.0f; // Make it such that a INA219 value will always be larger if not 0
float shuntVoltageBuffer = 0.0f;
for(int i = 0; i < 1000; i ++) {
}
Serial.print("\bShunt Voltage Smaller : "); Serial.println(shuntVoltageSmaller);
Serial.print("Shunt Voltage Larger : "); Serial.println(shuntVoltageLarger);
shuntVoltageBuffer = (shuntVoltageSmaller + shuntVoltageLarger) /2.0f;
Serial.print("Average of the Smaller and Larger Shunt Voltage Values : "); Serial.println(shuntVoltageBuffer,3);
ds.variousData.INA219ShuntOffsetVoltageCompensation = shuntVoltageBuffer;
Serial.print(F("\b\nShunt OFFSET Voltage MEAN of Smaller/Larger of the INA219 : ")); Serial.println(ds.variousData.INA219ShuntOffsetVoltageCompensation,3);
/******************************************/
// The following method does not give an enough precise result ! (Kept for documentation)
// Serial.println(F("\b \nFinding the AVERAGE of and of the INA219 sensor"));
// shuntVoltageBuffer = 0;
// for (int i = 0; i <500; i++) {
// activityWheel();
// shuntVoltageBuffer += fp.diagnosticsGetShuntVoltage_mV();
// MY_MILLI_DELAY(5);
// }
// Serial.print(F("\b \nShunt OFFSET Voltage AVERAGE of the INA219 : ")); Serial.println((shuntVoltageBuffer) /1000.0f,3);
EEPROM.put(ds.eepromPointers.eepromINA219OffsetVoltageCompensation, ds.variousData.INA219ShuntOffsetVoltageCompensation);
Serial.print("INA219 Shunt Offset Voltage Value from EEPROM : "); Serial.println(EEPROM.get(ds.eepromPointers.eepromINA219OffsetVoltageCompensation, ds.variousData.INA219ShuntOffsetVoltageCompensation),3);
Serial.print("INA219 Shunt Offset Voltage Value from VARIABLE: " ); Serial.print(ds.variousData.INA219ShuntOffsetVoltageCompensation);
}
/**************************************************************************************************************************/
void Diagnostics::activityWheel() {
static uint32_t timer = millis();
static uint8_t counter = 0;
if (millis() - timer >= 200) {
}
}
/**************************************************************************************************************************/
Second function.
void FunctionProcessing::adjustINA219Gain() { // Function organize in such a way that the gain is not continuously reprogrammed if not needed
if (ds.variousData.currentOutputValue >= 1.600f) { // Between 1.6 A and 3.2 A
}
else if (ds.variousData.currentOutputValue >= 0.800f) { // Between 0.8 A and 1.6 A
}
else if (ds.variousData.currentOutputValue >= 0.400f) { // Between 0.4 A and 0.8 A
}
else if (ds.variousData.currentOutputValue > 0.000f) { // Between 0.0 A and 0.4 A
}
else if (ds.variousData.currentOutputValue <= 0.000f) { // 0.0 A
}
}
/*****************************************************************/
Finally while in the initialization (setup():
/* The shunt offset voltage is found by the diagnostics function with the voltage regulator removed (see Diagnostics.cpp) */
if (ds.variousData.INA219ShuntOffsetVoltageCompensation > 0.0f) {
ina219.setShuntVoltOffset_mV(ds.variousData.INA219ShuntOffsetVoltageCompensation); // insert the shunt voltage (millivolts) you detect at zero current (i.e INA219 open output)
Regards,
Rene-Jean Mercier
The text was updated successfully, but these errors were encountered: