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,33 +18,37 @@
// Local logging tag // Local logging tag
static const char TAG[] = "main"; static const char TAG[] = "main";
static void check_efuse() #ifdef VERBOSE
{
//Check if two point calibration values are burned into eFuse static void check_efuse()
if (esp_adc_cal_check_efuse(ESP_ADC_CAL_VAL_EFUSE_TP) == ESP_OK) { {
ESP_LOGI(TAG,"eFuse Two Point: Supported"); //Check if two point calibration values are burned into eFuse
} else { if (esp_adc_cal_check_efuse(ESP_ADC_CAL_VAL_EFUSE_TP) == ESP_OK) {
ESP_LOGI(TAG,"eFuse Two Point: NOT supported"); ESP_LOGI(TAG,"eFuse Two Point: Supported");
} else {
ESP_LOGI(TAG,"eFuse Two Point: NOT supported");
}
//Check Vref is burned into eFuse
if (esp_adc_cal_check_efuse(ESP_ADC_CAL_VAL_EFUSE_VREF) == ESP_OK) {
ESP_LOGI(TAG,"eFuse Vref: Supported");
} else {
ESP_LOGI(TAG,"eFuse Vref: NOT supported");
}
} }
//Check Vref is burned into eFuse static void print_char_val_type(esp_adc_cal_value_t val_type)
if (esp_adc_cal_check_efuse(ESP_ADC_CAL_VAL_EFUSE_VREF) == ESP_OK) { {
ESP_LOGI(TAG,"eFuse Vref: Supported"); if (val_type == ESP_ADC_CAL_VAL_EFUSE_TP) {
} else { ESP_LOGI(TAG,"Characterized using Two Point Value");
ESP_LOGI(TAG,"eFuse Vref: NOT supported"); } else if (val_type == ESP_ADC_CAL_VAL_EFUSE_VREF) {
ESP_LOGI(TAG,"Characterized using eFuse Vref");
} else {
ESP_LOGI(TAG,"Characterized using Default Vref");
}
} }
}
static void print_char_val_type(esp_adc_cal_value_t val_type) #endif // verbose
{
if (val_type == ESP_ADC_CAL_VAL_EFUSE_TP) {
ESP_LOGI(TAG,"Characterized using Two Point Value");
} else if (val_type == ESP_ADC_CAL_VAL_EFUSE_VREF) {
ESP_LOGI(TAG,"Characterized using eFuse Vref");
} else {
ESP_LOGI(TAG,"Characterized using Default Vref");
}
}
uint16_t read_voltage(void) uint16_t read_voltage(void)
{ {
@ -52,21 +56,23 @@ uint16_t read_voltage(void)
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
check_efuse(); //show if Two Point or Vref are burned into eFuse
check_efuse();
//Configure GPIO used fpr ADC1 #endif
//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);
print_char_val_type(val_type);
#ifdef VERBOSE
//show calibration source
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