ADC2 and Wifi together - any hope?

shenanigans
Posts: 2
Joined: Sun Oct 16, 2022 6:53 am

ADC2 and Wifi together - any hope?

Postby shenanigans » Sun Oct 16, 2022 7:58 am

The API documentation insists that ADC2 and Wifi are not to be used together. The datasheet however notes the Arbiter built into the chip, which is clearly intended to enable this functionality. Wondering whether a feature in the silicon had in fact been abandoned by the API team I gave this a whirl:

Code: Select all

void Sensor_uncage(){
    isCaged = false;
    ESP_ERROR_CHECK (adc_continuous_start (adcHandle));
    // adjust the ADC2 arbiter, as the driver resets it every time
    adc_arbiter_t adc2ArbiterConfig = {
        .mode      = ADC_ARB_MODE_FIX,
        .rtc_pri    = 0,
        .dig_pri    = 2,
        .pwdet_pri  = 1,
    };
    adc_hal_arbiter_config (&adc2ArbiterConfig);
    // ...
Initially this will just panic right away, but with Wifi NVS disabled it will only intermittently panic, and if the Wifi stack is able to connect successfully there seems to be no further issue - Continuous Mode ADC on Unit 2 and the wifi stack will live in harmony, with the exception that the ADC sampling frequency will be slightly incorrect.

Interestingly, the ADC sampling frequency will be differently incorrect if you enable NVS for the initial startup process:

Code: Select all

void app_main (void) {
    //Initialize NVS
    esp_err_t flashInitResult = nvs_flash_init();
    if (flashInitResult == ESP_ERR_NVS_NO_FREE_PAGES || flashInitResult == ESP_ERR_NVS_NEW_VERSION_FOUND) {
      ESP_ERROR_CHECK (nvs_flash_erase());
      flashInitResult = nvs_flash_init();
    }
    ESP_ERROR_CHECK (flashInitResult);

    Wifi_init();

    ESP_ERROR_CHECK (nvs_flash_deinit());
    
    Sensor_init();
    Sensor_uncage();
    // ...
Looking at the esp-idf source it appears that whatever configuration is being altered, it's happening in something I don't have the source for, such as

Code: Select all

esp_wifi_init_internal
So, before I start manually pulling all the register values and trying to figure out how my ADC controller is being misconfigured by the wifi stack (or is it an issue with SPI3?) could somebody with more information give me some insight on whether there's any hope of success?

I'm obviously quite concerned about what might happen in the internal portions of the wifi stack if I find the misconfiguration and align things to what the DIG ADC driver wants. I'm especially concerned that I might produce something that works on my bench but exhibits strange long-term bugs in the field.

And yes, I am increasingly leaning towards using an external ADC with an SPI / I2C / I2S interface, as this would free up ADC1 for battery level measurements. The reason I'm trying to avoid this is that I need to change output pins as soon as possible after every pair of simultaneous ADC measurements, which is very easy to do with the DIG ADC driver but seems like it's probably a lot harder to do with an external device involved. Although it would be wasteful and silly I find myself tempted to just put two ESP32 modules on the board - but then I'll still be frustrated that I can't dedicate a radio each to Wifi and BLE and still do my sampling!

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: ADC2 and Wifi together - any hope?

Postby ESP_igrr » Sun Oct 16, 2022 8:27 pm

Hi shenanigans, the answer depends on which chip you are using.

ADC2 and Wi-Fi can't be used together on the ESP32.

On the ESP32-S2 and newer chips, ADC can be used together with Wi-Fi, although usage by Wi-Fi has priority over the usage by software. So you may occasionally get an error code while getting an ADC sample, in which case you have to retry sampling.

shenanigans
Posts: 2
Joined: Sun Oct 16, 2022 6:53 am

Re: ADC2 and Wifi together - any hope?

Postby shenanigans » Tue Oct 18, 2022 1:24 pm

I'm on the S2, however I simply can't tolerate any missed samples, so it's only acceptable for my use case if I can alter the Arbiter's priority. As you can see I've been attempting to do so with poor but not completely negative results. The question in my mind is whether all of the remaining issues can be resolved or if some are intractable. If, for example, the closed source portions of the wifi stack aren't error-checking their results from the ADC, that's something I can't hope to fix. Issues like the timer misconfiguration on the other hand I might hope to find a setup that works for both purposes.

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 98 guests