-
Couldn't load subscription status.
- Fork 18
Open
Description
tinypico-arduino/TinyPICO-Helper/src/TinyPICO.cpp
Lines 207 to 230 in 3b364e6
| float TinyPICO::GetBatteryVoltage() | |
| { | |
| uint32_t raw, mv; | |
| esp_adc_cal_characteristics_t chars; | |
| // only check voltage every 1 second | |
| if ( nextVoltage - millis() > 0 ) | |
| { | |
| nextVoltage = millis() + 1000; | |
| // grab latest voltage | |
| analogRead(BAT_VOLTAGE); // Just to get the ADC setup | |
| raw = adc1_get_raw(BATT_CHANNEL); // Read of raw ADC value | |
| // Get ADC calibration values | |
| esp_adc_cal_characterize(ADC_UNIT_1,ADC_ATTEN_11db ,ADC_WIDTH_BIT_12,DEFAULT_VREF,&chars); | |
| // Convert to calibrated mv then volts | |
| mv = esp_adc_cal_raw_to_voltage(raw, &chars) * (LOWER_DIVIDER+UPPER_DIVIDER) / LOWER_DIVIDER; | |
| lastMeasuredVoltage = (float)mv / 1000.0; | |
| } | |
| return ( lastMeasuredVoltage ); | |
| } |
I'm not familiar enough yet with how the adc is configured and used and reused, but in debugging my program I've found that if I call the GetBatteryVoltage() function anywhere in my code... the ULP program I have that uses adc1 to wake on hall sensor readings fails to execute. I'm guessing because of the way this function uses the ADC that perhaps there needs to be some kind of release or reset on the adc? The ULP loading code looks like this:
esp_err_t err = ulp_load_binary(0, ulp_main_bin_start,
(ulp_main_bin_end - ulp_main_bin_start) /
sizeof(uint32_t));
ESP_ERROR_CHECK(err);
adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_DB_0);
adc1_config_channel_atten(ADC1_CHANNEL_3, ADC_ATTEN_DB_0);
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_ulp_enable();
esp_err_t ulp_run_err =
ulp_run((&ulp_entry - RTC_SLOW_MEM) / sizeof(uint32_t));
if (ulp_run_err != ESP_OK)
log_e("Failed to run ULP program.");Metadata
Metadata
Assignees
Labels
No labels