tinypico / tinypico-arduino

Arduino libraries and example code for TinyPICO
MIT License
45 stars 20 forks source link

Using GetBatteryVoltage() function causes my adc1 based ULP process to stop working #15

Open mbbender opened 2 years ago

mbbender commented 2 years ago

https://github.com/tinypico/tinypico-arduino/blob/3b364e65c4688f8dde0f598533fa035c6735ac71/TinyPICO-Helper/src/TinyPICO.cpp#L207-L230

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.");