mirror of
https://github.com/SlimeVR/SlimeVR-Tracker-ESP.git
synced 2026-04-06 02:01:57 +02:00
Fix for MCP ADC not displaying correct voltage
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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_
|
||||
|
||||
Reference in New Issue
Block a user