add vbat for metro, clean up

This commit is contained in:
hathach committed 2019-05-06 11:29:16 +07:00
1 parent 8c4767f801
commit 85ea29dbaf
3 files changed
+8 -6

No files matched your search

@@ -1,12 +1,13 @@
#include <Arduino.h>
uint32_t vbat_pin = PIN_VBAT; // A7 for feather nRF52832, A6 for nRF52840
#define VBAT_MV_PER_LSB (0.73242188F) // 3.0V ADC range and 12-bit ADC resolution = 3000mV/4096
#ifdef NRF52840_XXAA // if this is for nrf52840
#define VBAT_PIN (A6)
#define VBAT_DIVIDER (0.5F) // 150K + 150K voltage divider on VBAT
#define VBAT_DIVIDER (0.5F) // 150K + 150K voltage divider on VBAT
#define VBAT_DIVIDER_COMP (2.0F) // Compensation factor for the VBAT divider
#else
#define VBAT_PIN (A7)
#define VBAT_DIVIDER (0.71275837F) // 2M + 0.806M voltage divider on VBAT = (2M / (0.806M + 2M))
#define VBAT_DIVIDER_COMP (1.403F) // Compensation factor for the VBAT divider
#endif
@@ -27,7 +28,7 @@ float readVBAT(void) {
delay(1);
// Get the raw 12-bit, 0..3000mV ADC value
raw = analogRead(VBAT_PIN);
raw = analogRead(vbat_pin);
// Set the ADC back to the default settings
analogReference(AR_DEFAULT);