diff --git a/src/batterymonitor.cpp b/src/batterymonitor.cpp index eb11771..a26b923 100644 --- a/src/batterymonitor.cpp +++ b/src/batterymonitor.cpp @@ -42,7 +42,7 @@ void BatteryMonitor::Loop() level = voltage_3_3 - level; if (level < 50) { - voltage = 4.0F; + voltage = 5.0F; } else { @@ -52,7 +52,8 @@ void BatteryMonitor::Loop() #endif #if BATTERY_MONITOR_EXTERNAL last_battery_sample = now_ms; - voltage = ((float)analogRead(PIN_BATTERY_LEVEL)) * batteryADCMultiplier; + float e = ((float)analogRead(PIN_BATTERY_LEVEL)) * batteryADCMultiplier; + voltage = (voltage > 0) ? min(voltage, e) : e; #endif #if BATTERY_MONITOR_MCP3021 if (address > 0) @@ -65,6 +66,7 @@ void BatteryMonitor::Loop() if (status == 0) { float v = (((uint16_t)(MSB & 0x0F) << 6) | (uint16_t)(LSB >> 2)); + v *= batteryADCMultiplier; voltage = (voltage > 0) ? min(voltage, v) : v; } } diff --git a/src/defines.h b/src/defines.h index fcc3fd9..ff2a992 100644 --- a/src/defines.h +++ b/src/defines.h @@ -129,5 +129,9 @@ // SlimeVR Board can handle max 5V > so analogRead of 5.0V input will result in 1023.0 #define batteryADCMultiplier 1.0 / 1023.0 * (320 + BATTERY_MONITOR_EXTERNAL) / 100 #endif +#if BATTERY_MONITOR_MCP3021 + // Default recommended resistors are 9.1k and 5.1k + #define batteryADCMultiplier 3.3 / 1023.0 * 14.2 / 9.1 +#endif #endif // SLIMEVR_DEFINES_H_