battery monitoring finished

This commit is contained in:
Klaus K Wilting 2018-06-03 15:02:09 +02:00
parent b93c80b924
commit 63eda7db03

View File

@ -18,6 +18,8 @@
// Local logging tag // Local logging tag
static const char TAG[] = "main"; static const char TAG[] = "main";
#ifdef VERBOSE
static void check_efuse() static void check_efuse()
{ {
//Check if two point calibration values are burned into eFuse //Check if two point calibration values are burned into eFuse
@ -46,27 +48,31 @@ static void print_char_val_type(esp_adc_cal_value_t val_type)
} }
} }
#endif // verbose
uint16_t read_voltage(void) uint16_t read_voltage(void)
{ {
static const adc1_channel_t channel = HAS_BATTERY_PROBE; static const adc1_channel_t channel = HAS_BATTERY_PROBE;
static const adc_atten_t atten = ADC_ATTEN_DB_11; static const adc_atten_t atten = ADC_ATTEN_DB_11;
static const adc_unit_t unit = ADC_UNIT_1; static const adc_unit_t unit = ADC_UNIT_1;
//Check if Two Point or Vref are burned into eFuse #ifdef VERBOSE
//show if Two Point or Vref are burned into eFuse
check_efuse(); check_efuse();
#endif
//Configure GPIO used fpr ADC1
//gpio_set_direction(GPIO_NUM_35, GPIO_MODE_INPUT);
//Configure ADC1 //Configure ADC1
//ESP_ERROR_CHECK(adc_gpio_init(unit, (adc_channel_t) channel));
ESP_ERROR_CHECK(adc1_config_width(ADC_WIDTH_BIT_12)); ESP_ERROR_CHECK(adc1_config_width(ADC_WIDTH_BIT_12));
ESP_ERROR_CHECK(adc1_config_channel_atten(channel, atten)); ESP_ERROR_CHECK(adc1_config_channel_atten(channel, atten));
//Characterize ADC1 //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_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); esp_adc_cal_value_t val_type = esp_adc_cal_characterize(unit, atten, ADC_WIDTH_BIT_12, DEFAULT_VREF, adc_chars);
#ifdef VERBOSE
//show calibration source
print_char_val_type(val_type); print_char_val_type(val_type);
#endif
//sample ADC1 //sample ADC1
uint32_t adc_reading = 0; uint32_t adc_reading = 0;
@ -82,7 +88,7 @@ uint16_t read_voltage(void)
#ifdef BATT_FACTOR #ifdef BATT_FACTOR
voltage *= BATT_FACTOR; voltage *= BATT_FACTOR;
#endif #endif
ESP_LOGI(TAG,"Raw: %d\tVoltage: %dmV", adc_reading, voltage); ESP_LOGI(TAG,"Raw: %d / Voltage: %dmV", adc_reading, voltage);
return voltage; return voltage;
} }
#endif // HAS_BATTERY_PROBE #endif // HAS_BATTERY_PROBE