Skip to content

Commit

Permalink
Fix attenuation for some ESP32 pins (#2144)
Browse files Browse the repository at this point in the history
Fix scale when checking low voltage scenarios
  • Loading branch information
pkendall64 committed Apr 4, 2023
1 parent ca8359c commit a800803
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/AnalogVbat/devAnalogVbat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ static int start()
return DURATION_NEVER;
}
vbatUpdateScale = 1;
#if defined(PLATFORM_ESP32)
analogSetPinAttenuation(GPIO_ANALOG_VBAT, ADC_0db);
analogSetWidth(12);
#endif
return VBAT_SAMPLE_INTERVAL;
}

Expand All @@ -40,7 +44,7 @@ static void reportVbat()
uint32_t adc = vbatSmooth.calc_scaled();
uint16_t vbat;
// For negative offsets, anything between abs(OFFSET)*CNT and 0 is considered 0
if (ANALOG_VBAT_OFFSET < 0 && adc <= (ANALOG_VBAT_OFFSET * -VBAT_SMOOTH_CNT))
if (ANALOG_VBAT_OFFSET < 0 && adc <= (ANALOG_VBAT_OFFSET * -vbatSmooth.scale()))
vbat = 0;
else
vbat = adc * 100U / (ANALOG_VBAT_SCALE * vbatSmooth.scale());
Expand Down

0 comments on commit a800803

Please sign in to comment.