testing battery probe (experimental)

This commit is contained in:
Klaus K Wilting 2018-06-03 00:05:53 +02:00
parent 9c60a237cf
commit 5ca3ef72fd
3 changed files with 14 additions and 22 deletions

View File

@ -14,7 +14,7 @@
;env_default = heltec
;env_default = ttgov1
;env_default = ttgov2
;env_default = ttgov21
env_default = ttgov21
;env_default = lopy
;env_default = lopy4
;env_default = fipy

View File

@ -18,10 +18,6 @@
// Local logging tag
static const char TAG[] = "main";
static const adc_channel_t channel = (adc_channel_t) HAS_BATTERY_PROBE;
static const adc_atten_t atten = ADC_ATTEN_DB_0;
static const adc_unit_t unit = ADC_UNIT_1;
static void check_efuse()
{
//Check if two point calibration values are burned into eFuse
@ -52,35 +48,31 @@ static void print_char_val_type(esp_adc_cal_value_t val_type)
uint16_t read_voltage(void)
{
static const adc1_channel_t channel = HAS_BATTERY_PROBE;
static const adc_atten_t atten = ADC_ATTEN_DB_0;
static const adc_unit_t unit = ADC_UNIT_1;
//Check if Two Point or Vref are burned into eFuse
check_efuse();
//Configure ADC
if (unit == ADC_UNIT_1) {
//Configure ADC1
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten((adc1_channel_t)channel, atten);
} else {
adc2_config_channel_atten((adc2_channel_t)channel, atten);
}
adc1_config_channel_atten(channel, atten);
//Characterize ADC
//Characterize ADC1
esp_adc_cal_characteristics_t *adc_chars = (esp_adc_cal_characteristics_t *) calloc(1, sizeof(esp_adc_cal_characteristics_t));
esp_adc_cal_value_t val_type = esp_adc_cal_characterize(unit, atten, ADC_WIDTH_BIT_12, DEFAULT_VREF, adc_chars);
print_char_val_type(val_type);
//sample ADC
//sample ADC1
uint32_t adc_reading = 0;
//Multisampling
for (int i = 0; i < NO_OF_SAMPLES; i++) {
if (unit == ADC_UNIT_1) {
adc_reading += adc1_get_raw((adc1_channel_t)channel);
} else {
int raw;
adc2_get_raw((adc2_channel_t)channel, ADC_WIDTH_BIT_12, &raw);
adc_reading += raw;
}
adc_reading += adc1_get_raw(channel);
}
adc_reading /= NO_OF_SAMPLES;
//Convert adc_reading to voltage in mV
uint32_t voltage = esp_adc_cal_raw_to_voltage(adc_reading, adc_chars);
ESP_LOGI(TAG,"Raw: %d\tVoltage: %dmV", adc_reading, voltage);

View File

@ -5,7 +5,7 @@
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C
#define DISPLAY_FLIP 1 // rotated display
#define HAS_LED 23 // green on board LED_G3 (not in initial board version)
#define HAS_BATTERY_PROBE ADC1_GPIO35_CHANNEL // battery probe GPIO pin -> ADC_CHANNEL_7
#define HAS_BATTERY_PROBE ADC1_GPIO35_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7
// re-define pin definitions of pins_arduino.h
#define PIN_SPI_SS 18 // ESP32 GPIO18 (Pin18) -- HPD13A NSS/SEL (Pin4) SPI Chip Select Input