ESP32-S3-DEVKITC ADC Read Issue (Question)

Andrew123098
Posts: 3
Joined: Thu Jan 06, 2022 10:50 pm

ESP32-S3-DEVKITC ADC Read Issue (Question)

Postby Andrew123098 » Tue Apr 19, 2022 10:31 pm

Hello All,
I am working on a project that requires reading in analog data of 2 ADC channels. The circuits before each of the channels are identical. However, when I give, for example, a 50 Hz sinusoid as an input to both circuits, ADC 2 reads the signal just fine while ADC 1 (all of its channels) read in noise near 0 volts. I tested to see if it was a circuit error by swapping which ADC channel reads each circuit, and ADC 1 still only reads noise near 0 volts telling me that there is either an issue with my code or an issue with the microcontroller (I have tested this on 3 different ESP32 S3s and got the same outcome). Could anyone tell me why this would be happening? Is it a programming issue? Is it a firmware bug? I have left a graph of the voltage reading below as well as the code flashed to the microcontroller.

Code: Select all

#include <stdio.h>
#include <driver/adc.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "esp_adc_cal.h"

void app_main(void)
{   
    printf("Hello world!\n");

  
    /* ADC Configuration and Callibration Documentation: |
    ------------------------------------------------------
        VRef of the ESP32-S3 is 1100 mV                  |
                                                         
        Right Channel: GPIO 4 ADC1 Channel 3             |
        Left Channel: GPIO 11 ADC2 Channel 0             |             

        ADC Attenuation Options:                         |
        ADC_ATTEN_DB_0   : 0 - 950 mV                    |
        ADC_ATTEN_DB_2_5 : 0 - 1250 mV                   |
        ADC_ATTEN_DB_6   : 0 - 1750 mV                   |
        ADC_ATTEN_DB_11  : 0 - 3100 mV                   |

        ADC Accuracy Options:                            |
        ADC_WIDTH_9Bit                                   |
        ADC_WIDTH_10Bit                                  |
        ADC_WIDTH_11Bit                                  |
        ADC_WIDTH_12Bit                                  |
        ADC_WIDTH_BIT_DEFAULT (Max Bit Width)            |
    -----------------------------------------------------*/

    // Configure desired precision and attenuation for ADC pins
    adc1_config_width(ADC_WIDTH_BIT_DEFAULT);
    adc1_config_channel_atten(ADC1_CHANNEL_3,ADC_ATTEN_DB_0);
    adc2_config_channel_atten(ADC2_CHANNEL_0,ADC_ATTEN_DB_0);

    // Create ADC channel characteristics structs for use in calibration functions
    esp_adc_cal_characteristics_t adc1_chars;
    esp_adc_cal_characteristics_t adc2_chars;
    esp_adc_cal_characterize(ADC_UNIT_1,ADC_ATTEN_DB_0,ADC_WIDTH_BIT_DEFAULT,1100,&adc1_chars);
    esp_adc_cal_characterize(ADC_UNIT_2,ADC_ATTEN_DB_0,ADC_WIDTH_BIT_DEFAULT,1100,&adc2_chars);

    int val1;
    int val2;
    int n = 44100;
    int counter = 0;
    float difference;
    while(true){    
        val1 = adc1_get_raw(ADC1_CHANNEL_3);
        adc2_get_raw(ADC2_CHANNEL_0,ADC_WIDTH_BIT_DEFAULT,&val2);

        int adc1_voltage = esp_adc_cal_raw_to_voltage(val1,&adc1_chars);
        int adc2_voltage = esp_adc_cal_raw_to_voltage(val2,&adc2_chars);
        printf("\n%d, %d",adc1_voltage,adc2_voltage);
        vTaskDelay(1);
        counter++;
    }
}
Attachments
Garbage15.jpg
Garbage15.jpg (28.21 KiB) Viewed 1412 times

Who is online

Users browsing this forum: Google [Bot] and 208 guests