Inconsistant ADC Measurement Values

trycatcherror
Posts: 1
Joined: Fri Sep 22, 2017 3:42 pm

Inconsistant ADC Measurement Values

Postby trycatcherror » Fri Sep 22, 2017 4:55 pm

Hello!

I am working on project that requires measuring the voltage of six different inputs simultanously. For the development I'm using the DevKitC with ESP WROOM 32.
http://akizukidenshi.com/download/ds/es ... eet_en.pdf
Setup.jpeg
Setup.jpeg (50.06 KiB) Viewed 3401 times
As a newcomer to ESP32, I am using the adc example.

Here is the code I used:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "driver/gpio.h"
#include "driver/adc.h"
#include "esp_system.h"
#include "esp_adc_cal.h"

#define V_REF   1100
#define ADC1_TEST_CHANNEL (ADC1_CHANNEL_7)     
//#define V_REF_TO_GPIO  //Remove comment on define to route v_ref to GPIO

void app_main(void)
{
#ifndef V_REF_TO_GPIO
    //Init ADC and Characteristics
    esp_adc_cal_characteristics_t characteristics;
    adc1_config_width(ADC_WIDTH_12Bit);
    adc1_config_channel_atten(ADC1_TEST_CHANNEL, ADC_ATTEN_0db);
    esp_adc_cal_get_characteristics(V_REF, ADC_ATTEN_0db, ADC_WIDTH_12Bit, &characteristics);
    uint32_t voltage;
    while(1){
        voltage = adc1_to_voltage(ADC1_TEST_CHANNEL, &characteristics);
        printf("%d mV\n",voltage);
        vTaskDelay(pdMS_TO_TICKS(1000));
    }
#else
    //Get v_ref
    esp_err_t status;
    status = adc2_vref_to_gpio(GPIO_NUM_25);
    if (status == ESP_OK){
        printf("v_ref routed to GPIO\n");
    }else{
        printf("failed to route v_ref\n");
    }
    fflush(stdout);
#endif
}
The output was really confusing. First without the jumper cable:

123 mV
124 mV
124 mV
122 mV
120 mV
121 mV
121 mV
124 mV
128 mV
139 mV
146 mV
155 mV
172 mV
172 mV
187 mV
195 mV
195 mV
189 mV
188 mV
190 mV
185 mV
195 mV
202 mV
198 mV
199 mV

Then with a jumper cable attached (with no power source!)

54 mV
54 mV
54 mV
54 mV
54 mV
54 mV
54 mV
54 mV
54 mV
54 mV
54 mV
81 mV
193 mV
338 mV
617 mV
1018 mV
1018 mV
1018 mV
1018 mV
1018 mV
1018 mV
1018 mV
1018 mV
1018 mV
1018 mV
1018 mV
1018 mV
1018 mV
1018 mV
1018 mV

It seems that the voltage is going up and down over and over again. I am completely clueless why this is happening. It could be that I'm missing something obvious in the config for example, but I have not been able to figure out what is wrong.

I would really appreciate all the help and information on the topic.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Inconsistant ADC Measurement Values

Postby WiFive » Sat Sep 23, 2017 8:33 pm

Without it connected to anything you are going to pick up noise values, more noise with the jumper wire acting as an antenna

Who is online

Users browsing this forum: No registered users and 99 guests